Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
ipfs-unixfs
Advanced tools
JavaScript implementation of IPFS' unixfs (a Unix FileSystem representation on top of a MerkleDAG)
JavaScript implementation of IPFS' UnixFS (a Unix FileSystem files representation on top of a MerkleDAG)
The UnixFS spec can be found inside the ipfs/specs repository
> npm i ipfs-unixfs
import { UnixFS } from 'ipfs-unixfs'
The code published to npm that gets loaded on require is in fact a ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process.
import { UnixFS } from 'ipfs-unixfs'
Loading this module through a script tag will make the UnixFS
obj available in the global namespace.
<script src="https://npmcdn.com/ipfs-unixfs/dist/index.min.js"></script>
<!-- OR -->
<script src="https://npmcdn.com/ipfs-unixfs/dist/index.js"></script>
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' })
syntax = "proto2";
message Data {
enum DataType {
Raw = 0;
Directory = 1;
File = 2;
Metadata = 3;
Symlink = 4;
HAMTShard = 5;
}
required DataType Type = 1;
optional bytes Data = 2;
optional uint64 filesize = 3;
repeated uint64 blocksizes = 4;
optional uint64 hashType = 5;
optional uint64 fanout = 6;
optional uint32 mode = 7;
optional UnixTime mtime = 8;
}
message UnixTime {
required int64 Seconds = 1;
optional fixed32 FractionalNanoseconds = 2;
}
message Metadata {
optional string MimeType = 1;
}
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 }
Feel free to join in. All welcome. Open an issue!
This repository falls under the IPFS Code of Conduct.
FAQs
JavaScript implementation of IPFS' unixfs (a Unix FileSystem representation on top of a MerkleDAG)
The npm package ipfs-unixfs receives a total of 85,632 weekly downloads. As such, ipfs-unixfs popularity was classified as popular.
We found that ipfs-unixfs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.