From 9a23e1862003047b0c236ae1ea739a111bdbc797 Mon Sep 17 00:00:00 2001 From: Derek Date: Thu, 22 Jul 2010 12:16:06 -0400 Subject: [PATCH] Fixed: remove unnecessary EOF write attempt for read-only files in BGZF::Close() --- BGZF.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) 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 -- 2.39.5