1 // ***************************************************************************
2 // BgzfStream_p.h (c) 2011 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 7 October 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>
27 #include <api/IBamIODevice.h>
38 // constructor & destructor
43 // main interface methods
47 // returns true if BgzfStream open for IO
48 bool IsOpen(void) const;
49 // opens the BGZF file
50 void Open(const std::string& filename, const IBamIODevice::OpenMode mode);
51 // reads BGZF data into a byte buffer
52 size_t Read(char* data, const size_t dataLength);
53 // seek to position in BGZF file
54 void Seek(const int64_t& position);
55 // sets IO device (closes previous, if any, but does not attempt to open)
56 void SetIODevice(IBamIODevice* device);
57 // enable/disable compressed output
58 void SetWriteCompressed(bool ok);
59 // get file position in BGZF file
60 int64_t Tell(void) const;
61 // writes the supplied data into the BGZF buffer
62 size_t Write(const char* data, const size_t dataLength);
66 // compresses the current block
67 size_t DeflateBlock(void);
68 // flushes the data in the BGZF block
69 void FlushBlock(void);
70 // de-compresses the current block
71 size_t InflateBlock(const size_t& blockLength);
75 // static 'utility' methods
77 // checks BGZF block header
78 static bool CheckBlockHeader(char* header);
82 unsigned int m_blockLength;
83 unsigned int m_blockOffset;
84 uint64_t m_blockAddress;
86 bool m_isWriteCompressed;
87 IBamIODevice* m_device;
92 char* UncompressedBlock;
93 char* CompressedBlock;
95 RaiiWrapper Resources;
98 } // namespace Internal
99 } // namespace BamTools
101 #endif // BGZFSTREAM_P_H