This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make add only work on single items (#3167)
`ipfs.add` now returns single items only. Where a source would result in multiple items returned, only the last item is returned. As a first pass `ipfs.add` still takes multiple items but only accepting single items is documented and considered supported. In the future it may throw if multiple items are passed. `ipfs.addAll` retains the previous behaviour of `ipfs.add`. Examples: ```javascript const { cid, path, mode, mtime } = await ipfs.add('Hello world') ``` ```javascript const { cid } = await ipfs.add(Uint8Array.from([0, 1, 2])) ``` ```javascript const { cid } = await ipfs.add(fs.createReadStream('/path/to/file.txt')) ``` ```javascript const { cid } = await ipfs.add({ path: '/foo/bar/baz.txt', content: 'File content' }) // Creates a DAG with multiple levels of directories. // The returned cid is the CID for the root directory /foo // You can retrieve the file content with an IPFS path for await (const buf of ipfs.cat(`/ipfs/${cid}/bar/baz.txt`)) { ... } // Or get the CID of the nested file with ipfs.files.stat const { cid: fileCid } = await ipfs.files.stat(`/ipfs/${cid}/bar/baz.txt`) // or ipfs.dag.resolve const { cid: fileCid } = await ipfs.dag.resolve(`/ipfs/${cid}/bar/baz.txt`) ``` ```javascript // To have `/foo` included in the ipfs path, wrap it in a directory: const { cid } = await ipfs.add({ path: '/foo/bar/baz.txt', content: 'File content' }, { wrapWithDirectory: true }) for await (const buf of ipfs.cat(`/ipfs/${cid}/foo/bar/baz.txt`)) { ... } ``` BREAKING CHANGES: - `ipfs.add` only works on single items - a Uint8Array, a String, an AsyncIterable<Uint8Array> etc - `ipfs.addAll` works on multiple items
- Loading branch information
1 parent
8c122e8
commit 1760b89
Showing
76 changed files
with
979 additions
and
704 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.