MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: ReadList

  • To: mathgroup at
  • Subject: [mg20779] Re: [mg20732] ReadList
  • From: John Fultz <jfultz at>
  • Date: Thu, 11 Nov 1999 00:22:51 -0500
  • Sender: owner-wri-mathgroup at

You don't say exactly which version or which machine you tried this
on.  I tried this on Mathematica 4.0.1 under Windows, and I couldn't
reproduce the problem you saw.  Nonetheless, I do have a suggestion
that might help fix your problem.

13 and 10 (among others) are problematic bytes because when you
open files as "text" files (which is what ReadList does by
default), there is actually a layer of translation going on.
The fact that there are translations going on means that,
while reading plain-text files becomes a lot easier, you can
never be certain that an arbitrary byte sequence represents
exactly what was in the file.  Note that this is not a
Mathematica-specific issue...the issue arises from the
very different new-line conventions which have been adopted
by Macintosh, Unix, and Windows (each different from the other).

In Mathematica, if you want to open a file as a "binary" file
(i.e. with no translation), then you should call OpenRead
(or OpenWrite if you're writing) with the option
DOSTextFormat->False.  In your case, your example would be:

In[1]:= strm = OpenRead["tmp", DOSTextFormat -> False]

Out[1]= InputStream["tmp", 8]

In[2]:= ReadList[strm, Byte]

Out[2]= {10, 13}

In[3]:= Close[strm]

Out[3]= "tmp"

So, that's one simple answer to your question of what to do.

As far as FastBinaryFiles is concerned, I'm not aware of anyone having
difficulties installing it.  It's a fairly simple procedure (aside from
the compilation of the source file you have to do on a Unix box).  And
it should emaulate the standard package Utilities`BinaryFiles` almost
exactly (the almost is in reference to one or two minor bugs in that
package which FastBinaryFiles does *not* emulate).  If you're having
trouble with it, you can feel free to send me private email about it.


John Fultz
jfultz at
User Interface Group
Wolfram Research, Inc.

> Consider the following oddity:
> In[82]:=
> WriteBinary["tmp", {10, 13}, ByteConversion -> Identity];
> Close["tmp"];
> In[84]:=
> ReadListBinary["tmp", Byte]
> Out[84]=
> {10, 13}
> In[85]:=
> ReadList["tmp", Byte]
> Out[85]=
> {13, 10}
> Why does ReadList invert the roles of 10 and 13? I gather this has 
> something to do with carriage returns and line feeds, but if one is 
> specifying Byte as the type for ReadList, then one expects the byte 
> that is in the file. Examination with a hex dump program will reveal, 
> of course, that the contents of the file are indeed {10,13}.
> Whatever the tortured explanation, what is a body to do? The 
> ReadListBinary function is about 200 times slower than ReadList and 
> thus unusable, and the MathSource package FastBinaryFiles is 
> non-standard and difficult to install. It seems bizarre that this 
> capability (reading raw bytes rapidly from a file) is not readily 
> available, especially since it is presumably required by the built-in 
> Import function.
> Regards,
> Andrew Watson

  • Prev by Date: Levi-Civita Density
  • Next by Date: Integration problem
  • Previous by thread: Re: Levi-Civita Density
  • Next by thread: Integration problem