// closes BGZF file\r
void BgzfData::Close(void) {\r
\r
- // skip if file not open, otherwise set flag\r
+ // skip if file not open, otherwise set flag\r
if ( !IsOpen ) return;\r
- IsOpen = false;\r
-\r
- // flush the current BGZF block\r
- if ( IsWriteOnly ) FlushBlock();\r
\r
- // write an empty block (as EOF marker)\r
- int blockLength = DeflateBlock();\r
- fwrite(CompressedBlock, 1, blockLength, Stream);\r
+ // if writing to file, flush the current BGZF block,\r
+ // then write an empty block (as EOF marker)\r
+ if ( IsWriteOnly ) {\r
+ FlushBlock();\r
+ int blockLength = DeflateBlock();\r
+ fwrite(CompressedBlock, 1, blockLength, Stream);\r
+ }\r
\r
// flush and close\r
fflush(Stream);\r
fclose(Stream);\r
+ IsOpen = false;\r
}\r
\r
// compresses the current block\r