Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
ipfs-unixfs-importer
Advanced tools
JavaScript implementation of the UnixFs importer used by IPFS
$ npm i ipfs-unixfs-importer
<script>
tagLoading 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>
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
}
import { importer, importFile, importDir, importBytes, importByteStream } from 'ipfs-unixfs-importer'
The importer
function returns an async iterator takes a source async iterator that yields objects of the form:
{
path: 'a name',
content: (Buffer or iterator emitting Buffers),
mtime: (Number representing seconds since (positive) or before (negative) the Unix Epoch),
mode: (Number representing ugo-rwx, setuid, setguid and sticky bit)
}
stream
will output file info objects as files get stored in IPFS. When stats on a node are emitted they are guaranteed to have been written.
blockstore
is an instance of a blockstore
The input's file paths and directory structure will be preserved in the dag-pb
created nodes.
A convenience function for importing a single file or directory.
A convenience function for importing a directory - note this is non-recursive, to import recursively use the importer function.
A convenience function for importing a single Uint8Array.
A convenience function for importing a single stream of Uint8Arrays.
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.
FAQs
JavaScript implementation of the UnixFs importer used by IPFS
The npm package ipfs-unixfs-importer receives a total of 32,497 weekly downloads. As such, ipfs-unixfs-importer popularity was classified as popular.
We found that ipfs-unixfs-importer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.