You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
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.
Copy file name to clipboardexpand all lines: SPEC/FILES.md
+72
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,8 @@
22
22
-[files.cp](#filescp)
23
23
-[files.flush](#filesflush)
24
24
-[files.ls](#filesls)
25
+
-[files.lsReadableStream](#fileslsreadablestream)
26
+
-[files.lsPullStream](#fileslspullstream)
25
27
-[files.mkdir](#filesmkdir)
26
28
-[files.mv](#filesmv)
27
29
-[files.read](#filesread)
@@ -1090,6 +1092,7 @@ Where:
1090
1092
-`options` is an optional Object that might contain the following keys:
1091
1093
-`long` is a Boolean value to decide whether or not to populate `type`, `size` and `hash` (default: false)
1092
1094
-`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)
1093
1096
-`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:
1094
1097
1095
1098
-`name` which is the file's name
@@ -1112,6 +1115,75 @@ ipfs.files.ls('/screenshots', function (err, files) {
1112
1115
// 2018-01-22T18:08:49.184Z.png
1113
1116
```
1114
1117
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.
-`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
+
conststream=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.
0 commit comments