From c5e72d03a7cdf4e87ee4ce482a0c35f294961b4c Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 30 Sep 2021 08:40:57 +0100 Subject: [PATCH] chore: use ipfs.addAll for streams `ipfs.add` is for single items, `ipfs.addAll` is for multiple. In the next ipfs release we will start enforcing this so update the example to call the correct method. --- examples/browser-add-readable-stream/src/index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/browser-add-readable-stream/src/index.js b/examples/browser-add-readable-stream/src/index.js index 5ea9e4c9..46ff72bd 100644 --- a/examples/browser-add-readable-stream/src/index.js +++ b/examples/browser-add-readable-stream/src/index.js @@ -110,12 +110,14 @@ const main = async () => { } }) - const data = await ipfs.add(stream) - - // The last data event will contain the directory hash - if (data.path === directory) { - return data.cid + for await (const data of ipfs.addAll(stream)) { + // The last data event will contain the directory hash + if (data.path === directory) { + return data.cid + } } + + throw new Error('Could not find directory in `ipfs.addAll` output') } const addFile = async (name, content, directory) => {