@zon-lib/zon package brings Rust-level performance to Node.js environments.
Installation
Serialization
Converts a JavaScript object directly into a ZON binary buffer.Supported Types:
- Strings
- Numbers (Integer)
- Nested Objects (Coming Soon)
Deserialization (Reader)
TheZonReader class wraps the binary buffer.
Constructor
Initializes the reader. Throws if the magic header is invalid.
Methods
Returns the offset to the root data item defined in the file header.
Reads a UTF-8 string from the given offset.
Reads an unsigned 32-bit integer from the given offset.
Returns the total length of the buffer.
Writing Data (Writer)
For advanced usage, useZonWriter to build a buffer manually.
Constructor
Initializes a new empty writer.
Methods
Writes a string and returns its offset.
Writes a 32-bit integer and returns its offset.
Sets the root offset for the file.
Returns the final binary buffer.
Memory Management
Zero-Copy in JS?
When you pass aBuffer or Uint8Array to ZonReader, the WASM memory view is created over that buffer.
Warning: If you modify the underlying buffer while the reader is active, you may read corrupt data.
Error Handling
The reader methods throws standard JavaScriptError objects if the access is invalid. You should wrap read operations in try/catch blocks if dealing with untrusted input.
Buffer too small for ZonHeader: The provided buffer is < 50 bytes.Invalid Magic Number: The file does not start withZON1.Read out of bounds: Attempted to read past the end of the buffer.
