1 // ***************************************************************************
2 // BgzfStream_p.h (c) 2011 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 25 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/api_global.h"
26 #include "api/BamAux.h"
27 #include "api/IBamIODevice.h"
35 // constructor & destructor
40 // main interface methods
44 // returns true if BgzfStream open for IO
45 bool IsOpen(void) const;
46 // opens the BGZF file
47 void Open(const std::string& filename, const IBamIODevice::OpenMode 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 // sets IO device (closes previous, if any, but does not attempt to open)
53 void SetIODevice(IBamIODevice* device);
54 // enable/disable compressed output
55 void SetWriteCompressed(bool ok);
56 // get file position in BGZF file
57 int64_t Tell(void) const;
58 // writes the supplied data into the BGZF buffer
59 size_t Write(const char* data, const size_t dataLength);
63 // compresses the current block
64 size_t DeflateBlock(void);
65 // flushes the data in the BGZF block
66 void FlushBlock(void);
67 // de-compresses the current block
68 size_t InflateBlock(const size_t& blockLength);
72 // static 'utility' methods
74 // checks BGZF block header
75 static bool CheckBlockHeader(char* header);
79 unsigned int m_blockLength;
80 unsigned int m_blockOffset;
81 uint64_t m_blockAddress;
83 bool m_isWriteCompressed;
84 IBamIODevice* m_device;
86 RaiiBuffer m_uncompressedBlock;
87 RaiiBuffer m_compressedBlock;
90 } // namespace Internal
91 } // namespace BamTools
93 #endif // BGZFSTREAM_P_H