I've been parsing the blk*.dat files using fread().
Let's say this is the basic structure of a blk.dat file:
[magicbyte] [blockheader] [transactions]
[magicbyte] [blockheader] [transactions]
...
[magicbyte] [blockheader] [transactions]
When parsing, I start by reading the first 4 bytes.
- If it's equal to
D9B4BEF9(magicbyte), I gather the [blockheader] and [transactions] data. - If I get
NULL, I assume that I've reached the end of the blk.dat file and move on to the next one (if there is one). - If I get
00000000, I assume that the blk.dat file is incomplete, and I keep re-reading it.
Is this a reliable way to parse the blk.dat files? The 00000000 check is what I'm most unsure of.