![]() |
libfilezilla
|
Lean class for file access. More...
#include <file.hpp>
Public Types | |
enum | mode { reading, writing } |
Files can be opened for reading or writing, but not both. | |
enum | creation_flags { existing, empty } |
Creation flags when opening file for writing. More... | |
enum | seek_mode { begin, current, end } |
Used by seek. More... | |
Public Member Functions | |
file (native_string const &f, mode m, creation_flags d=existing) | |
file (file const &)=delete | |
file & | operator= (file const &)=delete |
bool | opened () const |
bool | open (native_string const &f, mode m, creation_flags d=existing) |
void | close () |
int64_t | size () const |
Gets size of file. More... | |
int64_t | seek (int64_t offset, seek_mode m) |
Relative seek based on seek mode. More... | |
int64_t | position () |
Get Current position in file. | |
bool | truncate () |
Truncate the file to the current position of the file pointer. More... | |
int64_t | read (void *buf, int64_t count) |
Read data from file. More... | |
int64_t | write (void const *buf, int64_t count) |
Write data to file. More... | |
bool | fsync () |
Ensure data is flushed to disk. More... | |
Lean class for file access.
This class uses the system's native file access functions. It is a less convoluted and much faster alternative to the almost useless std::fstream.
Supports large files exceeding the 32bit limits.
enum creation_flags |
Creation flags when opening file for writing.
Only evaluated when opening existing files for writing Non-existing files will always be created when writing. Opening for reading never creates files.
Enumerator | |
---|---|
existing | Keep existing data if file exists, otherwise create new. |
empty | Truncate file if already existing, otherwise create new. |
enum seek_mode |
Used by seek.
Enumerator | |
---|---|
begin | Seek from beginning of file. |
current | Seek from current position in the file. |
end | Seek from end of file. |
bool fsync | ( | ) |
Ensure data is flushed to disk.
int64_t read | ( | void * | buf, |
int64_t | count | ||
) |
Read data from file.
Reading from file advances the file pointer with the number of octets read.
buf | The buffer that should receive the data. Must be large enough to hold at least count octets |
count | The number of octets to read |
buf
. It may be less than count
. count
octets can happen at any time, it does not indicate EOF. int64_t seek | ( | int64_t | offset, |
seek_mode | m | ||
) |
Relative seek based on seek mode.
It is possible to seek past the end of the file. Doing so does not change the size of the file. It will only change on subsequent writes.
You can get the current position int the file by passing current
as seek_mode with a 0 offset.
int64_t size | ( | ) | const |
Gets size of file.
bool truncate | ( | ) |
Truncate the file to the current position of the file pointer.
Despite its name, this function can extend the size of the file if the current file pointer is past the end of the file.
int64_t write | ( | void const * | buf, |
int64_t | count | ||
) |
Write data to file.
Writing to file advances the file pointer with the number of octets written
buf | The buffer that holds the data to be written. Must hold at least count octets |
count | The number of octets to write |
count
.