constdata = newUnixFS({ type:'file' }) data.addBlockSize(256n) // add the size of each block data.addBlockSize(256n) // ...
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.
import { UnixFS } from'ipfs-unixfs'
constdata = newUnixFS({ type:'directory' })
Example: Create an unixfs Data element
import { UnixFS } from'ipfs-unixfs'
constdata = newUnixFS({ // ...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
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
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.
Example: Create an unixfs Data element
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 afile
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 nodeExample: Add and remove a block size to the block size list
Example: Get total fileSize
Example: Marshal and unmarshal
Example: Is this UnixFS entry a directory?
Example: Has an mtime been set?
If no modification time has been set, no
mtime
property will be present on theData
instance: