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

Commit d8e4819

Browse files
committed
Adds API for ipfs.files.get.
1 parent bb63627 commit d8e4819

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

API/files/README.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
files API
1+
Files API
22
=========
33

44
#### `add`
@@ -92,8 +92,43 @@ ipfs.files.createAddStream(function (err, stream) {
9292

9393

9494

95+
### `get`
9596

96-
#### `cat`
97+
> Get [UnixFS][] files from IPFS.
98+
99+
##### `Go` **WIP**
100+
101+
##### `JavaScript` - ipfs.files.get(hash, [callback])
102+
103+
Where `hash` is an IPFS multiaddress or multihash.
104+
105+
`callback` must follow `function (err, stream) {}` signature, where `err` is an
106+
error if the operation was not successful. `stream` will be a Readable stream,
107+
outputting objects of the form
108+
109+
```js
110+
{
111+
path: '/tmp/myfile.txt',
112+
content: Readable stream
113+
}
114+
```
115+
116+
If no `callback` is passed, a promise is returned with the Readable stream.
117+
118+
Example:
119+
120+
```js
121+
ipfs.files.get('QmQ2r6iMNpky5f1m4cnm3Yqw8VSvjuKpTcK1X7dBR1LkJF', function (err, stream) {
122+
stream.on('data', (file) => {
123+
console.log(file.path)
124+
file.content.pipe(process.stdout)
125+
})
126+
})
127+
```
128+
129+
130+
131+
#### `cat`
97132

98133
> Streams the file at the given IPFS multihash..
99134
@@ -103,7 +138,7 @@ ipfs.files.createAddStream(function (err, stream) {
103138

104139
`multihash` is a [multihash][] which can be passed as
105140

106-
- Buffer, the raw Buffer of the multihash
141+
- Buffer, the raw Buffer of the multihash
107142
- String, the base58 encoded version of the multihash
108143

109144
`callback` must follow `function (err, stream) {}` signature, where `err` is an error if the operation was not successful and `stream` is a readable stream of the file.

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ interface-ipfs-core API.
6060

6161
## Install
6262

63-
In JavaScript land:
64-
```js
63+
In JavaScript using [npm](http://npmjs.org/):
64+
```
6565
npm install interface-ipfs-core
6666
```
6767

6868
In Go land:
6969

70-
```go
70+
```
7171
# Not available
7272
```
7373

@@ -114,3 +114,5 @@ This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/c
114114
## License
115115

116116
MIT
117+
118+
[UnixFS]: https://github.com/ipfs/specs/tree/master/unixfs

0 commit comments

Comments
 (0)