Giter Site home page Giter Site logo

ipfs-only-hash's Introduction

ipfs-only-hash

Build Status dependencies Status JavaScript Style Guide

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 to 262144): the average chunk size (rabin chunker only)
      • minChunkSize (positive integer): the minimum chunk size (rabin chunker only)
      • maxChunkSize (positive integer, defaults to 262144): the maximum chunk size
    • strategy (string, defaults to "balanced"): the DAG builder strategy name. Supports:
      • flat: flat list of chunks
      • balanced: builds a balanced tree
      • trickle: builds a trickle tree
    • maxChildrenPerNode (positive integer, defaults to 174): the maximum children per node for the balanced and trickle DAG builder strategies
    • layerRepeat (positive integer, defaults to 4): (only applicable to the trickle DAG builder strategy). The maximum repetition of parent nodes for each layer of the tree.
    • reduceSingleLeafToSelf (boolean, defaults to true): 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 use
    • cidVersion (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 in UnixFS protobufs and will instead contain the raw file bytes
    • leafType (string, defaults to 'file') what type of UnixFS node leaves should be - can be 'file' or 'raw' (ignored when rawLeaves is true)

Contribute

Feel free to dive in! Open an issue or submit PRs.

License

MIT © Alan Shaw

ipfs-only-hash's People

Contributors

alanshaw avatar haywirez avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.