in reply to Updating Binary Files With variable record lengths

I have a binary file with "records" of variable lengths. Each record ends with a '\n'.

This makes no sense. Let's say that your records consist of a number of unsigned longs, it doesn't matter how many. When these are packed to their 4-byte binary representations, there are ~67,000,000 legitimate values where one or more bytes of the four will be "\n". These include the numbers 10, 266, 522, 778, 1034, 1290, 1546, 1802, 2058, 2314, 2560, 2561, 2562, 2563, 2564, 2565, 2566, 2567, 2568 ...

When you try to read a record containing one of these values back expecting a "\n" as the delimiter, the IO code will encounter the "\n" embedded within one of your binary values and truncate the record.

And you will have the same problem with all types of packed binary numbers. Shorts & longs, signed & unsigned, and floating point also.

So, if you are writing raw binary values to a file and trying to use "\n" as a delimiter--or any other character--you will not be able to read that data back successfully. Period.

If you are not writing raw binary values to the file, then you are goingt o have to clarify what you mean by "binary data", because your question as asked simply doesn't make any sense.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."
  • Comment on Re: Updating Binary Files With variable record lengths