You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
refactor: ipfs.add only works on single items, ipfs.addAll works on multiple
`ipfs.add` returns single items only. Where a source would result in multiple items returned, only the last item is returned.
`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(Uint16Array.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
// (stat or something like it should really be a root level command)
const { cid: fileCid } = await ipfs.files.stat(`/ipfs/${cid}/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
As an object, `secs` is the number of seconds since (positive) or before (negative) the Unix Epoch began and `nsecs` is the number of nanoseconds since the last full second.
145
+
146
+
As an array of numbers, it must have two elements, as per the output of [`process.hrtime()`](https://nodejs.org/dist/latest/docs/api/process.html#process_process_hrtime_time).
147
+
148
+
#### Options
149
+
150
+
An optional object which may have the following keys:
151
+
152
+
| Name | Type | Default | Description |
153
+
| ---- | ---- | ------- | ----------- |
154
+
| chunker |`String`|`'size-262144`| chunking algorithm used to build ipfs DAGs |
155
+
| cidVersion |`Number`|`0`| the CID version to use when storing the data |
156
+
| hashAlg |`String`|`'sha2-256'`| multihash hashing algorithm to use |
157
+
| onlyHash |`boolean`|`false`| If true, will not add blocks to the blockstore |
158
+
| pin |`boolean`|`true`| pin this object when adding |
159
+
| progress | function |`undefined`| a function that will be called with the byte length of chunks as a file is added to ipfs |
160
+
| rawLeaves |`boolean`|`false`| if true, DAG leaves will contain raw file data and not be wrapped in a protobuf |
161
+
| trickle |`boolean`|`false`| if true will use the [trickle DAG](https://godoc.org/github.com/ipsn/go-ipfs/gxlibs/github.com/ipfs/go-unixfs/importer/trickle) format for DAG generation |
162
+
| wrapWithDirectory |`boolean`|`false`| Adds a wrapping node around the content |
163
+
| timeout |`Number`|`undefined`| A timeout in ms |
164
+
| signal |[AbortSignal][]|`undefined`| Can be used to cancel any long running requests started as a result of this call |
165
+
166
+
#### Returns
167
+
168
+
| Type | Description |
169
+
| -------- | -------- |
170
+
|`UnixFSEntry`| A object describing the added data |
0 commit comments