🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

ipld

Package Overview
Dependencies
Maintainers
2
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ipld

The JavaScript Implementation of IPLD

0.21.1
Source
npm
Version published
Weekly downloads
731
-39.79%
Maintainers
2
Weekly downloads
 
Created
Source
IPLD hex logo

The JavaScript implementation of the IPLD

Coverage Status Dependency Status js-standard-style

The JavaScript implementation of the IPLD, InterPlanetary Linked-Data

Project Status

We've come a long way, but this project is still in Alpha, lots of development is happening, API might change, beware of the Dragons 🐉.

Want to get started? Check our examples folder. You can check the development status at the js-ipld Waffle Board.

Throughput Graph

Weekly Core Dev Calls

Tech Lead

Volker Mische

Lead Maintainer

Volker Mische

Table of Contents

Install

> npm install --save ipld

Usage

const Ipld = require('ipld')
const IpfsRepo = require('ipfs-repo')
const IpfsBlockService = require('ipfs-block-service')

const initIpld = (ipfsRepoPath, callback) => {
  const repo = new IpfsRepo(ipfsRepoPath)
  repo.init({}, (err) => {
    if (err) {
      return callback(err)
    }
    repo.open((err) => {
      if (err) {
        return callback(err)
      }
      const blockService = new IpfsBlockService(repo)
      const ipld = new Ipld({blockService: blockService})
      return callback(null, ipld)
    })
  })
}

initIpld('/tmp/ifpsrepo', (err, ipld) => {
  // Do something with the `ipld`, e.g. `ipld.get(…)`
})

API

IPLD constructor

Creates and returns an instance of IPLD.

const ipld = new Ipld(options)

The options is an object with any of these properties:

options.blockService
TypeDefault
ipfs.BlockService instanceRequired (no default)

Example:

const blockService = new IpfsBlockService(repo)
const ipld = new Ipld({blockService: blockService})
options.formats
TypeDefault
Array of IPLD Format implementations[require('ipld-dag-cbor'), require('ipld-dag-pb'), require('ipld-raw')]

By default only the dag-cbor), dag-pb) and raw) IPLD Formats are supported. Other formats need to be added manually. Here is an example if you want to have support for ipld-git only:

const ipldGit = require('ipld-git')

const ipld = new Ipld({
  formats: [ipldGit],
  …
})
options.loadFormat(codec, callback)
TypeDefault
Functionnull

Function to dynamically load an IPLD Format. It is passed a string codec, the multicodec of the IPLD format to load and a callback function to call when the format has been loaded. e.g.

const ipld = new Ipld({
  loadFormat (codec, callback) {
    if (codec === 'git-raw') {
      callback(null, require('ipld-git'))
    } else {
      callback(new Error('unable to load format ' + codec))
    }
  }
})

.put(node, options, callback)

Store the given node of a recognized IPLD Format.

options is an object that must contain one of the following combinations:

  • cid - the CID of the node
  • [hashAlg], [version] and format - the hashAlg, version and the format that should be used to create the CID of the node. The hashAlg and version defaults to the default values for the format.

It may contain any of the following:

  • onlyHash - If true the serialized form of the node will not be passed to the underlying block store but the passed callback will be invoked as if it had been

callback is a function that should have the signature as following: function (err, cid) {}, where err is an Error object in case of error and cid is the cid of the stored object.

.get(cid [, path] [, options], callback)

Retrieve a node by the given cid or cid + path

options is an optional object containing:

  • localResolve: bool - if true, get will only attempt to resolve the path locally

callback should be a function with the signature function (err, result), the result being an object with:

  • value - the value that resulted from the get
  • remainderPath - If it didn't manage to successfully resolve the whole path through or if simply the localResolve option was passed.
  • cid - Where the graph traversal finished - if remainderPath has a value, this will be where it has its root

.getMany(cids, callback)

Retrieve several nodes at once

callback should be a function with the signature function (err, result), the result is an array with the nodes corresponding to the CIDs.

.getStream(cid [, path] [, options])

Same as get, but returns a source pull-stream that is used to pass the fetched node.

.treeStream(cid [, path] [, options])

Returns all the paths under a cid + path through a pull-stream. Accepts the following options:

  • recursive - bool - traverse through links to complete the graph.

.remove(cid, callback)

Remove a node by the given cid

.support.add(multicodec, formatResolver, formatUtil)

Add support to another IPLD Format

.support.rm(multicodec)

Removes support of an IPLD Format

Properties

defaultOptions

Default options for IPLD.

Packages

Listing of dependencies from the IPLD ecosystem.

This table is generated using the module package-table with package-table --data=package-list.json.

PackageVersionDepsCICoverageLead Maintainer
IPLD Formats
ipld-bitcoinnpmDepsjenkinscodecovVolker Mische
ipld-dag-cbornpmDepsjenkinscodecovVolker Mische
ipld-dag-pbnpmDepsjenkinscodecovVolker Mische
ipld-ethereumnpmDepsjenkinscodecovkumavis
ipld-gitnpmDepsjenkinscodecovVolker Mische
ipld-rawnpmDepsjenkinscodecovVolker Mische
ipld-zcashnpmDepsjenkinscodecovVolker Mische
Data Types (non IPLD specific)
multihashesnpmDepsjenkinscodecovDavid Dias
ipfs-blocknpmDepsjenkinscodecovVolker Mische
Storage
ipfs-reponpmDepsjenkinscodecovJacob Heun
interface-datastorenpmDepsN/AcodecovPedro Teixeira
ipfs-block-servicenpmDepsjenkinscodecovVolker Mische

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the IPFS Code of Conduct.

License

MIT

Keywords

IPFS

FAQs

Package last updated on 25 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts