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

Commit 94801f1

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

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
@@ -709,11 +709,11 @@ ipfs.files.rm('/my/beautiful/directory', { recursive: true }, (err) => {
709709

710710
#### `read`
711711

712-
> Read a file.
712+
> Read a file into a [`Buffer`][b].
713713
714714
##### `Go` **WIP**
715715

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

718718
Where:
719719

@@ -722,15 +722,77 @@ Where:
722722
- `offset` is an Integer with the byte offset to begin reading from.
723723
- `count` is an Integer with the maximum number of bytes to read.
724724

725-
`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`.
725+
`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`.
726726

727727
If no `callback` is passed, a promise is returned.
728728

729729
**Example:**
730730

731731
```JavaScript
732732
ipfs.files.read('/hello-world', (err, buf) => {
733-
console.log(buf.toString())
733+
console.log(buf.toString('utf8'))
734+
})
735+
736+
// Hello, World!
737+
```
738+
739+
#### `readReadableStream`
740+
741+
> Read a file into a [`ReadableStream`][rs].
742+
743+
##### `Go` **WIP**
744+
745+
##### `JavaScript` - ipfs.files.readReadableStream(path, [options], [callback])
746+
747+
Where:
748+
749+
- `path` is the path of the object to read.
750+
- `options` is an optional Object that might contain the following keys:
751+
- `offset` is an Integer with the byte offset to begin reading from.
752+
- `count` is an Integer with the maximum number of bytes to read.
753+
754+
`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`.
755+
756+
If no `callback` is passed, a promise is returned.
757+
758+
**Example:**
759+
760+
```JavaScript
761+
ipfs.files.readReadableStream('/hello-world', (err, stream) => {
762+
stream.on('data', (buf) => console.log(buf.toString('utf8')))
763+
})
764+
765+
// Hello, World!
766+
```
767+
768+
#### `readPullStream`
769+
770+
> Read a file into a [`PullStream`][ps].
771+
772+
##### `Go` **WIP**
773+
774+
##### `JavaScript` - ipfs.files.readReadableStream(path, [options], [callback])
775+
776+
Where:
777+
778+
- `path` is the path of the object to read.
779+
- `options` is an optional Object that might contain the following keys:
780+
- `offset` is an Integer with the byte offset to begin reading from.
781+
- `count` is an Integer with the maximum number of bytes to read.
782+
783+
`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`.
784+
785+
If no `callback` is passed, a promise is returned.
786+
787+
**Example:**
788+
789+
```JavaScript
790+
ipfs.files.readPullStream('/hello-world', (err, stream) => {
791+
pull(
792+
stream,
793+
through(buf => console.log(buf.toString('utf8'))),
794+
collect(err => {})
795+
)
734796
})
735797

736798
// Hello, World!

0 commit comments

Comments
 (0)