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

@chris.troutner/ipfs-message-port-client

v0.7.2

Published

IPFS client library for accessing IPFS node over message port

Downloads

7

Readme

ipfs-message-port-client

Travis CI Codecov branch Dependency Status js-standard-style

A client library for the IPFS API over message channel. This client library provides (subset) of IPFS API enabling applications to work with js-ipfs running in the different JS e.g. SharedWorker.

Lead Maintainer

Alex Potsides

Table of Contentens

Install

$ npm install --save ipfs-message-port-client

Usage

This client library works with IPFS node over the message channel and assumes that IPFS node is provided via ipfs-message-port-server on the other end.

It provides following API subset:

A client can be instantiated from the MessagePort instance. The primary goal of this library is to allow sharing a node across browsing contexts (tabs, iframes) and therefore most likely ipfs-message-port-server will be in a separate JS bundle and loaded in the SharedWorker.

const IPFSClient = require('ipfs-message-port-client')
// URL to the script containing ipfs-message-port-server.
const IPFS_SERVER_URL = '/bundle/ipfs-worker.js'

const main = async () => {
  const worker = new SharedWorker(IPFS_SERVER_URL)
  const ipfs = IPFSClient.from(worker.port)
  const data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')

  for await (const chunk of data) {
    console.log(chunk)
  }
}

It is also possible to instantiate a detached client, which can be attached to the server later on. This is useful when a server port is received via a message from another JS context (e.g. iframe)

Note: Client will queue all API calls and only execute them once it is attached (unless they time out or are aborted in the meantime).

const IPFSClient = require('ipfs-message-port-client')


const ipfs = IPFSClient.detached()

const main = async () => {
  const data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')

  for await (const chunk of data) {
    console.log(chunk)
  }
}

window.onload = main
window.onmessage = ({ports}) => {
  IPFSClient.attach(ports[0])
}

Notes on Performance

Since client works with IPFS node over message channel all the data passed is copied via structured cloning algorithm, which may lead to suboptimal results (especially with large binary data). In order to avoid unnecessary copying all API options have being extended with optional transfer property that can be supplied Transferables which will be used to move corresponding values instead of copying.

Note: Transferring data will empty it on the sender side which can lead to errors if that data is used again later. To avoid these errors transfer option was added so user can explicitly give up reference when it is safe to do so.

/**
 * @param {Uint8Array} data - Large data chunk
 */
const example = async (data) => {
  // Passing `data.buffer` will cause underlying `ArrayBuffer` to be
  // transferred emptying `data` in JS context.
  ipfs.add(data, { transfer: [data.buffer] })
}

It is however recommended to prefer web native Blob / File instances as most web APIs provide them as option & can be send across without copying underlying memory.

const example = async (url) => {
  const request = await fetch(url)
  const blob = await request.blob()
  ipfs.add(blob)
}

Contribute

Contributions welcome. Please check out the issues.

Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS Code of Conduct.

License

FOSSA Status