Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #15760 > unrolled thread

Re: on importing/exporting binary files

Started byBill Rowe <readnews@sbcglobal.net>
First post2011-02-12 10:22 +0000
Last post2011-02-12 10:22 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: on importing/exporting binary files Bill Rowe <readnews@sbcglobal.net> - 2011-02-12 10:22 +0000

#15760 — Re: on importing/exporting binary files

FromBill Rowe <readnews@sbcglobal.net>
Date2011-02-12 10:22 +0000
SubjectRe: on importing/exporting binary files
Message-ID<ij5n09$joo$1@smc.vnet.net>
On 2/11/11 at 4:17 AM, l.balzano@gmail.com (Luigi B) wrote:

>I have some files that contain a text header followed by binary data.
>My problem is to open the file, change a line in the (text) header
>and close it (saving it). I tried with  "Import"  but it takes long
>time and when I "export" the files the binary part gets messed up.

>Does anyone know how to do this efficiently as I have thousands of
>files that need to be processed?

I would do this using the low level functions input/output
functions and write my own routine to read in the header and
write out the modified header.

The sequence would be something like:

str=OpenWrite[filename];
SetStreamPosition[str, posOfStartOfLineToChange];
WriteString[str, newText]
Close[str];

Note, the above assumes the new text being written to the file
is exactly the same length of as the text you are replacing. If
this is not the case, you will need to read in the entire file,
modify it then write it back out. If the modification changes
the line length, I would do something like

data=BinaryRead[filename,"Byte"];

modify the bytes I wanted changed then do

BinaryWrite[filename, changedData, "Byte"];

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web