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

Commit 88ff0df

Browse files
committed
docs: add mfs stream ls methods
The only mfs ls method at the moment buffers the output into an array before returning it to the user. This PR adds two new methods, lsPullStream and lsReadableStream to allow the user to either buffer the output themseleves (in case they need sorting, etc) or just stream it on to an output of some sort.
1 parent 9959d02 commit 88ff0df

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

SPEC/FILES.md

+72
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
- [files.cp](#filescp)
2323
- [files.flush](#filesflush)
2424
- [files.ls](#filesls)
25+
- [files.lsReadableStream](#fileslsreadablestream)
26+
- [files.lsPullStream](#fileslspullstream)
2527
- [files.mkdir](#filesmkdir)
2628
- [files.mv](#filesmv)
2729
- [files.read](#filesread)
@@ -1090,6 +1092,7 @@ Where:
10901092
- `options` is an optional Object that might contain the following keys:
10911093
- `long` is a Boolean value to decide whether or not to populate `type`, `size` and `hash` (default: false)
10921094
- `cidBase` is which number base to use to format hashes - e.g. `base32`, `base64` etc (default: `base58btc`)
1095+
- `sort` is a Boolean value, if true entries will be sorted by filename (default: false)
10931096
- `callback` is an optional function with the signature `function (error, files) {}`, where `error` may be an Error that occured if the operation was not successful and `files` is an array containing Objects that contain the following keys:
10941097

10951098
- `name` which is the file's name
@@ -1112,6 +1115,75 @@ ipfs.files.ls('/screenshots', function (err, files) {
11121115
// 2018-01-22T18:08:49.184Z.png
11131116
```
11141117

1118+
#### `files.lsReadableStream`
1119+
1120+
> Lists a directory from the local mutable namespace that is addressed by a valid IPFS Path. The list will be yielded as Readable Streams.
1121+
1122+
##### `Go` **WIP**
1123+
1124+
##### `JavaScript` - ipfs.files.lsReadableStream([path], [options]) -> [Readable Stream][rs]
1125+
1126+
Where:
1127+
1128+
- `path` is an optional string to show listing for (default: `/`)
1129+
- `options` is an optional Object that might contain the following keys:
1130+
- `long` is a Boolean value to decide whether or not to populate `type`, `size` and `hash` (default: false)
1131+
- `cidBase` is which number base to use to format hashes - e.g. `base32`, `base64` etc (default: `base58btc`)
1132+
1133+
It returns a [Readable Stream][rs] in [Object mode](https://nodejs.org/api/stream.html#stream_object_mode) that will yield objects containing the following keys:
1134+
1135+
- `name` which is the file's name
1136+
- `type` which is the object's type (`directory` or `file`)
1137+
- `size` the size of the file in bytes
1138+
- `hash` the hash of the file
1139+
1140+
**Example:**
1141+
1142+
```JavaScript
1143+
const stream = ipfs.lsReadableStream('/some-dir')
1144+
1145+
stream.on('data', (file) => {
1146+
// write the file's path and contents to standard out
1147+
console.log(file.name)
1148+
})
1149+
```
1150+
1151+
#### `files.lsPullStream`
1152+
1153+
> Fetch a file or an entire directory tree from IPFS that is addressed by a valid IPFS Path. The files will be yielded through a Pull Stream.
1154+
1155+
##### `Go` **WIP**
1156+
1157+
##### `JavaScript` - ipfs.lsPullStream([path], [options]) -> [Pull Stream][ps]
1158+
1159+
Where:
1160+
1161+
- `path` is an optional string to show listing for (default: `/`)
1162+
- `options` is an optional Object that might contain the following keys:
1163+
- `long` is a Boolean value to decide whether or not to populate `type`, `size` and `hash` (default: false)
1164+
- `cidBase` is which number base to use to format hashes - e.g. `base32`, `base64` etc (default: `base58btc`)
1165+
1166+
It returns a [Pull Stream][os] that will yield objects containing the following keys:
1167+
1168+
- `name` which is the file's name
1169+
- `type` which is the object's type (`directory` or `file`)
1170+
- `size` the size of the file in bytes
1171+
- `hash` the hash of the file
1172+
1173+
**Example:**
1174+
1175+
```JavaScript
1176+
pull(
1177+
ipfs.lsPullStream('/some-dir'),
1178+
pull.through(file => {
1179+
console.log(file.name)
1180+
})
1181+
pull.onEnd(...)
1182+
)
1183+
```
1184+
1185+
A great source of [examples][] can be found in the tests for this API.
1186+
11151187
[examples]: https://github.com/ipfs/interface-ipfs-core/blob/master/js/src/files
11161188
[b]: https://www.npmjs.com/package/buffer
11171189
[rs]: https://www.npmjs.com/package/readable-stream

0 commit comments

Comments
 (0)