vg
tools for working with variation graphs
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
vg::io::BlockedGzipOutputStream Class Reference

#include <blocked_gzip_output_stream.hpp>

Inheritance diagram for vg::io::BlockedGzipOutputStream:

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
 
BlockedGzipOutputStreamoperator= (const BlockedGzipOutputStream &other)=delete
 
 BlockedGzipOutputStream (BlockedGzipOutputStream &&other)=delete
 
BlockedGzipOutputStreamoperator= (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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ BlockedGzipOutputStream() [1/4]

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.

◆ BlockedGzipOutputStream() [2/4]

vg::io::BlockedGzipOutputStream::BlockedGzipOutputStream ( std::ostream &  stream)

Make a new stream outputting to the given C++ std::ostream, wrapping it in a BGZF.

◆ ~BlockedGzipOutputStream()

vg::io::BlockedGzipOutputStream::~BlockedGzipOutputStream ( )
virtual

Destroy the stream, finishing all writes if necessary.

◆ BlockedGzipOutputStream() [3/4]

vg::io::BlockedGzipOutputStream::BlockedGzipOutputStream ( const BlockedGzipOutputStream other)
delete

◆ BlockedGzipOutputStream() [4/4]

vg::io::BlockedGzipOutputStream::BlockedGzipOutputStream ( BlockedGzipOutputStream &&  other)
delete

Member Function Documentation

◆ AllowsAliasing()

bool vg::io::BlockedGzipOutputStream::AllowsAliasing ( ) const
virtual

Return true if WriteAliasedRaw() is actually available, and false otherwise.

◆ BackUp()

void vg::io::BlockedGzipOutputStream::BackUp ( int  count)
virtual

When called after Next(), mark the last count bytes of the buffer that Next() produced as not to be written to the output. The user must not have touched those bytes.

◆ ByteCount()

int64_t vg::io::BlockedGzipOutputStream::ByteCount ( ) const
virtual

Get the number of bytes written since the stream was constructed.

◆ EndFile()

void vg::io::BlockedGzipOutputStream::EndFile ( )
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.

◆ Flush()

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.

◆ flush_self()

void vg::io::BlockedGzipOutputStream::flush_self ( )
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.

◆ force_close()

void vg::io::BlockedGzipOutputStream::force_close ( )
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.

◆ Next()

bool vg::io::BlockedGzipOutputStream::Next ( void **  data,
int *  size 
)
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.

◆ operator=() [1/2]

BlockedGzipOutputStream& vg::io::BlockedGzipOutputStream::operator= ( BlockedGzipOutputStream &&  other)
delete

◆ operator=() [2/2]

BlockedGzipOutputStream& vg::io::BlockedGzipOutputStream::operator= ( const BlockedGzipOutputStream other)
delete

◆ StartFile()

void vg::io::BlockedGzipOutputStream::StartFile ( )
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.

◆ Tell()

int64_t vg::io::BlockedGzipOutputStream::Tell ( )
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.

◆ WriteAliasedRaw()

bool vg::io::BlockedGzipOutputStream::WriteAliasedRaw ( const void *  data,
int  size 
)
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.

Member Data Documentation

◆ backed_up

size_t vg::io::BlockedGzipOutputStream::backed_up
protected

The number of characters that have been backed up from the end of the buffer.

◆ buffer

std::vector<char> vg::io::BlockedGzipOutputStream::buffer
protected

This vector will own the memory we use as our void* buffer.

◆ byte_count

size_t vg::io::BlockedGzipOutputStream::byte_count
protected

The counter to back ByteCount.

◆ end_file

bool vg::io::BlockedGzipOutputStream::end_file
protected

Flag for whether we are supposed to close out the BGZF file.

◆ handle

BGZF* vg::io::BlockedGzipOutputStream::handle
protected

The open BGZF handle being written to.

◆ know_offset

bool vg::io::BlockedGzipOutputStream::know_offset
protected

Flag for whether our backing stream is tellable.

◆ wrapped_ostream

hFILE* vg::io::BlockedGzipOutputStream::wrapped_ostream
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.


The documentation for this class was generated from the following files: