1 // ***************************************************************************
2 // BgzfStream_p.h (c) 2011 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 5 April 2011(DB)
6 // ---------------------------------------------------------------------------
7 // Based on BGZF routines developed at the Broad Institute.
8 // Provides the basic functionality for reading & writing BGZF files
9 // Replaces the old BGZF.* files to avoid clashing with other toolkits
10 // ***************************************************************************
12 #ifndef BGZFSTREAM_P_H
13 #define BGZFSTREAM_P_H
19 // This file is not part of the BamTools API. It exists purely as an
20 // implementation detail. This header file may change from version to version
21 // without notice, or even be removed.
25 #include <api/BamAux.h>
26 #include <api/BamConstants.h>
37 // constructor & destructor
42 // main interface methods
46 // opens the BGZF file (mode is either "rb" for reading, or "wb" for writing)
47 void Open(const std::string& filename, const char* mode);
48 // reads BGZF data into a byte buffer
49 size_t Read(char* data, const size_t dataLength);
50 // seek to position in BGZF file
51 void Seek(const int64_t& position);
52 // enable/disable compressed output
53 void SetWriteCompressed(bool ok);
54 // get file position in BGZF file
55 int64_t Tell(void) const;
56 // writes the supplied data into the BGZF buffer
57 size_t Write(const char* data, const size_t dataLength);
61 // compresses the current block
62 size_t DeflateBlock(void);
63 // flushes the data in the BGZF block
64 void FlushBlock(void);
65 // de-compresses the current block
66 size_t InflateBlock(const size_t& blockLength);
70 // static 'utility' methods
72 // checks BGZF block header
73 static bool CheckBlockHeader(char* header);
77 unsigned int BlockLength;
78 unsigned int BlockOffset;
82 bool IsWriteCompressed;
87 char* UncompressedBlock;
88 char* CompressedBlock;
91 RaiiWrapper Resources;
95 } // namespace Internal
96 } // namespace BamTools
98 #endif // BGZFSTREAM_P_H