Skip to main content
The Node.js adapter uses napi-rs, which compiles a Rust crate into a .node native addon. The addon links directly to zinc-core and exposes a JavaScript class backed by the Rust core.

Installation

Build the core from a source checkout, then set up the adapter:

ZincRegion

create

Creates a new region. Throws if the name already exists or the size is invalid.

open

Opens an existing region. Throws if the region does not exist.

asBuffer

Returns a Node.js Buffer backed by the shared memory mapping. No copying occurs.
The buffer points directly into the mmap. Writing to the buffer modifies shared memory immediately.

notify

wait

Returns true if data was available, false on timeout.

Complete example

TypeScript

The package includes TypeScript declarations. The ZincRegion class and all its methods are fully typed.

napi-rs internals

asBuffer() uses napi-rs to wrap the mapping without copying. Its finalizer retains an Arc<SharedRegion> until the buffer is collected. A buffer remains valid after its region object is collected. Node has no explicit close() method; the creator unlinks when both its region object and retained buffers have been released. tryWait() consumes a pending notification without blocking. wait() returns false on timeout and throws on other failures. Capacities and timeouts must be unsigned 32-bit integers; fractional, negative, and out-of-range values are rejected.