Turi Create  4.0
turi::fileio_impl::general_fstream_source Class Reference

#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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ general_fstream_source() [1/4]

turi::fileio_impl::general_fstream_source::general_fstream_source ( std::string  file)
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)

◆ general_fstream_source() [2/4]

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.

◆ general_fstream_source() [3/4]

turi::fileio_impl::general_fstream_source::general_fstream_source ( const general_fstream_source )
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.

◆ general_fstream_source() [4/4]

turi::fileio_impl::general_fstream_source::general_fstream_source ( general_fstream_source &&  )
default

Default move constructor

◆ ~general_fstream_source()

turi::fileio_impl::general_fstream_source::~general_fstream_source ( )

destructor. If all copies of this object is closed, closes the file.

Member Function Documentation

◆ close()

void turi::fileio_impl::general_fstream_source::close ( )

Closes all file handles

◆ file_size()

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.

◆ get_bytes_read()

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.

◆ get_underlying_stream()

std::shared_ptr<std::istream> turi::fileio_impl::general_fstream_source::get_underlying_stream ( ) const

Returns the underlying stream object if possible. nullptr otherwise.

◆ is_open()

bool turi::fileio_impl::general_fstream_source::is_open ( ) const

Returns true if the file is opened

◆ read()

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.

◆ seek()

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.


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