[Baypiggies] File IO question

Aahz aahz at pythoncraft.com
Tue Jul 25 14:55:16 CEST 2006

On Tue, Jul 25, 2006, Ken Seehart wrote:
> My question is this: If I write a single byte to a file that contains
> exactly one byte, can I be sure that a power outage during the write
> will not render the file unreadable?

No, you cannot be sure.  What I would do is keep the data in two
different directories; that makes it more likely that you'll be able to
recover your data.  Also, what OS are you using?  (Yes, I saw that it was
Linux, not all Linux is alike.)  You may be able to format the flash disk
with a filesystem that allows journaling.

Another point: I would use \x00 and \xFF for the byte.
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it."  --Brian W. Kernighan

More information about the Baypiggies mailing list