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 (mode is either "rb" for reading, or "wb" for writing)
50 void Open(const std::string& filename, const char* mode);
51 void Open(const std::string& filename, const IBamIODevice::OpenMode mode);
52 // reads BGZF data into a byte buffer
53 size_t Read(char* data, const size_t dataLength);
54 // seek to position in BGZF file
55 void Seek(const int64_t& position);
56 // sets IO device (closes previous, if any, but does not attempt to open)
57 void SetIODevice(IBamIODevice* device);
58 // enable/disable compressed output
59 void SetWriteCompressed(bool ok);
60 // get file position in BGZF file
61 int64_t Tell(void) const;
62 // writes the supplied data into the BGZF buffer
63 size_t Write(const char* data, const size_t dataLength);
67 // compresses the current block
68 size_t DeflateBlock(void);
69 // flushes the data in the BGZF block
70 void FlushBlock(void);
71 // de-compresses the current block
72 size_t InflateBlock(const size_t& blockLength);
76 // static 'utility' methods
78 // checks BGZF block header
79 static bool CheckBlockHeader(char* header);
83 unsigned int m_blockLength;
84 unsigned int m_blockOffset;
85 uint64_t m_blockAddress;
89 bool m_isWriteCompressed;
91 IBamIODevice* m_device;
96 char* UncompressedBlock;
97 char* CompressedBlock;
100 RaiiWrapper Resources;
103 } // namespace Internal
104 } // namespace BamTools
106 #endif // BGZFSTREAM_P_H