Turi Create
4.0
|
#include <core/storage/fileio/general_fstream_source.hpp>
Public Member Functions | |
general_fstream_source (std::string file) | |
general_fstream_source (std::string file, bool gzip_compressed) | |
general_fstream_source (const general_fstream_source &)=default | |
general_fstream_source (general_fstream_source &&)=default | |
~general_fstream_source () | |
bool | is_open () const |
std::streamsize | read (char *c, std::streamsize bufsize) |
void | close () |
size_t | file_size () const |
size_t | get_bytes_read () const |
std::streampos | seek (std::streamoff off, std::ios_base::seekdir way) |
std::shared_ptr< std::istream > | get_underlying_stream () const |
Implements a general file stream source device which wraps the union_fstream, and provides automatic gzip decompression capabilities.
The general_fstream_souce is NOT thread-safe.
Definition at line 25 of file general_fstream_source.hpp.
|
explicit |
Constructs a fstream source which opens a file. This file can be of any protocol supported by the union_fstream, and may also be gzip compressed. Gzip compression detection is automatic based on the file extension. (Whether it ends in .gz)
turi::fileio_impl::general_fstream_source::general_fstream_source | ( | std::string | file, |
bool | gzip_compressed | ||
) |
Constructs a fstream source which opens a file. This file can be of any protocol supported by the union_fstream, and may also be gzip compressed. Gzip compression detection is not performed, and the gzip_compressed flag is used to enable/disable gzip decompression.
|
default |
Default copy constructor. copied object shares handles with the original object. Required because boost streams requires devices to be copyable. This should really not be used otherwise.
|
default |
Default move constructor
turi::fileio_impl::general_fstream_source::~general_fstream_source | ( | ) |
destructor. If all copies of this object is closed, closes the file.
void turi::fileio_impl::general_fstream_source::close | ( | ) |
Closes all file handles
size_t turi::fileio_impl::general_fstream_source::file_size | ( | ) | const |
Returns the length of the open file. Returns (size_t)(-1) if there is no file opened.
size_t turi::fileio_impl::general_fstream_source::get_bytes_read | ( | ) | const |
Returns the number of physical bytes read so far. This is an estimate, especially if the file is gzip compressed. Returns (size_t)(-1) if there is no file opened.
std::shared_ptr<std::istream> turi::fileio_impl::general_fstream_source::get_underlying_stream | ( | ) | const |
Returns the underlying stream object if possible. nullptr otherwise.
bool turi::fileio_impl::general_fstream_source::is_open | ( | ) | const |
Returns true if the file is opened
std::streamsize turi::fileio_impl::general_fstream_source::read | ( | char * | c, |
std::streamsize | bufsize | ||
) |
Attempts to read bufsize bytes into the buffer provided. Returns the actual number of bytes read. Returns -1 on failure.
std::streampos turi::fileio_impl::general_fstream_source::seek | ( | std::streamoff | off, |
std::ios_base::seekdir | way | ||
) |
Seeks to a different location. Will fail on compressed files.