vg
tools for working with variation graphs
|
#include <blocked_gzip_output_stream.hpp>
Public Member Functions | |
BlockedGzipOutputStream (BGZF *bgzf_handle) | |
BlockedGzipOutputStream (std::ostream &stream) | |
virtual | ~BlockedGzipOutputStream () |
Destroy the stream, finishing all writes if necessary. More... | |
BlockedGzipOutputStream (const BlockedGzipOutputStream &other)=delete | |
BlockedGzipOutputStream & | operator= (const BlockedGzipOutputStream &other)=delete |
BlockedGzipOutputStream (BlockedGzipOutputStream &&other)=delete | |
BlockedGzipOutputStream & | operator= (BlockedGzipOutputStream &&other)=delete |
virtual bool | Next (void **data, int *size) |
virtual void | BackUp (int count) |
virtual int64_t | ByteCount () const |
Get the number of bytes written since the stream was constructed. More... | |
virtual bool | WriteAliasedRaw (const void *data, int size) |
virtual bool | AllowsAliasing () const |
Return true if WriteAliasedRaw() is actually available, and false otherwise. More... | |
virtual int64_t | Tell () |
virtual void | StartFile () |
virtual void | EndFile () |
void | Flush () |
Protected Member Functions | |
void | flush_self () |
void | force_close () |
Protected Attributes | |
BGZF * | handle |
The open BGZF handle being written to. More... | |
hFILE * | wrapped_ostream |
std::vector< char > | buffer |
This vector will own the memory we use as our void* buffer. More... | |
size_t | backed_up |
The number of characters that have been backed up from the end of the buffer. More... | |
size_t | byte_count |
The counter to back ByteCount. More... | |
bool | know_offset |
Flag for whether our backing stream is tellable. More... | |
bool | end_file |
Flag for whether we are supposed to close out the BGZF file. More... | |
Protobuf-style ZeroCopyOutputStream that writes data in blocked gzip format, and allows interacting with virtual offsets. Does NOT emit the BGZF end-of-file marker unless told to, because we don't want an empty block after every vg io::write call.
vg::io::BlockedGzipOutputStream::BlockedGzipOutputStream | ( | BGZF * | bgzf_handle | ) |
Make a new stream outputting to the given open BGZF file handle. The stream will own the BGZF file and close it when destructed. Note that with this constructor we have no access to the backing hFILE*, so Flush() will not be able to flush it.
vg::io::BlockedGzipOutputStream::BlockedGzipOutputStream | ( | std::ostream & | stream | ) |
Make a new stream outputting to the given C++ std::ostream, wrapping it in a BGZF.
|
virtual |
Destroy the stream, finishing all writes if necessary.
|
delete |
|
delete |
|
virtual |
Return true if WriteAliasedRaw() is actually available, and false otherwise.
|
virtual |
|
virtual |
Get the number of bytes written since the stream was constructed.
|
virtual |
Make this BlockedGzipOutputStream write the BGZF-required empty end of file block, when it finishes writing to the BGZF. These blocks are permitted in the interior of files, but we don't want to add them all the time because they're superfluous and they are supposed to be EOF indicators while we are supposed to be able to append data to a file in progress.
void vg::io::BlockedGzipOutputStream::Flush | ( | ) |
Throws on failure. On success, the object used to construct this stream (i.e. the backing BGZF or ostream) will have all data previously written to this stream in its buffers. Flushes backing BGZFs but not backing ostreams. Flushes any intermediate streams we created.
|
protected |
Actually dump the buffer data to the BGZF, if needed. Sadly, we can't really be zero-copy because the BGZF library isn't. Does NOT make the BGZF flush and finish its block.
|
protected |
Force the BGZF handle closed without letting the library write its EOF marker. TODO: This is necessarily a hack that depends strongly on htslib internals. Should not be called unless data has been flushed into the BGZF.
|
virtual |
Get a buffer to write to. Saves the address of the buffer where data points, and the size of the buffer where size points. Returns false on an unrecoverable error, and true if a buffer was gotten. The stream is responsible for making sure data in the buffer makes it into the output. The data pointer must be valid until the next write call or until the stream is destroyed.
|
delete |
|
delete |
|
virtual |
Tell this BlockedGzipOutputStream that it is at the beginning of a file, when the backing stream is unseekable. Must be called before anything has been written. Enables Tell() and sets the current virtual offset to 0.
|
virtual |
Return the blocked gzip virtual offset at which the next buffer returned by Next() will start, or -1 if operating on an untellable stream like standard output. Note that this will only get you the position of the next write if anything you are writing through is fully backed up to the next actually-unwritten byte. See Protobuf's CodedOutputStream::Trim(). Not const because buffered data may need to be sent to the compressor to get the virtual offset.
|
virtual |
Take the given data at the given address into the stream as written. Only works if AllowsAliasing() returns true. Returns true on success, and false on an unrecoverable error.
|
protected |
The number of characters that have been backed up from the end of the buffer.
|
protected |
This vector will own the memory we use as our void* buffer.
|
protected |
The counter to back ByteCount.
|
protected |
Flag for whether we are supposed to close out the BGZF file.
|
protected |
The open BGZF handle being written to.
|
protected |
Flag for whether our backing stream is tellable.
|
protected |
The hFILE* created to connect the BGZF to the ostream, if we are based on an ostream. Really owned by the BGZF, we just need to be able to flush it since the BGZF's flush doesn't do that.