]> git.donarmstrong.com Git - bamtools.git/commitdiff
Fixed: remove unnecessary EOF write attempt for read-only files in BGZF::Close()
authorDerek <derekwbarnett@gmail.com>
Thu, 22 Jul 2010 16:16:06 +0000 (12:16 -0400)
committerDerek <derekwbarnett@gmail.com>
Thu, 22 Jul 2010 16:16:06 +0000 (12:16 -0400)
BGZF.cpp

index a9f2f5651cc2d714f2728bd700d72b95f8bffbc0..9bc922a78cb9c03f3d7bd320dee84dc311721039 100644 (file)
--- a/BGZF.cpp
+++ b/BGZF.cpp
@@ -47,20 +47,21 @@ BgzfData::~BgzfData(void) {
 // 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