![]() |
VRS
A file format for sensor data.
|
Class to abstract VRS file system operations, to enable support for alternate storage methods, in particular network/cloud storage implementations. More...
#include <FileHandler.h>
Classes | |
struct | CacheStats |
Stats for cache. More... | |
Public Types | |
using | CacheStatsCallbackFunction = std::function< void(const CacheStats &stats)> |
Public Member Functions | |
virtual unique_ptr< FileHandler > | makeNew () const =0 |
virtual const string & | getFileHandlerName () const =0 |
virtual const string & | getWriteFileHandlerName () const |
virtual int | open (const string &filePath) |
virtual int | openSpec (const FileSpec &fileSpec)=0 |
int | delegateOpen (const FileSpec &fileSpec, unique_ptr< FileHandler > &outNewDelegate) override |
virtual bool | isOpened () const =0 |
virtual int64_t | getTotalSize () const =0 |
virtual int | close ()=0 |
virtual int | skipForward (int64_t offset)=0 |
virtual int | setPos (int64_t offset)=0 |
virtual bool | isAvailableOrPrefetch (MAYBE_UNUSED size_t length) |
virtual int | read (void *buffer, size_t length)=0 |
template<typename T , std::enable_if_t< std::is_trivially_copyable< T >::value, int > = 0> | |
int | read (T &object) |
Helper to read trivially copyable objects, in a chunk aware way. | |
virtual size_t | getLastRWSize () const =0 |
virtual bool | isReadOnly () const |
virtual vector< std::pair< string, int64_t > > | getFileChunks () const =0 |
virtual void | forgetFurtherChunks (int64_t maxSize)=0 |
Call this method to forget any chunk beyond this file size. | |
virtual int | getLastError () const =0 |
virtual bool | isEof () const =0 |
virtual int64_t | getPos () const =0 |
virtual int64_t | getChunkPos () const =0 |
virtual int | getChunkRange (int64_t &outChunkOffset, int64_t &outChunkSize) const =0 |
virtual bool | setCachingStrategy (CachingStrategy) |
virtual CachingStrategy | getCachingStrategy () const |
virtual bool | prefetchReadSequence (MAYBE_UNUSED const vector< std::pair< size_t, size_t > > &sequence, MAYBE_UNUSED bool clearSequence=true) |
virtual bool | setStatsCallback (const CacheStatsCallbackFunction &) |
virtual bool | purgeCache () |
bool | isFileHandlerMatch (const FileSpec &fileSpec) const |
virtual bool | isRemoteFileSystem () const =0 |
virtual bool | showProgress () const |
Tell if the file handler is probably slow, and extra progress information might be useful. | |
![]() | |
virtual int | parseUri (FileSpec &inOutFileSpec, MAYBE_UNUSED size_t colonIndex) const |
Static Public Member Functions | |
static unique_ptr< FileHandler > | makeOpen (const string &filePath) |
Open a file in read-only mode. Returns an open file handler, or nullptr on error. | |
static unique_ptr< FileHandler > | makeOpen (const FileSpec &fileSpec) |
Class to abstract VRS file system operations, to enable support for alternate storage methods, in particular network/cloud storage implementations.
For simplicity, in this documentation, we will references "files", but they might be one or more data blobs on a network storage.
VRS file users probably only need to use RecordFileReader & RecordFileWriter, but they have the option to use FileHandler directly to access files stored on remote file systems, same as VRS. Use FileHandlerFactory::delegateOpen() to find the proper FileHandler implementation and open a file. FileHandler only exposes read operations, because it's the most implementation, while WriteFileHandler extends FileHandler for write operations. Both are abstract classes.
'int' return values are status codes: 0 means success, while other values are error codes, which can always be converted to a human readable string using vrs::errorCodeToMessage(code). File sizes and offset are specified using int64_t, which is equivalent to the POSIX behavior. Byte counts use size_t.
|
pure virtual |
Close the file & free all the held resources, even if an error occurs.
Implemented in vrs::DiskFileT< FileChunk >, and vrs::AtomicDiskFile.
|
overridevirtual |
Open a file, while giving the opportunity to the FileHandler to delegate the file operations to another FileHandler. With this method, a FileHandler might decide that another FileHandler is the right one to open a file, after inspecting the spec, parsing of the path, or lookup.
fileSpec | file specification. |
outNewDelegate | If provided, might be a fallback FileHandler to use. On exit, may be set to a different FileHandler than the current object, if the current FileHandler was not ultimately the right one to handle the provided path, or cleared if the current FileHandler should be used to continue accessing the file. |
Implements vrs::FileDelegator.
|
pure virtual |
Call this method to forget any chunk beyond this file size.
Implemented in vrs::DiskFileT< FileChunk >.
|
inlinevirtual |
Get caching strategy.
|
pure virtual |
Get position in the current chunk.
Implemented in vrs::DiskFileT< FileChunk >.
|
pure virtual |
Get range of the current chunk.
outChunkOffset | index of the first byte of the chunk. |
outChunkSize | number of bytes in the chunk. |
Implemented in vrs::DiskFileT< FileChunk >.
|
pure virtual |
Get the list of chunks, path + size.
Implemented in vrs::DiskFileT< FileChunk >.
|
pure virtual |
Get the last error code.
Implemented in vrs::DiskFileT< FileChunk >.
|
pure virtual |
Get the number of bytes actually moved during the last read or write operation.
Implemented in vrs::DiskFileT< FileChunk >.
|
pure virtual |
Get the absolute position in the file, in a chunk aware way.
Implemented in vrs::DiskFileT< FileChunk >.
|
pure virtual |
Get the total size of all the chunks considered.
Implemented in vrs::DiskFileT< FileChunk >.
|
inlinevirtual |
Check if a number of bytes are available for immediate return (e.g. on disk or in-cache)
length | the number of bytes to check availability of. |
|
pure virtual |
Tell if we are at the end of the last chunk.
Implemented in vrs::DiskFileT< FileChunk >.
|
pure virtual |
Tell if a file is actually open.
Implemented in vrs::DiskFileT< FileChunk >.
|
virtual |
Find out if the file is currently open in read-only mode.
Reimplemented in vrs::DiskFileT< FileChunk >, and vrs::WriteFileHandler.
|
pure virtual |
Tell if the file handler is handling remote data. Readers might need caching. Writers might not support modifying written data (and require a split head).
Implemented in vrs::DiskFileT< FileChunk >.
|
pure virtual |
Make a new instance of the concrete class implementing this interface in its default state, no matter what this object's state is, so that we can access more files using the same method.
Implemented in vrs::DiskFileT< FileChunk >.
|
virtual |
Open a file in read-only mode.
filePath | a disk path, or anything that the particular module recognizes. |
|
pure virtual |
Open a file in read-only mode.
fileSpec | a file spec supported by this file handler. |
Implemented in vrs::DiskFileT< FileChunk >.
|
inlinevirtual |
Tell what read operations are going to happen, so that, if the file handler supports it, data can be cached ahead of time.
sequence | a series of (file_offset, length), ordered by anticipated request order. Read request must not happen exactly as described:
|
clearSequence | Flag on whether to cancel any pre-existing custom read sequence upon caching starts. |
|
inlinevirtual |
Purge read cache buffer, if any. Sets the caching strategy to Passive, and clears any pending read sequence.
|
pure virtual |
Read a number of bytes, in a chunk aware way. If fewer than length bytes can be read, an error code is returned, then use getLastRWSize() to know how many bytes were really read. If there are too few remaining bytes in the current chunk, then the new chunk is opened and read, until enough data can be read.
buffer | a buffer to the bytes to write. |
length | the number of bytes to write. |
Implemented in vrs::DiskFileT< FileChunk >.
|
inlinevirtual |
Set caching strategy.
CachingStrategy | Caching strategy desired. |
|
pure virtual |
Set the file position at an arbitrary position, in a chunk aware way.
offset | the absolute position to jump to, which may be forward or backward. |
Implemented in vrs::DiskFileT< FileChunk >.
|
pure virtual |
Skip a number of bytes further in the file, in a chunk aware way.
offset | the number of bytes to skip. |
Implemented in vrs::DiskFileT< FileChunk >.