npm install ipfs-unixfs

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

About ipfs-unixfs

The npm package "ipfs-unixfs" is a crucial tool for developers looking to leverage the InterPlanetary File System (IPFS) with a familiar Unix filesystem interface. This package allows for the efficient handling of files and directories in applications that utilize IPFS, a peer-to-peer protocol for storing and sharing data in a distributed file system. By using "ipfs-unixfs," developers can create, read, and manage files using standard Unix filesystem semantics, but with the added benefits of IPFS such as decentralization, redundancy, and immutability. This makes it an ideal choice for projects requiring high availability and security for file storage.

To get started with "ipfs-unixfs," developers can easily integrate it into their projects by running the command npm install ipfs-unixfs. This installation command sets up the node module in your project environment, allowing you to begin constructing applications with IPFS capabilities enhanced by the Unix filesystem paradigm. The module provides a set of APIs that mimic traditional file handling operations, such as adding, removing, and modifying files, thereby simplifying the transition for developers familiar with standard file system operations.

The benefits of using "ipfs-unixfs" extend beyond simple file manipulation. It encapsulates the complexities of dealing with a decentralized network while providing a straightforward, scalable solution for managing data. Whether you are building a decentralized application (dApp), a content delivery network, or a system for archiving large volumes of data, "ipfs-unixfs" offers a robust framework for managing file data in a distributed environment. This not only enhances data integrity and accessibility but also significantly reduces the risks associated with data loss and censorship.

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 code repository. View Code

ipfs-unixfs

ipfs.tech Discuss codecov CI

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

About

This module contains the protobuf definition of the UnixFS data structure found at the root of all UnixFS DAGs.

The UnixFS spec can be found in the ipfs/specs repository

Example - Create a file composed of several blocks

const data = new UnixFS({ type: 'file' })
data.addBlockSize(256) // add the size of each block
data.addBlockSize(256)
// ...

Example - Create a directory that contains several files

Creating a directory that contains several files is achieve by creating a unixfs element that identifies a MerkleDAG node as a directory. The links of that MerkleDAG node are the files that are contained in this directory.

const data = new UnixFS({ type: 'directory' })

Example - Create an unixfs Data element

const data = new UnixFS([options])

options is an optional object argument that might include the following keys:

Example - Add and remove a block size to the block size list

data.addBlockSize(<size in bytes>)
data.removeBlockSize(<index>)

Example - Get total fileSize

data.fileSize() // => size in bytes

Example - Marshal and unmarshal

const marshaled = data.marshal()
const unmarshaled = Unixfs.unmarshal(marshaled)

Example - Is this UnixFS entry a directory?

const dir = new Data({ type: 'directory' })
dir.isDirectory() // true

const file = new Data({ type: 'file' })
file.isDirectory() // false

Example - Has an mtime been set?

If no modification time has been set, no mtime property will be present on the Data instance:

const file = new Data({ type: 'file' })
file.mtime // undefined

Object.prototype.hasOwnProperty.call(file, 'mtime') // false

const dir = new Data({ type: 'dir', mtime: new Date() })
dir.mtime // { secs: Number, nsecs: Number }

Install

$ npm i ipfs-unixfs

Browser <script> tag

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

<script src="https://unpkg.com/ipfs-unixfs/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.