MP4v2

Public Member Functions | Public Attributes | List of all members
mp4v2::platform::io::File Class Reference

File implementation. More...

`#include <File.h>`

Inheritance diagram for mp4v2::platform::io::File:

## Public Member Functions
| File (const std::string &name="", Mode mode=MODE_UNDEFINED, FileProvider *provider=NULL)
| Constructor. More...
| ~File ()
| Destructor. More...
bool | open (const std::string &name="", Mode mode=MODE_UNDEFINED)
| Open file. More...
bool | close ()
| Closes file. More...
bool | seek (Size pos)
| Set current file position in bytes. More...
bool | read (void *buffer, Size size, Size &nin)
| Binary stream read. More...
bool | write (const void *buffer, Size size, Size &nout)
| Binary stream write. More...
bool | truncate (Size size)
| Truncate file to length in bytes. More...
bool | getSize (Size &nout)
| Get size of file in bytes. More...
void | setName (const std::string &name)
void | setMode (Mode mode)
virtual bool | open (const std::string &name, Mode mode)=0
virtual bool | seek (Size pos)=0
virtual bool | read (void *buffer, Size size, Size &nin)=0
virtual bool | write (const void *buffer, Size size, Size &nout)=0
virtual bool | truncate (Size size)=0
virtual bool | close ()=0
virtual bool | getSize (Size &nout)=0

## Public Attributes
const std::string & | name
| read-only: file pathname or empty-string if not applicable
const bool & | isOpen
| read-only: true if file is open
const Mode & | mode
| read-only: file mode
const Size & | size
| read-only: file size
const Size & | position
| read-only: file position

## Additional Inherited Members
Public Types inherited from mp4v2::platform::io::FileProvider
enum | Mode { MODE_UNDEFINED , MODE_READ , MODE_MODIFY , MODE_CREATE }
| file operation mode flags More...
typedef int64_t | Size
| type used to represent all file sizes and offsets
Static Public Member Functions inherited from mp4v2::platform::io::FileProvider
static FileProvider & | standard ()

## Detailed Description

File implementation.

File objects model real filesystem files in a 1:1 releationship and always treated as binary; there are no translations of text content performed.

The interface represents all sizes with a signed 64-bit value, thus the limit to this interface is 63-bits of size, roughly 9.22 million TB.

## Constructor & Destructor Documentation

## ◆ File()

mp4v2::platform::io::File::File | ( | const std::string & | name = `""`,
|  | Mode | mode = `MODE_UNDEFINED`,
|  | FileProvider * | provider = `NULL`
| ) |  |
| explicit

Constructor.

A new file object is constructed but not opened.

Parameters

  name | filename of file object, or empty-string. On Windows, this should be a UTF-8 encoded string. On other platforms, it should be an 8-bit encoding that is appropriate for the platform, locale, file system, etc. (prefer to use UTF-8 when possible).
  mode | bitmask specifying mode flags. See Mode for bit constants.
  provider | a fileprovider instance. If NULL a standard file provider will be used otherwise the supplied provider must be new-allocated and will be delete'd via ~File().

## ◆ ~File()

mp4v2::platform::io::File::~File | ( |  | ) |

Destructor.

File object is destroyed. If the file is opened it is closed prior to destruction.

## Member Function Documentation

## ◆ close()

bool mp4v2::platform::io::File::close | ( |  | ) |
| virtual

Closes file.

If the file has not been opened or is not considered the owner of a filehandle, no action is taken.

Returns
  true on failure, false on success.

Implements mp4v2::platform::io::FileProvider.

## ◆ getSize()

bool mp4v2::platform::io::File::getSize | ( | Size & | nout | ) |
| virtual

Get size of file in bytes.

Parameters

  nout | output indicating the size of the file in bytes.

Returns
  true on failure, false on success.

Implements mp4v2::platform::io::FileProvider.

## ◆ open()

bool mp4v2::platform::io::File::open | ( | const std::string & | name = `""`,
|  | Mode | mode = `MODE_UNDEFINED`
| ) |  |
| virtual

Open file.

Parameters

  name | filename of file object, or empty-string to use name. On Windows, this should be a UTF-8 encoded string. On other platforms, it should be an 8-bit encoding that is appropriate for the platform, locale, file system, etc. (prefer to use UTF-8 when possible).
  mode | bitmask specifying mode flags. See Mode for bit constants.

Returns
  true on failure, false on success.

Implements mp4v2::platform::io::FileProvider.

## ◆ read()

bool mp4v2::platform::io::File::read | ( | void * | buffer,
|  | Size | size,
|  | Size & | nin
| ) |  |
| virtual

Binary stream read.

The function reads up to a maximum size bytes from file, storing them in buffer. The number of bytes actually read are returned in nin.

Parameters

  buffer | storage for data read from file.
  size | maximum number of bytes to read from file.
  nin | output indicating number of bytes read from file.

Returns
  true on failure, false on success.

Implements mp4v2::platform::io::FileProvider.

## ◆ seek()

bool mp4v2::platform::io::File::seek | ( | Size | pos | ) |
| virtual

Set current file position in bytes.

Parameters

  pos | new file position in bytes.

Returns
  true on failure, false on success.

Implements mp4v2::platform::io::FileProvider.

## ◆ truncate()

bool mp4v2::platform::io::File::truncate | ( | Size | size | ) |
| virtual

Truncate file to length in bytes.

Parameters

  size | number of bytes to truncate the file to.

Returns
  true on failure, false on success.

Implements mp4v2::platform::io::FileProvider.

## ◆ write()

bool mp4v2::platform::io::File::write | ( | const void * | buffer,
|  | Size | size,
|  | Size & | nout
| ) |  |
| virtual

Binary stream write.

The function writes up to a maximum size bytes from buffer to file. The number of bytes actually written are returned in nout.

Parameters

  buffer | data to be written out to file.
  size | maximum number of bytes to read from file.
  nout | output indicating number of bytes written to file.

Returns
  true on failure, false on success.

Implements mp4v2::platform::io::FileProvider.