npm install ipfs-unixfs-importer

JavaScript implementation of the UnixFs importer used by IPFS

About ipfs-unixfs-importer

The npm package "ipfs-unixfs-importer" is a critical tool within the InterPlanetary File System (IPFS) ecosystem, designed specifically to handle the importing of files and directory structures into the IPFS network using the UnixFS (Unix File System) format. This JavaScript implementation plays a pivotal role in ensuring that data added to IPFS maintains its structure and metadata effectively, mimicking traditional UNIX file systems. One of the primary benefits of using the "ipfs-unixfs-importer" is its ability to break down large files into smaller, manageable blocks, which are then hashed and stored in a decentralized manner. This not only enhances data retrieval speeds across the network but also boosts data redundancy and resilience, crucial for maintaining data integrity in a distributed system.

For developers looking to integrate this functionality into their projects, the process is straightforward. Simply run the command `npm install ipfs-unixfs-importer` in your project's root directory to add the package. This installation adds robust file handling capabilities to any application, enabling it to leverage the decentralized file storage benefits of IPFS. Once installed, developers can programmatically import files to IPFS, maintaining all the necessary attributes like file hierarchies and permissions which are essential for complex systems. This functionality is particularly beneficial for applications that need to handle large volumes of data or require a high degree of data availability and integrity.

The "ipfs-unixfs-importer" is not only about importing files efficiently but also about enhancing the scalability and performance of applications. By utilizing this package, developers can significantly reduce the overhead associated with traditional file uploads and storage, since IPFS nodes can cache files and serve them closer to the user, reducing latency and server load. This makes the "ipfs-unixfs-importer" an invaluable tool for building modern, efficient web applications that need to handle large datasets or provide fast, reliable access to a broad user base across different geographies.

More from ipfs

ipfs npm packages

Find the best node modules for your project.

Search npm

interface-datastore

datastore...

Read more
,

ipfs-unixfs

JavaScript implementation of IPFS' unixfs (a Unix FileSystem representation on top of a...

Read more
,

hamt-sharding

JavaScript implementation of sharding using hash array mapped...

Read more
,

ipfs-unixfs-importer

JavaScript implementation of the UnixFs importer used by...

Read more
,

is-ipfs

A set of utilities to help identify IPFS resources on the...

Read more
,

ipfs-unixfs-exporter

JavaScript implementation of the UnixFs exporter used by...

Read more
,

blockstore-core

Contains various implementations of the API contract described in...

Read more
,

ipfs-car

Convert files to content-addressed archives (...

Read more
,

datastore-core

Wrapper implementation for...

Read more
,

ipns

IPNS record...

Read more
,

datastore-level

Datastore implementation with level(up|down)...

Read more
,

ipfs-bitswap

JavaScript implementation of the Bitswap data exchange protocol used by...

Read more

Dependencies

Core dependencies of this npm package and its dev dependencies.

aegir, npm-run-all

Documentation

A README file for the ipfs-unixfs-importer code repository. View Code

ipfs-unixfs-importer

ipfs.tech Discuss codecov CI

JavaScript implementation of the UnixFs importer used by IPFS

About

Example

Let's create a little directory to import:

> cd /tmp
> mkdir foo
> echo 'hello' > foo/bar
> echo 'world' > foo/quux

And write the importing logic:

import { importer } from 'ipfs-unixfs-importer'
import { MemoryBlockstore } from 'blockstore-core/memory'
import * as fs from 'node:fs'

// Where the blocks will be stored
const blockstore = new MemoryBlockstore()

// Import path /tmp/foo/
const source = [{
  path: '/tmp/foo/bar',
  content: fs.createReadStream('/tmp/foo/bar')
}, {
  path: '/tmp/foo/quxx',
  content: fs.createReadStream('/tmp/foo/quux')
}]

for await (const entry of importer(source, blockstore)) {
  console.info(entry)
}

When run, metadata about DAGNodes in the created tree is printed until the root:

{
  cid: CID, // see https://github.com/multiformats/js-cid
  path: 'tmp/foo/bar',
  unixfs: UnixFS // see https://github.com/ipfs/js-ipfs-unixfs
}
{
  cid: CID, // see https://github.com/multiformats/js-cid
  path: 'tmp/foo/quxx',
  unixfs: UnixFS // see https://github.com/ipfs/js-ipfs-unixfs
}
{
  cid: CID, // see https://github.com/multiformats/js-cid
  path: 'tmp/foo',
  unixfs: UnixFS // see https://github.com/ipfs/js-ipfs-unixfs
}
{
  cid: CID, // see https://github.com/multiformats/js-cid
  path: 'tmp',
  unixfs: UnixFS // see https://github.com/ipfs/js-ipfs-unixfs
}

Install

$ npm i ipfs-unixfs-importer

Browser <script> tag

Loading this module through a script tag will make it's exports available as IpfsUnixfsImporter in the global namespace.

<script src="https://unpkg.com/ipfs-unixfs-importer/dist/index.min.js"></script>

API Docs

License

Licensed under either of

Contribute

Contributions welcome! Please check out the issues.

Also see 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.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.