Skip to content

akiroz/size-chunker-stream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

size-chunker-stream

A NodeJS transform stream for chunking raw data into constant-size chunks. Useful for consuming raw media streams where chunk size = 1 frame.

API

import SizeChunker from "@akiroz/size-chunker-stream";

const chunker = new SizeChunker({ chunkSize: 640 * 480 * 3 });

process.stdin.pipe(chunker);

chunker.on("data", (frame) => {
    // Do stuff with frame
});

Gotchas

The SizeChunker outputs Buffer of constant size, this does not mean the underlaying ArrayBuffer is also of the same constant size. To create typed views of the data, it may be nessesary to slice the underlaying ArrayBuffer:

chunker.on("data", ({ buffer, length, byteOffset }: Buffer) => {
    const frame = new Int16Array(buffer.slice(byteOffset, byteOffset + length));
    // Do stuff with frame
});

About

Constant chunk size transform stream for node.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published