This implements something similar to the object store from git (the .git/objects folder). By default blobs stored by cabs are sha256 hashed and stored in subdirectories to avoid putting too many files in a single directory. The hashing algorithm and depth of the directories are configurable.

Pipe in a blob stream (e.g. fs.createReadStream), get back objects for the various pieces stored. Each object has a hash of the block, as well as the starting and ending locations within the stream. You may optionally pass a string representing the hash function to use (default sha256) and number representing the block size (defaults to 5 MB).

To learn more about hashing algorithm tradeoffs read the comments on this issue.

you also have access to the base Cabs class located at cabs.Cabs, initialize it with a location and optionally an options object wtih a string representing the hash function to use (Defaults to sha256), the block size limit (defaults to 5 MB) and the depth of folders to use.

var store =newCabs('./location');

// or

var store =newCabs({

path:'./location',

hashFunction:'sha256',

limit:5*1024*1024

depth:3

});

store.write(buffer, callback);

//stores buffer, callback is called with the hash

store.read(hash, callback);

//calls the callback with the blob

store.rm(hash, callback);

//removes the file with the given hash

store.destroy(callback);

//deletes all the files related to the store, just a shortcut to rimraf so beware.