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

ipfs-unixfs

v11.1.4

Published

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

Downloads

452,248

Readme

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:

  • type (string, default file): The type of UnixFS entry. Can be:
    • raw
    • directory
    • file
    • metadata
    • symlink
    • hamt-sharded-directory
  • data (Uint8Array): The optional data field for this node
  • blockSizes (Array, default: []): 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.
  • mode (Number, default 0644 for files, 0755 for directories/hamt-sharded-directories) file mode
  • mtime (Date, { secs, nsecs }, { Seconds, FractionalNanoseconds }, [ secs, nsecs ]): The modification time of this node

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.