JavaScript implementation of IPFS' unixfs (a Unix FileSystem representation on top of a MerkleDAG)
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.
Core dependencies of this npm package and its dev dependencies.
aegir, npm-run-all
A README file for the ipfs-unixfs code repository. View Code
JavaScript implementation of IPFS' unixfs (a Unix FileSystem representation on top of a MerkleDAG)
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
const data = new UnixFS({ type: 'file' })
data.addBlockSize(256) // add the size of each block
data.addBlockSize(256)
// ...
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' })
const data = new UnixFS([options])
options
is an optional object argument that might include the following keys:
file
): The type of UnixFS entry. Can be:raw
directory
file
metadata
symlink
hamt-sharded-directory
[]
): If this is a file
node that is made up of multiple blocks, blockSizes
is a list numbers that represent the size of the file chunks stored in each child node. It is used to calculate the total file size.0644
for files, 0755
for directories/hamt-sharded-directories) file modeDate
, { secs, nsecs }
, { Seconds, FractionalNanoseconds }
, [ secs, nsecs ]
): The modification time of this nodedata.addBlockSize(<size in bytes>)
data.removeBlockSize(<index>)
data.fileSize() // => size in bytes
const marshaled = data.marshal()
const unmarshaled = Unixfs.unmarshal(marshaled)
const dir = new Data({ type: 'directory' })
dir.isDirectory() // true
const file = new Data({ type: 'file' })
file.isDirectory() // false
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 }
$ npm i ipfs-unixfs
<script>
tagLoading 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>
Licensed under either of
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.