@gjsify/stream 0.3.13 → 0.3.15

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.
@@ -1,4 +1,3 @@
1
1
  import { makeCallable } from "@gjsify/utils";
2
- export {
3
- makeCallable
4
- };
2
+
3
+ export { makeCallable };
@@ -1,39 +1,41 @@
1
+ //#region src/consumers/index.ts
1
2
  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;
3
+ const chunks = [];
4
+ for await (const chunk of stream) {
5
+ chunks.push(chunk instanceof Uint8Array ? chunk : new TextEncoder().encode(String(chunk)));
6
+ }
7
+ const totalLength = chunks.reduce((acc, c) => acc + c.length, 0);
8
+ const result = new Uint8Array(totalLength);
9
+ let offset = 0;
10
+ for (const chunk of chunks) {
11
+ result.set(chunk, offset);
12
+ offset += chunk.length;
13
+ }
14
+ return result.buffer;
14
15
  }
15
16
  async function blob(stream) {
16
- const buf = await arrayBuffer(stream);
17
- return new Blob([buf]);
17
+ const buf = await arrayBuffer(stream);
18
+ return new Blob([buf]);
18
19
  }
19
20
  async function buffer(stream) {
20
- const buf = await arrayBuffer(stream);
21
- return new Uint8Array(buf);
21
+ const buf = await arrayBuffer(stream);
22
+ return new Uint8Array(buf);
22
23
  }
23
24
  async function text(stream) {
24
- const buf = await arrayBuffer(stream);
25
- return new TextDecoder().decode(buf);
25
+ const buf = await arrayBuffer(stream);
26
+ return new TextDecoder().decode(buf);
26
27
  }
27
28
  async function json(stream) {
28
- const str = await text(stream);
29
- return JSON.parse(str);
29
+ const str = await text(stream);
30
+ return JSON.parse(str);
30
31
  }
31
- var consumers_default = { arrayBuffer, blob, buffer, text, json };
32
- export {
33
- arrayBuffer,
34
- blob,
35
- buffer,
36
- consumers_default as default,
37
- json,
38
- text
32
+ var consumers_default = {
33
+ arrayBuffer,
34
+ blob,
35
+ buffer,
36
+ text,
37
+ json
39
38
  };
39
+
40
+ //#endregion
41
+ export { arrayBuffer, blob, buffer, consumers_default as default, json, text };