samtools/htslib — pull request #46 by jkbonfield (2013-12-17 11:52:10+00:00)
Title: EOF block creation and checking for CRAM

CRAM support now has EOF blocks, as per the agreement with Vadim. These are backwards compatible with the 2.0 CRAM specification, although prior implementations of CRAM (both C and Java) had their own issues with the data generated here. Nevertheless that was a software error rather than specification change so I think this is valid.

Note you may wish to reconsider how the check is done for either CRAM and/or BAM as they differ. BAM does a seek and check of the EOF block when opening a file. CRAM does a check that the last block was empty upon closing of a file. The net effect is CRAM cannot tell there is a truncated file until we've finished processing, but on the flip side can detect a truncation in piped data. Perhaps both CRAM and BAM code is best updated to add checks to both locations, so they can detect errors early but also work on streams.