Socket
Book a DemoInstallSign in
Socket

@ipld/unixfsv2

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ipld/unixfsv2

Filesystem in a merkle tree.

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
3
Created
Source

js-unixfsv2

This library is a full implementation of unixfs-v2 for JavaScript.

encoder(path, options={})

Async generator that yields blocks for every file and and directory in the path.

Last block is the root block.

Runs recursively through directories. Accepts any valid file or directory string path.

const { encoder } = require('unixfsv2')
const storage = require('any-key-value-store')

const putBlock = async b => storage.put((await b.cid()).toString(), b.encode())

const storeDirectory = async path => {
  for await (const { block, root } of encoder(__dirname)) {
    await storage.putBlock(block || root.block())
    if (root) return root.block().cid()
  }
}

reader(rootBlock, getBlock)

Returns a new Reader instance for the root block.

const { reader } = require('unixfsv2')
const storage = require('any-key-value-store')
const Block = require('@ipld/block')

const getBlock = async cid => Block.create(await storage.get(cid.toString()), cid)

/* rootBlock would be the same as the last block in
/  encode example.
*/
const r = reader(rootBlock, getBlock)

FAQs

Package last updated on 18 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts