Package Exports
- ipfs-only-hash
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ipfs-only-hash) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ipfs-only-hash
Just enough code to calculate the IPFS hash for some data
Calculate the IPFS hash for some data without having to install or run an IPFS node.
Install
npm i ipfs-only-hash
Usage
const Hash = require('ipfs-only-hash')
const data = Buffer.from('hello world!')
const hash = await Hash.of(data)
console.log(hash) // QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j
API
Hash.of(input, [options])
-> Promise<String>
Calculate the hash for the provided input.
input
(Buffer|Iterable<Buffer>
): The input bytes to calculate the IPFS hash for. Note that Node.js readable streams are iterable!options
(Object
): Optional options:chunker
(string, defaults to"fixed"
): the chunking strategy. Supports:fixed
rabin
chunkerOptions
(object, optional): the options for the chunker. Defaults to an object with the following properties:avgChunkSize
(positive integer, defaults to262144
): the average chunk size (rabin chunker only)minChunkSize
(positive integer): the minimum chunk size (rabin chunker only)maxChunkSize
(positive integer, defaults to262144
): the maximum chunk size
strategy
(string, defaults to"balanced"
): the DAG builder strategy name. Supports:flat
: flat list of chunksbalanced
: builds a balanced treetrickle
: builds a trickle tree
maxChildrenPerNode
(positive integer, defaults to174
): the maximum children per node for thebalanced
andtrickle
DAG builder strategieslayerRepeat
(positive integer, defaults to 4): (only applicable to thetrickle
DAG builder strategy). The maximum repetition of parent nodes for each layer of the tree.reduceSingleLeafToSelf
(boolean, defaults totrue
): optimization for, when reducing a set of nodes with one node, reduce it to that node.hashAlg
(string, defaults to'sha2-256'
): multihash hashing algorithm to usecidVersion
(integer, default 0): the CID version to use when storing the data (storage keys are based on the CID, including it's version)rawLeaves
(boolean, defaults to false): When a file would span multiple DAGNodes, if this is true the leaf nodes will not be wrapped inUnixFS
protobufs and will instead contain the raw file bytesleafType
(string, defaults to'file'
) what type of UnixFS node leaves should be - can be'file'
or'raw'
(ignored whenrawLeaves
istrue
)
Contribute
Feel free to dive in! Open an issue or submit PRs.
License
MIT © Alan Shaw