From: Derek Date: Thu, 22 Jul 2010 16:16:06 +0000 (-0400) Subject: Fixed: remove unnecessary EOF write attempt for read-only files in BGZF::Close() X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=9a23e1862003047b0c236ae1ea739a111bdbc797;p=bamtools.git Fixed: remove unnecessary EOF write attempt for read-only files in BGZF::Close() --- diff --git a/BGZF.cpp b/BGZF.cpp index a9f2f56..9bc922a 100644 --- a/BGZF.cpp +++ b/BGZF.cpp @@ -47,20 +47,21 @@ BgzfData::~BgzfData(void) { // closes BGZF file void BgzfData::Close(void) { - // skip if file not open, otherwise set flag + // skip if file not open, otherwise set flag if ( !IsOpen ) return; - IsOpen = false; - - // flush the current BGZF block - if ( IsWriteOnly ) FlushBlock(); - // write an empty block (as EOF marker) - int blockLength = DeflateBlock(); - fwrite(CompressedBlock, 1, blockLength, Stream); + // if writing to file, flush the current BGZF block, + // then write an empty block (as EOF marker) + if ( IsWriteOnly ) { + FlushBlock(); + int blockLength = DeflateBlock(); + fwrite(CompressedBlock, 1, blockLength, Stream); + } // flush and close fflush(Stream); fclose(Stream); + IsOpen = false; } // compresses the current block