Re: Read & Write Binary Files

new topic     » goto parent     » topic index » view thread      » older message » newer message

Andy wrote:
> 
> Hello,
> 
> I am trying to figure out what kind of code you would use to read and write
> 
> binrary files, I have looked through the help files and through that "A
> Beginners
> Guide to Euphoria"
> but still I'm am confused, a little help?

Hi Andy

I guess it depends on what exactly you want to do; ie update parts of a binary
file, or just read a binary file and write a whole binary file, etc.

The trick is mainly in the open(...) statement; from the manual:

"r" - open text file for reading
"rb" - open binary file for reading
"w" - create text file for writing
"wb" - create binary file for writing
"u" - open text file for update (reading and writing)
"ub" - open binary file for update
"a" - open text file for appending
"ab" - open binary file for appending

So with binary files, it's a matter of making sure the "b" is in the second
argument to open.

The two key operations for binary files when updating in a random fashion are
seek() and tell().

seek() lets you position the place where you will do the next read or write
operation, and tell() lets you know where the current file position is.

Curiously enough I don't see a tell() in the Euphoria reference... I guess you
have to keep track of that yourself?

But yeah, without a specific problem to solve I'm at a bit of a loss to give
examples smile

Gary

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu