Docs

Data

Inherits: FileData
C++ type: Data

Description

An in-memory byte buffer that implements the FileData streaming interface. It can be loaded from a file path, from a raw byte pointer, or from another File object. Once loaded, it supports sequential read/write operations and random seek access.

In native exports, a filename lookup checks the optional resources.pak before falling back to the filesystem. This makes Data suitable for read-only packaged resources; direct File handles can only open loose files.

Data is used by the engine for audio sample loading, asset bundling, and anywhere that in-memory file-like access is needed.

Methods

Type Name Langs
unsigned int open C++ | Lua
int eof C++ | Lua
unsigned int read C++ | Lua
unsigned int write C++ | Lua
unsigned int length C++ | Lua
void seek C++ | Lua
unsigned int pos C++ | Lua

Method details

open

  • unsigned int open(unsigned char* aData, unsigned int aDataLength, bool aCopy = false, bool aTakeOwnership = true)
  • unsigned int open(const char* aFilename)
  • unsigned int open(File* aFile)

Loads data from a raw byte pointer, a file path, or a File object. The filename overload transparently reads packed asset://, lua://, and asset-relative paths in a native export. When aCopy is true, the data is duplicated into an internal buffer; when aTakeOwnership is true, the Data object takes ownership of the provided pointer. The File overload reads from the file's current position, and returns FileErrors::INVALID_PARAMETER when the file is not open. Lua has the filename overload only.

The Data(path) constructor, which FileData.newFile(path) also uses, logs an error when the file can't be opened and leaves the data empty. open doesn't log, so check what it returns to tell a missing file from an empty one.


eof

  • int eof()

Returns non-zero (true in Lua) if the read cursor is at or past the end of the buffer.


read / write

  • unsigned int read(unsigned char* aDst, unsigned int aBytes)
  • unsigned int write(unsigned char* aSrc, unsigned int aBytes)

Read or write aBytes bytes at the current cursor position. Returns the number of bytes actually transferred.


length

  • unsigned int length()

Returns the total size of the buffer in bytes.


seek

  • void seek(int aOffset)

Moves the read/write cursor to aOffset bytes from the beginning. A negative offset counts back from the end, and the cursor always stays between the start and the end of the data.


pos

  • unsigned int pos()

Returns the current cursor position.