npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dstanesc/store-chunky-bytes

v0.0.13

Published

Building block for content addressable persistence. Provides the ability to persist, modify and retrieve large byte-arrays or fragments thereof

Downloads

134

Readme

Store Chunky Bytes

Current library is a building block for content addressable persistence. Provides ability to persist, modify and retrieve large byte-arrays or fragments thereof. This is work in progress, features are still added, contributions welcome.

Current features:

  1. Persist large byte arrays, across multiple chunks, in the blob store of your choice (memory, cloud, ipfs, etc.)
  2. Modify the persisted byte arrays, O(n) efficiency where n is the number of impacted chunks
  3. Retrieve slices of data, based on the offset, independent of the individual chunk boundaries

Persisted data is content addressable, hence immutable and versionable.

Used in conjunction with content defined chunkers (eg. Fastcdc and Buzhash) offers chunk deduplication across versions of data.

The intended usage is to persist and access collections of fixed size records. In this case the records can be retrieved extremely efficient (O1) based on the offsets computed externally using mathematic formulas rather than scanning the data.

Usage

Create & Retrieve

import { chunkyStore } from '@dstanesc/store-chunky-bytes'
import { codec, blockStore, chunkerFactory } from './util'

const buf = ...

// configure utility functions
const { get, put } = blockStore()
const { encode, decode } = codec()
const { fastcdc, buzhash } = chunkerFactory({ fastAvgSize: 1024 * 16, buzHash: 15 })

// chunky store functionality
const { create, read } = chunkyStore()

// create blocks and store them in the block store
// the root is the cryptographic handle to the logical buffer and needs preserved for later access
const { root, blocks } = await create({ buf, chunk, encode }) 
for (const block of blocks) await put(block)

const startOffset = ...
const sliceLength = ...

// extract any slice of data 
const recordBytes = await read(startOffset, sliceLength, { root, decode, get })

// read all blocks, ie full byte array
const allBytes = await readAll({ root, decode, get })

Append

const buf2 = ... // byte array to append

// append additional data
// same chunking algorithm as in the creation phase required
// mandatory content-defined chunking algorithm (eg. fastcdc. buzhash, etc.)
// returns a new root and the new blocks
const { root: appendRoot, blocks: appendBlocks } = await append({ root: origRoot, decode, get }, { buf: buf2, chunk: fastcdc, encode })
for (const block of appendBlocks) await put(block)

const startOffset = ...
const sliceLength = ...

// extract any slice of data from the combined byte arrays using the second root
const recordBytes = await read(startOffset, sliceLength, { root: appendRoot, decode, get })

Update

const buf2 = ... // byte array to replace original section

// update original data 
// same chunking algorithm as in the creation phase required
// mandatory content-defined chunking algorithm (eg. fastcdc. buzhash, etc.)
// returns a new root and the new blocks
const { root: updateRoot, index: updateIndex, blocks: updateBlocks } = await update({ root, decode, get }, { buf: buf2, chunk: fastcdc, encode }, RECORD_UPDATE_OFFSET)

Note: Update alg. tuned heuristically for best stability (ie. compare chunk offsets after update w/ full chunking of the updated buffer) results w/ fastcdc.

Bulk

Note the additional put argument to store the intermediate blocks

const buf2 = ... // append buffer
const buf3 = ... // update buffer 1
const buf3 = ... // update buffer 2
// combines append and multiple update operations 
const { root: bulkRoot, index: bulkIndex, blocks: bulkBlocks } = await bulk({ root: origRoot, decode, get, put }, { chunk: fastcdc, encode }, buf2, [{ updateBuffer: buf3, updateStartOffset: RECORD_UPDATE_OFFSET }, { updateBuffer: buf4, updateStartOffset: RECORD_UPDATE_NEXT_OFFSET }])

Remove

const startOffset = ...
const sliceLength = ...

// delete a slice from original data 
// same chunking algorithm as in the creation phase required
// mandatory content-defined chunking algorithm (eg. fastcdc. buzhash, etc.)
// returns a new root and the new blocks
const { root: deleteRoot, index: deleteIndex, blocks: deleteBlocks } = await remove({ root, decode, get }, { chunk: fastcdc, encode }, startOffset, sliceLength)

For more details see the remove tests

To keep library size, dependencies and flexibility under control the blockStore, the content identifier encode/decode and the chunking functionality are not part of the library. However, all batteries are included. The test utilities offer basic functionality for reuse and extension.

Build

npm run clean
npm install
npm run build
npm run test

Licenses

Licensed under either Apache or MIT at your option.