Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 08a5aa0

Browse files
committed
Add API reference for files.get.
1 parent 1ee0bac commit 08a5aa0

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

API/files/README.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ ipfs.files.createAddStream(function (err, stream) {
9393

9494

9595

96-
#### `cat`
96+
#### `cat`
9797

98-
> Streams the file at the given IPFS multihash..
98+
> Streams the file at the given IPFS multihash.
9999
100100
##### `Go` **WIP**
101101

@@ -116,3 +116,43 @@ ipfs.files.cat(multihash, function (err, file) {
116116
})
117117
```
118118

119+
120+
#### `get`
121+
> Get [UnixFS][] files from IPFS.
122+
123+
##### `Go` **WIP**
124+
125+
##### `JavaScript` - ipfs.files.get(hash, [callback])
126+
127+
Where `hash` is an IPFS multiaddress or multihash.
128+
129+
`callback` must follow `function (err, stream) {}` signature, where `err` is an
130+
error if the operation was not successful. `stream` will be a Readable stream in
131+
[*object mode*](https://nodejs.org/api/stream.html#stream_object_mode),
132+
outputting objects of the form
133+
134+
```js
135+
{
136+
path: '/tmp/myfile.txt',
137+
content: <Readable stream>
138+
}
139+
```
140+
141+
Here, each `path` corresponds to the name of a file, and `content` is a regular
142+
Readable stream with the raw contents of that file.
143+
144+
If no `callback` is passed, a promise is returned with the Readable stream.
145+
146+
Example:
147+
148+
```js
149+
var multiaddr = '/ipfs/QmQ2r6iMNpky5f1m4cnm3Yqw8VSvjuKpTcK1X7dBR1LkJF'
150+
ipfs.files.get(multiaddr, function (err, stream) {
151+
stream.on('data', (file) => {
152+
// write the file's path and contents to standard out
153+
console.log(file.path)
154+
file.content.pipe(process.stdout)
155+
})
156+
})
157+
```
158+

0 commit comments

Comments
 (0)