@gjsify/stream 0.3.16 → 0.3.18

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