Shaka Packager SDK
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
shaka::LocalFile Class Reference

Implement LocalFile which deals with local storage. More...

#include <local_file.h>

Inheritance diagram for shaka::LocalFile:
shaka::File

Public Member Functions

 LocalFile (const char *file_name, const char *mode)
 
File implementation overrides.
bool Close () override
 
int64_t Read (void *buffer, uint64_t length) override
 
int64_t Write (const void *buffer, uint64_t length) override
 
int64_t Size () override
 
bool Flush () override
 
bool Seek (uint64_t position) override
 
bool Tell (uint64_t *position) override
 
- Public Member Functions inherited from shaka::File
const std::string & file_name () const
 

Static Public Member Functions

static bool Delete (const char *file_name)
 
- Static Public Member Functions inherited from shaka::File
static FileOpen (const char *file_name, const char *mode)
 
static FileOpenWithNoBuffering (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 bool IsLocalRegularFile (const char *file_name)
 
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)
 

Protected Member Functions

bool Open () override
 Internal open. Should not be used directly.
 
- Protected Member Functions inherited from shaka::File
 File (const std::string &file_name)
 
virtual ~File ()
 

Detailed Description

Implement LocalFile which deals with local storage.

Definition at line 20 of file local_file.h.

Constructor & Destructor Documentation

◆ LocalFile()

shaka::LocalFile::LocalFile ( const char *  file_name,
const char *  mode 
)
Parameters
file_nameC string containing the name of the file to be accessed.
modeC string containing a file access mode, refer to fopen for the available modes.

Definition at line 98 of file local_file.cc.

Member Function Documentation

◆ Close()

bool shaka::LocalFile::Close ( )
overridevirtual

Flush() and de-allocate resources associated with this file, and delete this File object. THIS IS THE ONE TRUE WAY TO DEALLOCATE THIS OBJECT.

Returns
true on success. For writable files, returning false MAY INDICATE DATA LOSS.

Implements shaka::File.

Definition at line 104 of file local_file.cc.

◆ Delete()

bool shaka::LocalFile::Delete ( const char *  file_name)
static

Delete a local file.

Parameters
file_nameis the path of the file to be deleted.
Returns
true if successful, or false otherwise.

Definition at line 199 of file local_file.cc.

◆ Flush()

bool shaka::LocalFile::Flush ( )
overridevirtual

Flush the file so that recently written data will survive an application crash (but not necessarily an OS crash). For instance, in LocalFile the data is flushed into the OS but not necessarily to disk.

Returns
true on success, false otherwise.

Implements shaka::File.

Definition at line 156 of file local_file.cc.

◆ Read()

int64_t shaka::LocalFile::Read ( void *  buffer,
uint64_t  length 
)
overridevirtual

Read data and return it in buffer.

Parameters
[out]bufferpoints to a block of memory with a size of at least length bytes.
lengthindicates number of bytes to be read.
Returns
Number of bytes read, or a value < 0 on error. Zero on end-of-file, or if 'length' is zero.

Implements shaka::File.

Definition at line 114 of file local_file.cc.

◆ Seek()

bool shaka::LocalFile::Seek ( uint64_t  position)
overridevirtual

Seek to the specifield position in the file.

Parameters
positionis the position to seek to.
Returns
true on success, false otherwise.

Implements shaka::File.

Definition at line 161 of file local_file.cc.

◆ Size()

int64_t shaka::LocalFile::Size ( )
overridevirtual
Returns
Size of the file in bytes. A return value less than zero indicates a problem getting the size.

Implements shaka::File.

Definition at line 138 of file local_file.cc.

◆ Tell()

bool shaka::LocalFile::Tell ( uint64_t *  position)
overridevirtual

Get the current file position.

Parameters
positionis a pointer to contain the current file position upon successful return.
Returns
true on succcess, false otherwise.

Implements shaka::File.

Definition at line 170 of file local_file.cc.

◆ Write()

int64_t shaka::LocalFile::Write ( const void *  buffer,
uint64_t  length 
)
overridevirtual

Write block of data.

Parameters
bufferpoints to a block of memory with at least length bytes.
lengthindicates number of bytes to write.
Returns
Number of bytes written, or a value < 0 on error.

Implements shaka::File.

Definition at line 126 of file local_file.cc.


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