DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
shaka::media::File Class Referenceabstract

Define an abstract file interface. More...

#include <file.h>

Inheritance diagram for shaka::media::File:
shaka::media::LocalFile shaka::media::MemoryFile shaka::media::ThreadedIoFile shaka::media::UdpFile

Public Member Functions

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 Public Member Functions

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 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)
 

Protected Member Functions

 File (const std::string &file_name)
 
virtual ~File ()
 
virtual bool Open ()=0
 Internal open. Should not be used directly.
 

Friends

class ThreadedIoFile
 

Detailed Description

Define an abstract file interface.

Definition at line 24 of file file.h.

Constructor & Destructor Documentation

virtual shaka::media::File::~File ( )
inlineprotectedvirtual

Do not call the destructor directly (with the "delete" keyword) nor use std::unique_ptr; instead use Close().

Definition at line 132 of file file.h.

Member Function Documentation

virtual bool shaka::media::File::Close ( )
pure virtual

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.

Implemented in shaka::media::ThreadedIoFile, shaka::media::UdpFile, shaka::media::LocalFile, and shaka::media::MemoryFile.

bool shaka::media::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_nameis the source file name.
to_file_nameis the destination file name.
Returns
true on success, false otherwise.

Definition at line 203 of file file.cc.

int64_t shaka::media::File::CopyFile ( File source,
File destination 
)
static

Copies the contents from source to destination.

Parameters
sourceThe file to copy from.
destinationThe file to copy to.
Returns
Number of bytes written, or a value < 0 on error.

Definition at line 232 of file file.cc.

int64_t shaka::media::File::CopyFile ( File source,
File destination,
int64_t  max_copy 
)
static

Copies the contents from source to destination.

Parameters
sourceThe file to copy from.
destinationThe file to copy to.
max_copyThe 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 236 of file file.cc.

bool shaka::media::File::Delete ( const char *  file_name)
static

Delete the specified file.

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

Definition at line 163 of file file.cc.

const std::string& shaka::media::File::file_name ( ) const
inline
Returns
The file name.

Definition at line 91 of file file.h.

virtual bool shaka::media::File::Flush ( )
pure virtual

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.

Implemented in shaka::media::ThreadedIoFile, shaka::media::UdpFile, shaka::media::LocalFile, and shaka::media::MemoryFile.

int64_t shaka::media::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 176 of file file.cc.

File * shaka::media::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_namecontains the name of the file to be accessed.
modecontains file access mode. Implementation dependent.
Returns
A File pointer on success, false otherwise.

Definition at line 141 of file file.cc.

File * shaka::media::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_namecontains the name of the file to be accessed.
modecontains file access mode. Implementation dependent.
Returns
A File pointer on success, false otherwise.

Definition at line 152 of file file.cc.

virtual int64_t shaka::media::File::Read ( void *  buffer,
uint64_t  length 
)
pure virtual

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.

Implemented in shaka::media::ThreadedIoFile, shaka::media::UdpFile, shaka::media::LocalFile, and shaka::media::MemoryFile.

bool shaka::media::File::ReadFileToString ( const char *  file_name,
std::string *  contents 
)
static

Read the file into string.

Parameters
file_nameis 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 185 of file file.cc.

virtual bool shaka::media::File::Seek ( uint64_t  position)
pure virtual

Seek to the specifield position in the file.

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

Implemented in shaka::media::ThreadedIoFile, shaka::media::UdpFile, shaka::media::LocalFile, and shaka::media::MemoryFile.

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

Implemented in shaka::media::ThreadedIoFile, shaka::media::UdpFile, shaka::media::LocalFile, and shaka::media::MemoryFile.

virtual bool shaka::media::File::Tell ( uint64_t *  position)
pure virtual

Get the current file position.

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

Implemented in shaka::media::ThreadedIoFile, shaka::media::UdpFile, shaka::media::LocalFile, and shaka::media::MemoryFile.

virtual int64_t shaka::media::File::Write ( const void *  buffer,
uint64_t  length 
)
pure virtual

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.

Implemented in shaka::media::ThreadedIoFile, shaka::media::UdpFile, shaka::media::LocalFile, and shaka::media::MemoryFile.


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