@gjsify/stream 0.0.3 → 0.1.0
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 +26 -2
- package/cjs-compat.cjs +7 -0
- package/lib/esm/consumers/index.js +37 -4
- package/lib/esm/index.js +1096 -4
- package/lib/esm/promises/index.js +28 -4
- package/lib/esm/web/index.js +34 -3
- package/lib/types/consumers/index.d.ts +13 -3
- package/lib/types/index.d.ts +182 -5
- package/lib/types/promises/index.d.ts +8 -3
- package/lib/types/web/index.d.ts +3 -3
- package/package.json +23 -45
- package/src/consumers/index.spec.ts +107 -0
- package/src/consumers/index.ts +39 -3
- package/src/edge-cases.spec.ts +593 -0
- package/src/index.spec.ts +2239 -7
- package/src/index.ts +1348 -5
- package/src/promises/index.spec.ts +140 -0
- package/src/promises/index.ts +31 -3
- package/src/test.mts +5 -2
- package/src/web/index.ts +32 -3
- package/tsconfig.json +21 -9
- package/tsconfig.tsbuildinfo +1 -0
- package/lib/cjs/consumers/index.js +0 -6
- package/lib/cjs/index.js +0 -6
- package/lib/cjs/promises/index.js +0 -6
- package/lib/cjs/web/index.js +0 -6
- package/test.gjs.js +0 -34839
- package/test.gjs.mjs +0 -34728
- package/test.gjs.mjs.meta.json +0 -1
- package/test.node.js +0 -1234
- package/test.node.mjs +0 -315
- package/tsconfig.types.json +0 -8
- package/tsconfig.types.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -1,10 +1,34 @@
|
|
|
1
1
|
# @gjsify/stream
|
|
2
2
|
|
|
3
|
-
Node.js stream module
|
|
3
|
+
GJS implementation of the Node.js `stream` module. Provides Readable, Writable, Duplex, Transform, and PassThrough streams.
|
|
4
|
+
|
|
5
|
+
Part of the [gjsify](https://github.com/gjsify/gjsify) project — Node.js and Web APIs for GJS (GNOME JavaScript).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @gjsify/stream
|
|
11
|
+
# or
|
|
12
|
+
yarn add @gjsify/stream
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { Readable, Writable, Transform } from '@gjsify/stream';
|
|
19
|
+
|
|
20
|
+
const readable = Readable.from(['hello', 'world']);
|
|
21
|
+
readable.on('data', (chunk) => console.log(chunk));
|
|
22
|
+
```
|
|
4
23
|
|
|
5
24
|
## Inspirations and credits
|
|
25
|
+
|
|
6
26
|
- https://github.com/browserify/stream-browserify
|
|
7
27
|
- https://github.com/geut/brode/blob/main/packages/browser-node-core/src/stream.js
|
|
8
28
|
- https://github.com/exogee-technology/readable-stream
|
|
9
29
|
- https://github.com/nodejs/readable-stream
|
|
10
|
-
- https://github.com/denoland/deno_std/blob/main/node/stream.ts
|
|
30
|
+
- https://github.com/denoland/deno_std/blob/main/node/stream.ts
|
|
31
|
+
|
|
32
|
+
## License
|
|
33
|
+
|
|
34
|
+
MIT
|
package/cjs-compat.cjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// CJS compatibility wrapper for npm packages that require('stream')
|
|
2
|
+
// In Node.js CJS, require('stream') returns the Stream constructor directly.
|
|
3
|
+
// When esbuild bundles ESM @gjsify/stream for CJS consumers, it returns a
|
|
4
|
+
// namespace object instead. This wrapper extracts the default export (the
|
|
5
|
+
// Stream class with all properties like Readable, Writable, etc. attached).
|
|
6
|
+
const mod = require('./lib/esm/index.js');
|
|
7
|
+
module.exports = mod.default || mod;
|
|
@@ -1,6 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
async function arrayBuffer(stream) {
|
|
2
|
+
const chunks = [];
|
|
3
|
+
for await (const chunk of stream) {
|
|
4
|
+
chunks.push(chunk instanceof Uint8Array ? chunk : new TextEncoder().encode(String(chunk)));
|
|
5
|
+
}
|
|
6
|
+
const totalLength = chunks.reduce((acc, c) => acc + c.length, 0);
|
|
7
|
+
const result = new Uint8Array(totalLength);
|
|
8
|
+
let offset = 0;
|
|
9
|
+
for (const chunk of chunks) {
|
|
10
|
+
result.set(chunk, offset);
|
|
11
|
+
offset += chunk.length;
|
|
12
|
+
}
|
|
13
|
+
return result.buffer;
|
|
14
|
+
}
|
|
15
|
+
async function blob(stream) {
|
|
16
|
+
const buf = await arrayBuffer(stream);
|
|
17
|
+
return new Blob([buf]);
|
|
18
|
+
}
|
|
19
|
+
async function buffer(stream) {
|
|
20
|
+
const buf = await arrayBuffer(stream);
|
|
21
|
+
return new Uint8Array(buf);
|
|
22
|
+
}
|
|
23
|
+
async function text(stream) {
|
|
24
|
+
const buf = await arrayBuffer(stream);
|
|
25
|
+
return new TextDecoder().decode(buf);
|
|
26
|
+
}
|
|
27
|
+
async function json(stream) {
|
|
28
|
+
const str = await text(stream);
|
|
29
|
+
return JSON.parse(str);
|
|
30
|
+
}
|
|
31
|
+
var consumers_default = { arrayBuffer, blob, buffer, text, json };
|
|
4
32
|
export {
|
|
5
|
-
|
|
33
|
+
arrayBuffer,
|
|
34
|
+
blob,
|
|
35
|
+
buffer,
|
|
36
|
+
consumers_default as default,
|
|
37
|
+
json,
|
|
38
|
+
text
|
|
6
39
|
};
|