RawChunksCodec
Defined in: packages/codecs/src/raw-codec.ts:78
RawChunksCodec - TRUE ZERO-COPY. Returns Buffer[] (array of chunks).
✅ BEST FOR:
- Streaming large files to disk
- Piping to other sockets
- Processing huge datasets chunk-by-chunk
- Any scenario where you want to avoid memory allocation
Example
Section titled “Example”const codec = new RawChunksCodec();
// Serialize (accepts multiple buffers)const payload = codec.serialize([chunk1, chunk2]);
// Deserialize - returns chunks without copying!const chunks = codec.deserializeChunks(receivedChunks);// chunks[0] === receivedChunks[0] (same reference!)Implements
Section titled “Implements”Codec<Buffer[],Buffer[]>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new RawChunksCodec():
RawChunksCodec
Returns
Section titled “Returns”RawChunksCodec
Properties
Section titled “Properties”
readonlyname:"raw-chunks"="raw-chunks"
Defined in: packages/codecs/src/raw-codec.ts:79
Human-readable codec name for debugging/logging.
Implementation of
Section titled “Implementation of”Methods
Section titled “Methods”deserialize()
Section titled “deserialize()”deserialize(
buffer):Buffer<ArrayBufferLike>[]
Defined in: packages/codecs/src/raw-codec.ts:90
Deserialize from a single merged buffer.
⚠️ WARNING: If called for large payloads, this implies a memory copy happened earlier (chunks were merged).
Parameters
Section titled “Parameters”buffer
Section titled “buffer”Buffer
Binary data to deserialize
Returns
Section titled “Returns”Buffer<ArrayBufferLike>[]
Deserialized data
Implementation of
Section titled “Implementation of”deserializeChunks()
Section titled “deserializeChunks()”deserializeChunks(
chunks):Buffer<ArrayBufferLike>[]
Defined in: packages/codecs/src/raw-codec.ts:98
✅ ZERO-COPY: Returns the array with the same Buffer references. No data is copied - only the array wrapper is new!
Parameters
Section titled “Parameters”chunks
Section titled “chunks”readonly Buffer<ArrayBufferLike>[]
Returns
Section titled “Returns”Buffer<ArrayBufferLike>[]
Implementation of
Section titled “Implementation of”serialize()
Section titled “serialize()”serialize(
data):Buffer
Defined in: packages/codecs/src/raw-codec.ts:81
Serialize data to binary format.
Parameters
Section titled “Parameters”Buffer<ArrayBufferLike>[]
Data to serialize
Returns
Section titled “Returns”Buffer
Binary representation as Buffer