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

Commit

Permalink
Add API reference for files.get.
Browse files Browse the repository at this point in the history
  • Loading branch information
hackergrrl committed Aug 9, 2016
1 parent f0be3dd commit 9ee6b5e
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions API/files/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ ipfs.files.createAddStream(function (err, stream) {



#### `cat`
#### `cat`

> Streams the file at the given IPFS multihash..
> Streams the file at the given IPFS multihash.
##### `Go` **WIP**

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


#### `get`
> Get [UnixFS][] files from IPFS.
##### `Go` **WIP**

##### `JavaScript` - ipfs.files.get(hash, [callback])

Where `hash` is an IPFS multiaddress or multihash.

`callback` must follow `function (err, stream) {}` signature, where `err` is an
error if the operation was not successful. `stream` will be a Readable stream in
[*object mode*](https://nodejs.org/api/stream.html#stream_object_mode),
outputting objects of the form

```js
{
path: '/tmp/myfile.txt',
content: <Readable stream>
}
```

Here, each `path` corresponds to the name of a file, and `content` is a regular
Readable stream with the raw contents of that file.

If no `callback` is passed, a promise is returned with the Readable stream.

Example:

```js
var multiaddr = '/ipfs/QmQ2r6iMNpky5f1m4cnm3Yqw8VSvjuKpTcK1X7dBR1LkJF'
ipfs.files.get(multiaddr, function (err, stream) {
stream.on('data', (file) => {
// write the file's path and contents to standard out
console.log(file.path)
file.content.pipe(process.stdout)
})
})
```

0 comments on commit 9ee6b5e

Please sign in to comment.