libgpac
Documentation of the core library of GPAC
FileIO Interface Reference

import"core.idl";

+ Collaboration diagram for FileIO:

Public Member Functions

 File (DOMString reference_url, function open, function close, function write, function read, function seek, function tell, function eof, function exists)
 
void protect ()
 
void destroy ()
 

Data Fields

attribute readonly DOMString url
 
attribute readonly DOMString resource_url
 
attribute readonly FileIO parent
 

Detailed Description

FileIO object

A FileIO object wraps calls to file IO, allowing the script to feed GPAC files not present on disk, or have GPAC create files in JS memory.

Whenever a file is opened, a new JS object of type FileIO is created and passed as "this" in the specified open, close, read, write, seek, tell, eof callbacks.

Any URL relative to the reference URL provided will be solved against the parent FileIO, resulting in additionnals open() calls.

Warning: this is work in progress

Member Function Documentation

◆ File()

FileIO::File ( DOMString  reference_url,
function  open,
function  close,
function  write,
function  read,
function  seek,
function  tell,
function  eof,
function  exists 
)

constructor for a FileIO

Parameters
reference_urlthe base URL this FileIO wraps
openthe open function callback, shall not be NULL. The callback is "boolean open(DOMString url, DOMString mode); ", with mode a fopen mode and the return value true indicates success
closethe close function callback, shall not be NULL. The callback is "close();"
writethe write function callback, shall not be NULL if read is NULL. The callback is "unsigned long write(ArrayBuffer ab);", where ab is the buffer to write and the return value the number of bytes written
readthe read function callback, shall not be NULL if write is NULL. The callback is "unsigned long read(ArrayBuffer ab);", where ab is the buffer to fill and the return value the number of bytes read
seekthe seek function callback, shall not be NULL. The callback is "unsigned long seek(unsigned long long pos, unsigned long whence);", as in gf_fseek
tellthe seek function callback, shall not be NULL. The callback is "unsigned long long tell();", as in gf_ftell
eofthe end of file function callback, shall not be NULL. The callback is "boolean eof();", as in gf_feof
existsthe file existence probing function callback, shall not be NULL. The callback is "boolean exists(DOMString URL);", returns true if file exists (for read access). The "this" object is the constructed FileIO on this callback.

◆ protect()

void FileIO::protect ( )

protects the FileIO factory, preventing it to be deleted until destroy is called This is needded in case a FileIO URL is used several time in a session (re-injecting a source), as libgpac will otherwise destroy the underlying FileIO factory when no more files are associated with it

◆ destroy()

void FileIO::destroy ( )

destroy the underlying FileIO, if not already destroyed. If protect is used, this function MUST be called before exiting gpac

Field Documentation

◆ url

attribute readonly DOMString FileIO::url

get the gfio:// URL associated with the fileIO object

◆ resource_url

attribute readonly DOMString FileIO::resource_url

get the underlying resource URL associated with the fileIO object

◆ parent

attribute readonly FileIO FileIO::parent

the parent FileIO object (the one constructed by the script) for this FileIO instance