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

ipfs-multiplexer

v1.0.1

Published

A multiplexer library, built on top of js-ipfs-http-client.

Downloads

5

Readme

IPFS Multiplexer Library

A multiplexer library, built on top of js-ipfs-http-client and implementing the interface-ipfs-core.

Lead Maintainer

Iñaki Arango.

Table of Contents

Install

This module uses node.js, and can be installed through npm:

npm install --save ipfs-multiplexer

We support both the Current and Active LTS versions of Node.js. Please see nodejs.org for what these currently are.

Importing the module and usage

import IpfsMultiplexer from 'ipfs-multiplexer';

const ipfsMultiplexer = new IpfsMultiplexer();

// Optionally, you can add your own nodes to the list of available nodes
ipfsMultiplexer.addGateway({
  host: 'localhost',
  port: 5001,
  protocol: 'http',
});

ipfsMultiplexer.get('Qmaisz6NMhDB51cCvNWa1GMS7LU1pAxdF4Ld6Ft9kZEP2a')
  .then(console.log)
  .catch(console.error);

Importing helper functions

import { testGateway } from 'ipfs-multiplexer';

testGateway({
    host: 'localhost',
    port: 5001,
    protocol: 'http',  
  })
  .then(() => {
    // Everything went fine
    console.log('The gateway is up');
  })
  .catch(err => {
    // The error thrown by the gateway during test request
    console.error(err);
  });

In a web browser

through Browserify

Same as in Node.js, you just have to browserify the code before serving it. See the browserify repo for how to do that.

See the example provided by js-ipfs-http-client in the examples folder to get a boilerplate.

through webpack

See the example provided by js-ipfs-http-client in the examples folder to get an idea on how to use a package with webpack.

Custom Headers

If you wish to send custom headers with each request made by this library, for example, the Authorization header. You can use the config to do so:

ipfsMultiplexer.addGateway({
  host: 'localhost',
  port: 5001,
  protocol: 'http',
  headers: {
    authorization: 'Bearer ' + TOKEN,
  },
});

Usage

API

IPFS Core API Compatible

js-ipfs-http-client follows the spec defined by interface-ipfs-core, which concerns the interface to expect from IPFS implementations. This interface is a currently active endeavor. You can use it today to consult the methods available.

IMPORTANTE NOTE: Due to the nature of a multiplexer, the commands from the Network and Node Management categories are not available. Please refere to these links to see which part of the API is not available.

Files

Graph

Additional Options

All core API methods take additional options specific to the HTTP API:

  • headers - An object or Headers instance that can be used to set custom HTTP headers. Note that this option can also be configured globally via the constructor options.
  • timeout - A number or string specifying a timeout for the request. If the timeout is reached before data is received a TimeoutError is thrown. If a number is specified it is interpreted as milliseconds, if a string is passed, it is intepreted according to parse-duration. Note that this option can also be configured globally via the constructor options.
  • searchParams - An object or URLSearchParams instance that can be used to add additional query parameters to the query string sent with each request.

NOTE: The signal property thas is described here is not available with this package, because it is used to abort the requests that have not arrived by the time where the multiplexer already has a valid response.

Development

Testing

We run tests by executing npm test in a terminal window. This will run Node.js test.

NOTE: While because the package conforms with the interface-ipfs-core spec because it extends js-ipfs-http-client, the tests provided by the interface module are yet to be added to this package's tests.

Contribute

ipfs-multiplexer is a work in progress. As such, there's a few things you can do right now to help out:

  • Check out the existing issues!
  • Perform code reviews. More eyes will help a) speed the project along b) ensure quality and c) reduce possible future bugs.
  • Add tests. There can never be enough tests. Note that interface tests exist inside interface-ipfs-core.
  • Contribute to the js-ipfs-http-client repository by checking out issues, performing code reviews, adding tests or by contributing to their FAQ repository. Remember ipfs-multiplexer is based on js-ipfs-http-client, so every improvement it gets, helps make this package better.

Historical context

This module started as part of docsit-client when we tried to speed up the IPFS operations of our documents, but we realized that it had so much more potential as an independent package.