From: John M. <joh...@ya...> - 2001-03-09 14:54:08
|
Yes, binary mode of course. I think I have a mental block in this area. This is twice that I've asked about this sort of thing. Thanks for your patience. $ jython Jython 2.0 on javaVM-1.3.0.01 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> tiffObj = open('john.tif', 'rb').read() >>> open('junk.tif', 'wb').write(tiffObj) >>> $ sum -r junk.tif john.tif 16525 25 junk.tif 16525 25 john.tif $ --- Finn Bock <bc...@wo...> wrote: > [D-Man] > > >On Thu, Mar 08, 2001 at 05:09:42PM -0800, John Mudd wrote: > >| This should be easy. Reading a binary file in Jython causes > changes to > >| the data? But it works in Python. > > > >You forgot to mention that you are using a kernel/OS that likes to > >mangle your data. ;-) > > I strongly suspect that John is using a *nix for the Jython test. > > >Use _binary_ mode for writing _binary_ data. > > Correct. > > >| $ jython > >| Jython 2.0 on javaVM-1.3.0.01 (JIT: null) > >| Type "copyright", "credits" or "license" for more information. > >| >>> tiffObj = open('john.tif', 'r').read() > >| >>> open('junk.tif', 'w').write(tiffObj) > > ^ > >This is "text" mode and Windoze likes to replace every \n with \r\n > in > >such streams. This is what causes your data corruption. > Fortunately > >on *nix systems the kernel doesn't mangle your streams under the > hood. > > Incorrect. It is Jython that does this mangling. The issue basicly > is: > should a read from a file into a unicode String read the data as > binary > (and always set the top 8 bit to zero) or as text by passing the data > through the default encoding. > > Without the 'b' flag, Jython is reading and writing the data as if > using > a Reader/Writer class. When you use the 'b' flag it uses a > InputStream/OutputStream. > > This overloading of the 'b' flag (the flag also controls the platform > dependent newline translation) is not a good thing, but it was the > best > I could come up with. Normally is works as expected and I think that > also goes for John's case. > > regards, > finn > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > http://lists.sourceforge.net/lists/listinfo/jython-users __________________________________________________ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/ |