1.1.4 • Published 5 months ago
@mdip/ipfs v1.1.4
MDIP IPFS
MDIP utilities for integrating with IPFS.
Installation
npm install @mdip/ipfsUsage
basic use
// Import using subpaths
import HeliaClient from '@mdip/ipfs/helia';
// Non-subpath import
import { HeliaClient } from '@mdip/ipfs';
const ipfs = new HeliaClient();
await ipfs.start();
const data = { data: 'whatever' };
const cid = await ipfs.addJSON(data);
const retrieve = await ipfs.getJSON(cid); // retrieve == data
await ipfs.stop();create factory
The static factory method create can be used to create and start an IPFS instance:
const ipfs = await HeliaClient.create();FS blockstore mode
Passing datadir in options to start or create will persist the data to the specified folder.
const ipfs = await HeliaClient.create({ datadir: 'data/ipfs' });minimal mode
Starting IPFS in minimal mode avoids starting a Helia IPFS server.
Only add works to generate CIDs. Nothing is persisted so get always throws a NotConnectedError.
const ipfs = await HeliaClient.create({ minimal: true });