Skip to content
This repository was archived by the owner on Jun 30, 2023. It is now read-only.

Commit 352f0c3

Browse files
author
Alan Shaw
committed
docs: add docs for addPullStream
1 parent b9974bc commit 352f0c3

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

API.md

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
* [IpfsHttpClientLite](#ipfshttpclientlite)
44
* [add](#add)
5-
* [addPullStream](#addpullstream) TODO: add docs
5+
* [addPullStream](#addpullstream)
66
* [addFromStream](#addfromstream) TODO: add docs
77
* [addFromURL](#addfromurl) TODO: add docs
88
* [bitswap.stat](#bitswapstat) TODO: add docs
@@ -178,7 +178,6 @@ console.log(res)
178178
A stream:
179179

180180
```js
181-
const fs = require('fs')
182181
const res = await ipfs.add(fs.createReadStream('./package.json'))
183182
console.log(res)
184183
/*
@@ -195,7 +194,6 @@ console.log(res)
195194
##### Multiple files
196195

197196
```js
198-
const fs = require('fs')
199197
const res = await ipfs.add([
200198
{ path: 'my-package.json', content: fs.createReadStream('./package.json') },
201199
{ path: 'hello.txt', content: Buffer.from('hello world!') }
@@ -222,7 +220,6 @@ Wrap multiple files in a directory:
222220
In this example, the last item in the array is the wrapping directory, it allows you to access `hello.txt` using `ipfs.cat` with the following path `/ipfs/QmVY4sGYjQ4RNmJNBaJiWocTYAkzi4CkHfT16cXGouMdN7/hello.txt` but it can also be accessed using `ipfs.cat` with `/ipfs/QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j` (note the former uses the directory CID and the latter uses the file CID).
223221

224222
```js
225-
const fs = require('fs')
226223
const res = await ipfs.add([
227224
{ path: 'my-package.json', content: fs.createReadStream('./package.json') },
228225
{ path: 'hello.txt', content: Buffer.from('hello world!') }
@@ -251,6 +248,74 @@ console.log(res)
251248
*/
252249
```
253250

251+
## `addPullStream`
252+
253+
Add/import files and directories to IPFS via pull streams and retrieve their CID(s).
254+
255+
### `addPullStream([options]): PullThrough`
256+
257+
#### Parameters
258+
259+
* `options` (optional) See docs for [`add`](#add) for available options.
260+
* Type: `Object`
261+
* Default: `null`
262+
263+
#### Returns
264+
265+
A "through" pull stream that can be used in a pull pipeline.
266+
267+
#### Examples
268+
269+
##### Single file
270+
271+
```js
272+
const data = Buffer.from('hello world!')
273+
274+
pull(
275+
pull.values([data]),
276+
ipfs.addPullStream(),
277+
pull.collect((err, res) => console.log(res))
278+
)
279+
280+
/*
281+
[
282+
{
283+
name: 'QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j',
284+
hash: 'QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j',
285+
size: '20'
286+
}
287+
]
288+
*/
289+
```
290+
291+
##### Multiple files
292+
293+
```js
294+
pull(
295+
pull.values([
296+
{ path: 'my-package.json', content: fs.createReadStream('./package.json') },
297+
{ path: 'hello.txt', content: Buffer.from('hello world!') }
298+
]),
299+
ipfs.addPullStream(),
300+
pull.collect((err, res) => console.log(res))
301+
)
302+
303+
/*
304+
[
305+
{
306+
name: 'my-package.json',
307+
hash: 'QmPoPzFTHedjR4TJcQwx1rPv8YSqAnzzFT35194vC8UShH',
308+
size: '1919'
309+
},
310+
{
311+
name: 'hello.txt',
312+
hash: 'QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j',
313+
size: '20'
314+
}
315+
]
316+
*/
317+
```
318+
254319
## `cat`
255320

256321
Read files from IPFS.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ This module is in heavy development, not all API methods are available (or docum
140140

141141
* [IpfsHttpClientLite](./API.md#ipfshttpclientlite)
142142
* [add](./API.md#add)
143-
* [addPullStream](./API.md#addpullstream) TODO: add docs
143+
* [addPullStream](./API.md#addpullstream)
144144
* [addFromStream](./API.md#addfromstream) TODO: add docs
145145
* [addFromURL](./API.md#addfromurl) TODO: add docs
146146
* [bitswap.stat](./API.md#bitswapstat) TODO: add docs

0 commit comments

Comments
 (0)