zipios++
2.0.2
Zipios++ – a small C++ library that provides easy access to .zip files.
|
To read a file by chunk from the end. More...
#include <backbuffer.hpp>
Public Member Functions | |
BackBuffer (std::istream &is, VirtualSeeker const &vs=VirtualSeeker(), ssize_t const chunk_size=1024) | |
ssize_t | readChunk (ssize_t &read_pointer) |
Read a chunk of data. More... | |
Private Attributes | |
ssize_t | m_chunk_size |
std::streampos | m_file_pos |
std::istream & | m_is |
VirtualSeeker | m_vs |
A BackBuffer instance is useful for reading the last part of a file in an efficient manner, when it is not known exactly how far back (towards the front!) to go, to find the start of the desired data block.
BackBuffer is an std::vector<unsigned char> that fills itself with data from a file by reading chunks from the end of the file progressing towards the start. Upon construction the BackBuffer instance is associated with a file and a chunksize can be specified. To read a chunk of the file into the BackBuffer call readChunk().
Note that this is not a good option for really large files as the buffer is enlarged using an insert() on each call to readChunk().
Definition at line 41 of file backbuffer.hpp.
zipios::BackBuffer::BackBuffer | ( | std::istream & | is, |
VirtualSeeker const & | vs = VirtualSeeker() , |
||
ssize_t const | chunk_size = 1024 |
||
) |
BackBuffer constructor.
Initialize a buffer that reads data backward.
The content of the buffer is defined as the content of the is
stream. The stream must be open and seekable. The file pointer of the stream is modified by this constructor and on each call to readChunk().
IOException | This exception is raised when the VirtualSeeker (vs ) returns an invalid answer determining the size of the stream. |
[in,out] | is | The istream to read the data from. The stream must be seekable, as BackBuffer will reposition the file pointer to read chunks from the back of the file. |
[in] | vs | The virtual seeker used to change the file pointer. |
[in] | chunk_size | Specifies the size of the chunks to read the file into the BackBuffer in. |
Definition at line 79 of file backbuffer.cpp.
References m_chunk_size, m_file_pos, m_is, m_vs, zipios::VirtualSeeker::vseekg(), and zipios::VirtualSeeker::vtellg().
ssize_t zipios::BackBuffer::readChunk | ( | ssize_t & | read_pointer | ) |
Reads another chunk and returns the size of the chunk that has been read. Returns 0 on I/O failure.
When a new chunk is read in the already stored bytes change position in the BackBuffer. read_pointer
is assumed by readChunk() to be a pointer into a position in the BackBuffer, and is updated to point to the same position in the file as it pointed to before the new chunk was prepended.
When first calling readChunk(), read_pointer
is expected to be zero and represent the position of EOF.
[in,out] | read_pointer | The buffer pointer. |
Definition at line 140 of file backbuffer.cpp.
References m_chunk_size, m_file_pos, m_is, m_vs, zipios::VirtualSeeker::vseekg(), and zipios::zipRead().
Referenced by zipios::ZipFile::ZipFile().
|
private |
Definition at line 50 of file backbuffer.hpp.
Referenced by BackBuffer(), and readChunk().
|
private |
Definition at line 52 of file backbuffer.hpp.
Referenced by BackBuffer(), and readChunk().
|
private |
Definition at line 51 of file backbuffer.hpp.
Referenced by BackBuffer(), and readChunk().
|
private |
Definition at line 49 of file backbuffer.hpp.
Referenced by BackBuffer(), and readChunk().