BinaryAsset

EntityAssetceramic.BinaryAsset (Class)

Asset for loading binary files as raw bytes.

BinaryAsset loads any file as raw binary data, making it useful for:

  • Custom file formats
  • Binary protocols
  • Compressed data
  • Non-text resources

The loaded data is provided as haxe.io.Bytes, which can be processed as needed by your application.

Features:

  • Hot-reload support for binary files
  • Asynchronous loading
  • Memory-efficient byte handling
// Load a binary file
var binaryAsset = new BinaryAsset('data');
binaryAsset.path = 'data/level.dat';
binaryAsset.onComplete(this, success -> {
    if (success) {
        // Access the raw bytes
        var bytes = binaryAsset.bytes;
        trace('Loaded ${bytes.length} bytes');
        // Process the binary data
        var input = new haxe.io.BytesInput(bytes);
        var version = input.readInt32();
        // ... read more data
    }
});
assets.addAsset(binaryAsset);
assets.load();

Instance Members

The loaded binary data as raw bytes. Will be null until the asset is successfully loaded.

Use haxe.io APIs to read and process the binary data:

  • BytesInput for reading
  • BytesOutput for writing
  • BytesBuffer for building

invalidateBytes(): Void

load(): Void

Loads the binary file from the specified path.

The loading is asynchronous and will emit a complete event when finished. On success, the bytes property will contain the loaded data.

Supports hot-reload on platforms that allow it - the file will be automatically reloaded when it changes on disk.


destroy(): Void

Destroys the binary asset and releases the loaded bytes from memory.


new(name: String, ?variant: String, ?options: Null<AssetOptions>): Void
Name Type Default
name String
variant String (optional)
options Null<AssetOptions> (optional)

Private Members

unobservedBytes: haxe.io.Bytes

emitBytesChange(current: haxe.io.Bytes, previous: haxe.io.Bytes): Void

Event when bytes field changes.

Name Type
current haxe.io.Bytes
previous haxe.io.Bytes

assetFilesDidChange(newFiles: ReadOnlyMap<String, Float>, previousFiles: ReadOnlyMap<String, Float>): Void

Called when asset files change on disk (hot-reload support). Automatically reloads the binary file if it has been modified.

Name Type Description
newFiles ReadOnlyMap<String, Float> Map of current files and their modification times
previousFiles ReadOnlyMap<String, Float> Map of previous files and their modification times

Metadata

Name Parameters
:build tracker.macros.EventsMacro.build()
:autoBuild tracker.macros.EventsMacro.build()
:build ceramic.macros.EntityMacro.buildForCompletion()
:autoBuild ceramic.macros.EntityMacro.buildForCompletion()
:build tracker.macros.ObservableMacro.build()
:autoBuild tracker.macros.ObservableMacro.build()