How to use the ipfs-unixfs.default function in ipfs-unixfs

To help you get started, we’ve selected a few ipfs-unixfs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AugurProject / augur / packages / augur-sdk / src / warp / WarpController.ts View on Github external
const file = Unixfs.default('file');
    for (let i = 0; i < results.length; i++) {
      file.addBlockSize(results[i].size);
    }

    const indexFile = new DAGNode(file.marshal());
    for (let i = 0; i < results.length; i++) {
      indexFile.addLink({
        Hash: results[i].hash,
        Size: results[i].size
      });
    }

    const indexFileResponse = await this.ipfs.dag.put(indexFile, WarpController.DEFAULT_NODE_TYPE);

    const directory = Unixfs.default('directory');
    for (let i = 0; i < results.length; i++) {
      directory.addBlockSize(results[i].size);
    }

    directory.addBlockSize(file.fileSize());
    const directoryNode = new DAGNode(directory.marshal());
    for (let i = 0; i < results.length; i++) {
      console.log(results[i]);
      directoryNode.addLink({
        Name: `file${i}`,
        Hash: results[i].hash,
        Size: results[i].size
      });
    }

    directoryNode.addLink({
github AugurProject / augur / packages / augur-sdk / src / warp / WarpController.ts View on Github external
async addDBToIPFS(table: Dexie.Table) {
    const results = await this.ipfsAddRows(await table.toArray());

    const file = Unixfs.default('file');
    for (let i = 0; i < results.length; i++) {
      file.addBlockSize(results[i].size);
    }

    const indexFile = new DAGNode(file.marshal());
    for (let i = 0; i < results.length; i++) {
      indexFile.addLink({
        Hash: results[i].hash,
        Size: results[i].size
      });
    }

    const indexFileResponse = await this.ipfs.dag.put(indexFile, WarpController.DEFAULT_NODE_TYPE);

    const directory = Unixfs.default('directory');
    for (let i = 0; i < results.length; i++) {
github AugurProject / augur / packages / augur-sdk / src / warp / WarpController.ts View on Github external
async createAllCheckpoints() {
    const otherDir = new DAGNode(Unixfs.default('directory').marshal());
    const versionFile = await this.ipfs.add({
      content: Buffer.from(WARPSYNC_VERSION),
    });
    otherDir.addLink({
      Name: 'VERSION',
      Hash: versionFile[0].hash,
      Size: 1,
    });

    for(const table of this.db.databasesToSync()) {
      const r = await this.addDBToIPFS(table);
      otherDir.addLink(r);
    }

    const d = await this.ipfs.dag.put(otherDir, WarpController.DEFAULT_NODE_TYPE);
    return d.toString();

ipfs-unixfs

JavaScript implementation of IPFS' unixfs (a Unix FileSystem representation on top of a MerkleDAG)

Apache-2.0 OR MIT
Latest version published 29 days ago

Package Health Score

81 / 100
Full package analysis

Popular ipfs-unixfs functions