1 // ***************************************************************************
2 // BgzfStream_p.h (c) 2011 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 10 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/IBamIODevice.h"
34 // constructor & destructor
39 // main interface methods
43 // returns true if BgzfStream open for IO
44 bool IsOpen(void) const;
45 // opens the BGZF file
46 void Open(const std::string& filename, const IBamIODevice::OpenMode mode);
47 // reads BGZF data into a byte buffer
48 size_t Read(char* data, const size_t dataLength);
49 // seek to position in BGZF file
50 void Seek(const int64_t& position);
51 // sets IO device (closes previous, if any, but does not attempt to open)
52 void SetIODevice(IBamIODevice* device);
53 // enable/disable compressed output
54 void SetWriteCompressed(bool ok);
55 // get file position in BGZF file
56 int64_t Tell(void) const;
57 // writes the supplied data into the BGZF buffer
58 size_t Write(const char* data, const size_t dataLength);
62 // compresses the current block
63 size_t DeflateBlock(void);
64 // flushes the data in the BGZF block
65 void FlushBlock(void);
66 // de-compresses the current block
67 size_t InflateBlock(const size_t& blockLength);
71 // static 'utility' methods
73 // checks BGZF block header
74 static bool CheckBlockHeader(char* header);
78 unsigned int m_blockLength;
79 unsigned int m_blockOffset;
80 uint64_t m_blockAddress;
82 bool m_isWriteCompressed;
83 IBamIODevice* m_device;
88 char* UncompressedBlock;
89 char* CompressedBlock;
91 RaiiWrapper Resources;
94 } // namespace Internal
95 } // namespace BamTools
97 #endif // BGZFSTREAM_P_H