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

Commit 0f8c02d

Browse files
committed
docs: adds stream-related mfs files.read method signatures
License: MIT Signed-off-by: achingbrain <alex@achingbrain.net>
1 parent d3986c0 commit 0f8c02d

File tree

1 file changed

+66
-4
lines changed

1 file changed

+66
-4
lines changed

SPEC/FILES.md

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -728,11 +728,11 @@ ipfs.files.rm('/my/beautiful/directory', { recursive: true }, (err) => {
728728

729729
#### `files.read`
730730

731-
> Read a file.
731+
> Read a file into a [`Buffer`][b].
732732
733733
##### `Go` **WIP**
734734

735-
##### `JavaScript` - ipfs.files.read(path, [options, callback])
735+
##### `JavaScript` - ipfs.files.read(path, [options], [callback])
736736

737737
Where:
738738

@@ -741,15 +741,77 @@ Where:
741741
- `offset` is an Integer with the byte offset to begin reading from.
742742
- `count` is an Integer with the maximum number of bytes to read.
743743

744-
`callback` must follow the `function (err, buf) {}` signature, where `err` is an Error if the operation was not successful and `buf` is a Buffer with the contents of `path`.
744+
`callback` must follow the `function (err, buf) {}` signature, where `err` is an Error if the operation was not successful and `buf` is a [`Buffer`][b] with the contents of `path`.
745745

746746
If no `callback` is passed, a promise is returned.
747747

748748
**Example:**
749749

750750
```JavaScript
751751
ipfs.files.read('/hello-world', (err, buf) => {
752-
console.log(buf.toString())
752+
console.log(buf.toString('utf8'))
753+
})
754+
755+
// Hello, World!
756+
```
757+
758+
#### `readReadableStream`
759+
760+
> Read a file into a [`ReadableStream`][rs].
761+
762+
##### `Go` **WIP**
763+
764+
##### `JavaScript` - ipfs.files.readReadableStream(path, [options], [callback])
765+
766+
Where:
767+
768+
- `path` is the path of the object to read.
769+
- `options` is an optional Object that might contain the following keys:
770+
- `offset` is an Integer with the byte offset to begin reading from.
771+
- `count` is an Integer with the maximum number of bytes to read.
772+
773+
`callback` must follow the `function (err, stream) {}` signature, where `err` is an Error if the operation was not successful and `stream` is a [`ReadableStream`][rs] with the contents of `path`.
774+
775+
If no `callback` is passed, a promise is returned.
776+
777+
**Example:**
778+
779+
```JavaScript
780+
ipfs.files.readReadableStream('/hello-world', (err, stream) => {
781+
stream.on('data', (buf) => console.log(buf.toString('utf8')))
782+
})
783+
784+
// Hello, World!
785+
```
786+
787+
#### `readPullStream`
788+
789+
> Read a file into a [`PullStream`][ps].
790+
791+
##### `Go` **WIP**
792+
793+
##### `JavaScript` - ipfs.files.readReadableStream(path, [options], [callback])
794+
795+
Where:
796+
797+
- `path` is the path of the object to read.
798+
- `options` is an optional Object that might contain the following keys:
799+
- `offset` is an Integer with the byte offset to begin reading from.
800+
- `count` is an Integer with the maximum number of bytes to read.
801+
802+
`callback` must follow the `function (err, stream) {}` signature, where `err` is an Error if the operation was not successful and `stream` is a [`PullStream`][ps] with the contents of `path`.
803+
804+
If no `callback` is passed, a promise is returned.
805+
806+
**Example:**
807+
808+
```JavaScript
809+
ipfs.files.readPullStream('/hello-world', (err, stream) => {
810+
pull(
811+
stream,
812+
through(buf => console.log(buf.toString('utf8'))),
813+
collect(err => {})
814+
)
753815
})
754816

755817
// Hello, World!

0 commit comments

Comments
 (0)