npm.io
2.0.0 • Published 6 months ago

rabin-native

Licence
Apache-2.0
Version
2.0.0
Deps
1
Size
850 kB
Vulns
0
Weekly
0

rabin-native

https://github.com/holepunchto/librabin bindings for JavaScript.

npm i rabin-native

Usage

const rabin = require('rabin-native')

const chunker = new rabin.Chunker()
const chunks = []

for (const chunk of chunker.push(shakespeare)) {
  chunks.push(chunk)
}

const chunk = chunker.end()

if (chunk) chunks.push(chunk)

API

const chunker = new Chunker([options])

Construct a new chunker.

Options include:

options = {
  minSize: 512 * 1024, // 512 KiB
  maxSize: 8 * 1024 * 1024 // 8 MiB
}
const iterator = chunker.push(data)

Push data to the chunker, returning an iterator over the identified chunks.

Each chunk has the following shape:

chunk = {
  // Size of the chunk in bytes
  length,
  // Offset of the chunk within the stream
  offset
}
const chunk = chunker.end()

Finish the chunker, returning the trailing chunk or null.

License

Apache-2.0