0
    const sources = files.map((file) => ({ path: `${file.index}${extension}`, content: file.buffer }));
        for await (const result of ipfs.addAll(sources, { wrapWithDirectory: true })) {
          Logger.log(`Uploaded: ${result.path}`);
          if (result.path === "") {
            rootCid = result.cid.toString();
          }
        }
    const sources = files.map((file) => ({ path: `root/${file.index}${extension}`, content: file.buffer }));
        for await (const result of ipfs.addAll(sources)) {
          Logger.log(`Uploaded: ${result.path}`);
          if (result.path === "root") {
            rootCid = result.cid.toString();
          }
        }

The rootCid will be the same for both of the above codes, but { wrapWithDirectory: true } is very slower. Why is this?

1 Answers1

0

This is because the execution time of ipfs' api method addAll is O(n) where n is the number of items in your input array

In other words, the more items you wish to add at once the longer it takes because each one creates an API call to add the item and each call must be awaited

Liam O'Toole
  • 167
  • 3
  • 13