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

node-ipfs-cluster-api

v0.0.1

Published

A client to the IPFS Cluster HTTP API, built for the browser.

Downloads

4

Readme

ipfs-cluster

dependencies Status JavaScript Style Guide minzip size

A zero-dependency client to the IPFS Cluster HTTP API, built for the browser.

Install

Import it from your favourite CDN (e.g. skypack.dev, unpkg.com, jsdelivr.com) or install directly from npm:

npm i @nftstorage/ipfs-cluster

Usage

Example:

import { Cluster } from 'https://cdn.skypack.dev/@nftstorage/ipfs-cluster'

const cluster = new Cluster('https://your-cluster-domain.com')

const file = new File(['foo'], 'foo.txt')
const { cid } = await cluster.add(file)
console.log(cid) // bafybeigpsl667todjswabhelaxvwmk7amgg3txsv5tkcpbpj5rtrf6g7mu

Using in Node.js

This library is designed to run in the browser or in web workers but it can be run in Node.js if required web APIs are added to the global environment. For exmaple:

import fetch from '@web-std/fetch'
import { FormData } from '@web-std/form-data'
import { File, Blob } from '@web-std/file'

Object.assign(global, { fetch, File, Blob, FormData })

API

This library is WIP and not all cluster HTTP API methods are available yet (PR's welcome!). Please see the typescript types for full parameter and return types.

Constructor

Create a new instance of the cluster client.

import { Cluster } from '@nftstorage/ipfs-cluster'
const cluster = new Cluster('https://your-cluster-domain.com', {
  // optional custom headers for e.g. auth
  headers: { Authorization: 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==' }
})

add

Import a file to the cluster. First argument must be a File or Blob.

const file = new File(['foo'], 'foo.txt')
const { cid } = await cluster.add(file)

Alternatively you can import data from a CAR (Content Addressable aRchive) file:

const car = new Blob(carFileData, { type: 'application/car' })
const { cid } = await cluster.add(car)

More information on reading and writing CAR files in JS.

addDirectory

Imports multiple files to the cluster. First argument must be an array of File or Blob.

const files = [
  new File(['foo'], 'foo.txt'),
  new File(['bar'], 'bar.txt'),
]
const dir = await cluster.addDirectory(file)

for (const entry of dir) {
  console.log(entry.cid)
  // bafybeigpsl667todjswabhelaxvwmk7amgg3txsv5tkcpbpj5rtrf6g7mu
  // bafybeidsnna57jpm2ttwaydwak25qpkxafrg4cnrjsfqipbcqxlsfobjje
}

allocation

Returns the current allocation for a given CID.

const cid = 'bafybeigpsl667todjswabhelaxvwmk7amgg3txsv5tkcpbpj5rtrf6g7mu'
const allocation = await cluster.allocation(cid)

metricNames

Get a list of metric types known to the peer.

const names = await cluster.metricNames()
console.log(names) // [ 'ping', 'freespace' ]

pin

Tracks a CID with the given replication factor and a name for human-friendliness.

const cid = 'bafybeigpsl667todjswabhelaxvwmk7amgg3txsv5tkcpbpj5rtrf6g7mu'
const { cid } = await cluster.pin(cid)

recover

Re-triggers pin or unpin IPFS operations for a CID in error state.

const cid = 'bafybeigpsl667todjswabhelaxvwmk7amgg3txsv5tkcpbpj5rtrf6g7mu'
const { cid } = await cluster.recover(cid)

status

Returns the current IPFS state for a given CID.

const cid = 'bafybeigpsl667todjswabhelaxvwmk7amgg3txsv5tkcpbpj5rtrf6g7mu'
const status = await cluster.status(cid)

for (const [clusterPeerID, pinInfo] of Object.entries(status.peerMap)) {
  console.log(`${clusterPeerID}: ${pinInfo.status}`)
  // e.g.
  // 12D3KooWAjKw14hMUo7wdyEu9KwogrUFCCMiQZApgZ4zMcvtcacj: pinned
  // 12D3KooWKiebn7GqPvjqjKARnm47Xoez6f1civBEWxef3u5G6UdM: pinned
  // 12D3KooWLKdPdFx5UpPNwoVmMXsLULCDegAqXZ7RAgpKuPSMKoSS: pinned
}

unpin

Untracks a CID from cluster.

const cid = 'bafybeigpsl667todjswabhelaxvwmk7amgg3txsv5tkcpbpj5rtrf6g7mu'
await cluster.unpin(cid)

Contribute

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

License

APACHE-2.0 AND MIT