@bablr/fs 1.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -4
- package/lib/index.js +2 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,16 +5,22 @@ This package offers fast, responsive, efficient access to the filesystem. Node's
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
7
7
|
```js
|
|
8
|
-
import { readFile, readDir } from '@bablr/fs';
|
|
8
|
+
import { readFile, readDir, decodeUTF8 } from '@bablr/fs';
|
|
9
9
|
|
|
10
|
-
let fileIterable = readFile(import.meta.url
|
|
10
|
+
let fileIterable = decodeUTF8(readFile(import.meta.url));
|
|
11
11
|
let directoryIterable = readDir('./');
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
## Why stream iterables?
|
|
15
15
|
|
|
16
|
-
Stream iterables offer a trifecta of desirable features:
|
|
16
|
+
[Stream iterables](https://github.com/bablr-lang/stream-iterator) are a way of using iterators as an abstraction over asynchronous data access in Javascript. They propagate both sync-ness and async-ness, moving data in an efficient way comparable to how a bucket brigade moves buckets of water. Stream iterables offer a trifecta of desirable features:
|
|
17
17
|
|
|
18
18
|
- Abstraction: they doesn’t require the provider to copy the data or expose its internal structure (benefit over web streams)
|
|
19
19
|
- Throughput: stream iterators have high throughput and efficiency when used on streams of many small items because only some steps must wait (benefit over flat async iterators)
|
|
20
|
-
- Responsiveness: returning the first data from a 20GB file doesn’t cause a huge delay, it takes just the same amount of time as opening a one-chunk file (benefit over fs.openFileSync
|
|
20
|
+
- Responsiveness: returning the first data from a 20GB file doesn’t cause a huge delay, it takes just the same amount of time as opening a one-chunk file (benefit over fs.openFileSync)
|
|
21
|
+
|
|
22
|
+
## Language support
|
|
23
|
+
|
|
24
|
+
Stream iterables are not yet supported natively by JS, yet they are still possible to construct and consume using libraries. They are a primitive data type in JS: nothing about them can be made any simpler. Compare this to the officially supported "[web streams](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API)", nothing about which could be made more complex.
|
|
25
|
+
|
|
26
|
+
We are thus looking for a champion for a `Symbol.streamIterator` proposal to TC39.
|
package/lib/index.js
CHANGED
|
@@ -121,14 +121,8 @@ function* __readFile(path) {
|
|
|
121
121
|
} while (!result.done);
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
export const readFile = (path
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (encoding && !/utf-?8/i.test(encoding)) throw new Error('unsupported encoding');
|
|
128
|
-
|
|
129
|
-
let bytes = new StreamIterable(__readFile(path, options));
|
|
130
|
-
|
|
131
|
-
return encoding ? decodeUTF8(bytes) : bytes;
|
|
124
|
+
export const readFile = (path) => {
|
|
125
|
+
return new StreamIterable(__readFile(path));
|
|
132
126
|
};
|
|
133
127
|
|
|
134
128
|
function* __readDir(path) {
|