PicoStorage::File class documentation
A file is internally identified by a pointer to the Cache object and an inode number. Thus the size of a File object is very small (8 bytes on 32 bit architectures).
File has value-semantics, so you can freely copy it around, and it's ok to pass it by value.
There is no need to close the File. The file is 'flushed' when you do a commit on the storage.
The file object becomes invalid (and should not be used anymore) after any of these operations:
- closing the storage this file belongs to
- removing the file from the storage,
- a rollback which undoes the file creation.
A File object is in one of two states: "initialized" or "un-initialized". See operator bool() for details.
int pread(void *buffer, int nBytes, int64 position) const;
int pwrite(void *buffer, int nBytes, int64 position) const;
Read from or write to a file, starting at a given offset.Parameters
- buffer
- a pointer to the data buffer. pread() stores here the data read, while pwrite() gets the data to write from here.
- nBytes
- how many bytes to read or write
- position
- the offset inside the file where the read or write begins
Returns
pread(): the number of bytes effectively read. The only reason for reading less than the requested nBytes is reaching the end of the file.pwrite(): returns void.
int64 getSize() const;
void setSize(int64 size)
Get or set the file size (in bytes). Using setSize() you can both shrink or grow a file. When growing the file, the hole is zero-filled.In the current implementation, the file size is limited to 2^40.
operator bool();
Indicates if the file is initialized. See Dir::operator bool() for details.
Returns
- true : the file is initialized, and can be used.
- false: the file is uninitialzed, you can't do other operations on it.