Define an abstract file interface.
More...
#include <file.h>
|
virtual bool | Close ()=0 |
|
virtual int64_t | Read (void *buffer, uint64_t length)=0 |
|
virtual int64_t | Write (const void *buffer, uint64_t length)=0 |
|
virtual int64_t | Size ()=0 |
|
virtual bool | Flush ()=0 |
|
virtual bool | Seek (uint64_t position)=0 |
|
virtual bool | Tell (uint64_t *position)=0 |
|
const std::string & | file_name () const |
|
|
static File * | Open (const char *file_name, const char *mode) |
|
static File * | OpenWithNoBuffering (const char *file_name, const char *mode) |
|
static bool | Delete (const char *file_name) |
|
static int64_t | GetFileSize (const char *file_name) |
|
static bool | ReadFileToString (const char *file_name, std::string *contents) |
|
static bool | WriteStringToFile (const char *file_name, const std::string &contents) |
|
static bool | WriteFileAtomically (const char *file_name, const std::string &contents) |
|
static bool | Copy (const char *from_file_name, const char *to_file_name) |
|
static int64_t | CopyFile (File *source, File *destination) |
|
static int64_t | CopyFile (File *source, File *destination, int64_t max_copy) |
|
static std::string | MakeCallbackFileName (const BufferCallbackParams &callback_params, const std::string &name) |
|
static bool | ParseCallbackFileName (const std::string &callback_file_name, const BufferCallbackParams **callback_params, std::string *name) |
|
|
| File (const std::string &file_name) |
|
virtual | ~File () |
|
virtual bool | Open ()=0 |
| Internal open. Should not be used directly.
|
|
Define an abstract file interface.
Definition at line 26 of file file.h.
◆ ~File()
virtual shaka::File::~File |
( |
| ) |
|
|
inlineprotectedvirtual |
Do not call the destructor directly (with the "delete" keyword) nor use std::unique_ptr; instead use Close().
Definition at line 170 of file file.h.
◆ Close()
virtual bool shaka::File::Close |
( |
| ) |
|
|
pure virtual |
◆ Copy()
bool shaka::File::Copy |
( |
const char * |
from_file_name, |
|
|
const char * |
to_file_name |
|
) |
| |
|
static |
Copies files. This is not good for copying huge files. Although not recommended, it is safe to have source file and destination file name be the same.
- Parameters
-
from_file_name | is the source file name. |
to_file_name | is the destination file name. |
- Returns
- true on success, false otherwise.
Definition at line 281 of file file.cc.
◆ CopyFile() [1/2]
int64_t shaka::File::CopyFile |
( |
File * |
source, |
|
|
File * |
destination |
|
) |
| |
|
static |
Copies the contents from source to destination.
- Parameters
-
source | The file to copy from. |
destination | The file to copy to. |
- Returns
- Number of bytes written, or a value < 0 on error.
Definition at line 316 of file file.cc.
◆ CopyFile() [2/2]
int64_t shaka::File::CopyFile |
( |
File * |
source, |
|
|
File * |
destination, |
|
|
int64_t |
max_copy |
|
) |
| |
|
static |
Copies the contents from source to destination.
- Parameters
-
source | The file to copy from. |
destination | The file to copy to. |
max_copy | The maximum number of bytes to copy; < 0 to copy to EOF. |
- Returns
- Number of bytes written, or a value < 0 on error.
Definition at line 320 of file file.cc.
◆ Delete()
bool shaka::File::Delete |
( |
const char * |
file_name | ) |
|
|
static |
Delete the specified file.
- Parameters
-
file_name | contains the path of the file to be deleted. |
- Returns
- true if successful, false otherwise.
Definition at line 198 of file file.cc.
◆ file_name()
const std::string& shaka::File::file_name |
( |
| ) |
const |
|
inline |
- Returns
- The file name. Note that the file type prefix has been stripped off.
Definition at line 94 of file file.h.
◆ Flush()
virtual bool shaka::File::Flush |
( |
| ) |
|
|
pure virtual |
◆ GetFileSize()
int64_t shaka::File::GetFileSize |
( |
const char * |
file_name | ) |
|
|
static |
- Returns
- The size of a file in bytes on success, a value < 0 otherwise. The file will be opened and closed in the process.
Definition at line 207 of file file.cc.
◆ MakeCallbackFileName()
std::string shaka::File::MakeCallbackFileName |
( |
const BufferCallbackParams & |
callback_params, |
|
|
const std::string & |
name |
|
) |
| |
|
static |
Generate callback file name. NOTE: THE GENERATED NAME IS ONLY VAID WHILE callback_params IS VALID.
- Parameters
-
callback_params | references BufferCallbackParams, which will be embedded in the generated callback file name. |
name | is the name of the buffer, which will be embedded in the generated callback file name. |
Definition at line 354 of file file.cc.
◆ Open()
File * shaka::File::Open |
( |
const char * |
file_name, |
|
|
const char * |
mode |
|
) |
| |
|
static |
Open the specified file. This is a file factory method, it opens a proper file automatically based on prefix, e.g. "file://" for LocalFile.
- Parameters
-
file_name | contains the name of the file to be accessed. |
mode | contains file access mode. Implementation dependent. |
- Returns
- A File pointer on success, false otherwise.
Definition at line 176 of file file.cc.
◆ OpenWithNoBuffering()
File * shaka::File::OpenWithNoBuffering |
( |
const char * |
file_name, |
|
|
const char * |
mode |
|
) |
| |
|
static |
Open the specified file in direct-access mode (no buffering). This is a file factory method, it opens a proper file automatically based on prefix, e.g. "file://" for LocalFile.
- Parameters
-
file_name | contains the name of the file to be accessed. |
mode | contains file access mode. Implementation dependent. |
- Returns
- A File pointer on success, false otherwise.
Definition at line 187 of file file.cc.
◆ ParseCallbackFileName()
bool shaka::File::ParseCallbackFileName |
( |
const std::string & |
callback_file_name, |
|
|
const BufferCallbackParams ** |
callback_params, |
|
|
std::string * |
name |
|
) |
| |
|
static |
Parse and extract callback params.
- Parameters
-
callback_file_name | is the name of the callback file which contains callback_params and name. |
callback_params | points to the parsed BufferCallbackParams pointer. |
name | points to the parsed name. |
- Returns
- true on success, false otherwise.
Definition at line 364 of file file.cc.
◆ Read()
virtual int64_t shaka::File::Read |
( |
void * |
buffer, |
|
|
uint64_t |
length |
|
) |
| |
|
pure virtual |
◆ ReadFileToString()
bool shaka::File::ReadFileToString |
( |
const char * |
file_name, |
|
|
std::string * |
contents |
|
) |
| |
|
static |
Read the contents of a file into string.
- Parameters
-
file_name | is the file to be read. It should be a valid file. |
contents[out] | points to the output string. Should not be NULL. |
- Returns
- true on success, false otherwise.
Definition at line 216 of file file.cc.
◆ Seek()
virtual bool shaka::File::Seek |
( |
uint64_t |
position | ) |
|
|
pure virtual |
◆ Size()
virtual int64_t shaka::File::Size |
( |
| ) |
|
|
pure virtual |
◆ Tell()
virtual bool shaka::File::Tell |
( |
uint64_t * |
position | ) |
|
|
pure virtual |
◆ Write()
virtual int64_t shaka::File::Write |
( |
const void * |
buffer, |
|
|
uint64_t |
length |
|
) |
| |
|
pure virtual |
◆ WriteFileAtomically()
bool shaka::File::WriteFileAtomically |
( |
const char * |
file_name, |
|
|
const std::string & |
contents |
|
) |
| |
|
static |
Save contents
to file_name
in an atomic manner.
- Parameters
-
file_name | is the destination file name. |
contents | is the data to be saved. |
- Returns
- true on success, false otherwise.
Definition at line 262 of file file.cc.
◆ WriteStringToFile()
bool shaka::File::WriteStringToFile |
( |
const char * |
file_name, |
|
|
const std::string & |
contents |
|
) |
| |
|
static |
Writes the data to file.
- Parameters
-
file_name | is the file to write to. |
contents | is the data to write. |
- Returns
- true on success, false otherwise.
Definition at line 234 of file file.cc.
The documentation for this class was generated from the following files: