js-ipfs-unixfs
    Preparing search index...

    Module ipfs-unixfs

    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

    import { UnixFS } from 'ipfs-unixfs'

    const data = new UnixFS({ type: 'file' })
    data.addBlockSize(256n) // add the size of each block
    data.addBlockSize(256n)
    // ...

    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'

    const data = new UnixFS({ type: 'directory' })
    import { UnixFS } from 'ipfs-unixfs'

    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
    import { UnixFS } from 'ipfs-unixfs'

    const data = new UnixFS({ type: 'file' })
    const sizeInBytes = 100n
    data.addBlockSize(sizeInBytes)
    import { UnixFS } from 'ipfs-unixfs'

    const data = new UnixFS({ type: 'file' })

    const index = 0
    data.removeBlockSize(index)
    import { UnixFS } from 'ipfs-unixfs'

    const data = new UnixFS({ type: 'file' })
    data.fileSize() // => size in bytes
    import { UnixFS } from 'ipfs-unixfs'

    const data = new UnixFS({ type: 'file' })
    const marshaled = data.marshal()
    const unmarshaled = UnixFS.unmarshal(marshaled)

    Example: Is this UnixFS entry a directory?

    import { UnixFS } from 'ipfs-unixfs'

    const dir = new UnixFS({ type: 'directory' })
    dir.isDirectory() // true

    const file = new UnixFS({ type: 'file' })
    file.isDirectory() // false

    If no modification time has been set, no mtime property will be present on the Data instance:

    import { UnixFS } from 'ipfs-unixfs'

    const file = new UnixFS({ type: 'file' })
    file.mtime // undefined

    Object.prototype.hasOwnProperty.call(file, 'mtime') // false

    const dir = new UnixFS({ type: 'directory', mtime: { secs: 5n } })
    dir.mtime // { secs: Number, nsecs: Number }

    Classes

    InvalidTypeError
    InvalidUnixFSMessageError
    UnixFS

    Interfaces

    Mtime
    UnixFSOptions

    Type Aliases

    MtimeLike
    UnixFSType