@adviser/cement 0.2.28 → 0.2.29
Sign up to get free protection for your applications and to get access to all the features.
- package/{base-sys-abstraction-C9WW3w57.d.cts → base-sys-abstraction-BkEiLHl0.d.ts} +8 -4
- package/{base-sys-abstraction-C9WW3w57.d.ts → base-sys-abstraction-Qj7pkY1N.d.cts} +8 -4
- package/{chunk-OXD3YZZ7.js → chunk-7KFVMTOS.js} +3 -47
- package/chunk-7KFVMTOS.js.map +1 -0
- package/{chunk-P5RXA4C4.js → chunk-GES3MUGV.js} +24 -27
- package/{chunk-LCPYQVWT.js.map → chunk-GES3MUGV.js.map} +1 -1
- package/{chunk-YDIUMYIE.js → chunk-Q65HLCNL.js} +8 -7
- package/chunk-Q65HLCNL.js.map +1 -0
- package/{chunk-DPIL5UIL.js → chunk-WMMUXBDX.js} +6 -2
- package/chunk-WMMUXBDX.js.map +1 -0
- package/{index-Dhb2fQiw.d.cts → index-Q3phXzYr.d.cts} +2 -21
- package/{index-CcsGcehs.d.ts → index-tIGZMHTc.d.ts} +2 -21
- package/index.cjs +264 -7343
- package/index.cjs.map +1 -1
- package/index.d.cts +72 -12
- package/index.d.ts +72 -12
- package/index.js +217 -7265
- package/index.js.map +1 -1
- package/node/index.cjs +220 -39
- package/node/index.cjs.map +1 -1
- package/node/index.d.cts +22 -4
- package/node/index.d.ts +22 -4
- package/node/index.js +201 -25
- package/node/index.js.map +1 -1
- package/package.json +23 -12
- package/src/LICENSE +201 -0
- package/src/README.md +39 -0
- package/src/base-sys-abstraction.test.ts +95 -0
- package/src/base-sys-abstraction.ts +242 -0
- package/src/bin2text.test.ts +59 -0
- package/src/bin2text.ts +47 -0
- package/src/crypto.test.ts +15 -0
- package/src/crypto.ts +125 -0
- package/src/file-service.ts +24 -0
- package/src/future.test.ts +32 -0
- package/src/future.ts +27 -0
- package/src/index.ts +22 -0
- package/src/jsr.json +20 -0
- package/src/log-level-impl.ts +87 -0
- package/src/log-writer-impl.ts +58 -0
- package/src/logger-impl.ts +498 -0
- package/src/logger.test.ts +1132 -0
- package/src/logger.ts +208 -0
- package/src/node/deno-file-service.ts +92 -0
- package/src/node/deno-sys-abstraction.ts +133 -0
- package/src/node/index.ts +4 -0
- package/src/node/mock-file-service.ts +45 -0
- package/src/node/node-file-service.ts +91 -0
- package/src/node/node-sys-abstraction.ts +121 -0
- package/src/option.ts +60 -0
- package/src/resolve-once.test.ts +321 -0
- package/src/resolve-once.ts +179 -0
- package/src/result.test.ts +102 -0
- package/src/result.ts +165 -0
- package/src/runtime.ts +36 -0
- package/src/sys-abstraction.ts +53 -0
- package/src/sys-env.test.ts +53 -0
- package/src/sys-env.ts +216 -0
- package/src/test/log-write-stream.ts +95 -0
- package/src/test/mock-logger.ts +40 -0
- package/src/time.ts +20 -0
- package/src/tracer.test.ts +314 -0
- package/src/tracer.ts +222 -0
- package/src/txt-en-decoder.ts +21 -0
- package/src/uri.test.ts +155 -0
- package/src/uri.ts +421 -0
- package/src/utils/console-write-stream.ts +72 -0
- package/src/utils/fanout-write-stream.ts +32 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/rebuffer.ts +75 -0
- package/src/utils/stream-map.ts +67 -0
- package/src/utils/stream2string.ts +47 -0
- package/src/utils/string2stream.ts +14 -0
- package/src/version.ts +3 -0
- package/src/web/index.ts +1 -0
- package/src/web/web-sys-abstraction.ts +80 -0
- package/ts/base-sys-abstraction.d.ts +84 -0
- package/ts/base-sys-abstraction.d.ts.map +1 -0
- package/ts/base-sys-abstraction.js +178 -0
- package/ts/base-sys-abstraction.js.map +1 -0
- package/ts/base-sys-abstraction.test.d.ts +2 -0
- package/ts/base-sys-abstraction.test.d.ts.map +1 -0
- package/ts/base-sys-abstraction.test.js +82 -0
- package/ts/base-sys-abstraction.test.js.map +1 -0
- package/ts/bin2text.d.ts +3 -0
- package/ts/bin2text.d.ts.map +1 -0
- package/ts/bin2text.js +43 -0
- package/ts/bin2text.js.map +1 -0
- package/ts/bin2text.test.d.ts +2 -0
- package/ts/bin2text.test.d.ts.map +1 -0
- package/ts/bin2text.test.js +51 -0
- package/ts/bin2text.test.js.map +1 -0
- package/ts/crypto.d.ts +76 -0
- package/ts/crypto.d.ts.map +1 -0
- package/ts/crypto.js +22 -0
- package/ts/crypto.js.map +1 -0
- package/ts/crypto.test.d.ts +2 -0
- package/ts/crypto.test.d.ts.map +1 -0
- package/ts/crypto.test.js +14 -0
- package/ts/crypto.test.js.map +1 -0
- package/ts/file-service.d.ts +17 -0
- package/ts/file-service.d.ts.map +1 -0
- package/ts/file-service.js +2 -0
- package/ts/file-service.js.map +1 -0
- package/ts/future.d.ts +8 -0
- package/ts/future.d.ts.map +1 -0
- package/ts/future.js +38 -0
- package/ts/future.js.map +1 -0
- package/ts/future.test.d.ts +2 -0
- package/ts/future.test.d.ts.map +1 -0
- package/ts/future.test.js +28 -0
- package/ts/future.test.js.map +1 -0
- package/ts/index.d.ts +23 -0
- package/ts/index.d.ts.map +1 -0
- package/ts/index.js +23 -0
- package/ts/index.js.map +1 -0
- package/ts/log-level-impl.d.ts +14 -0
- package/ts/log-level-impl.d.ts.map +1 -0
- package/ts/log-level-impl.js +72 -0
- package/ts/log-level-impl.js.map +1 -0
- package/ts/log-writer-impl.d.ts +10 -0
- package/ts/log-writer-impl.d.ts.map +1 -0
- package/ts/log-writer-impl.js +45 -0
- package/ts/log-writer-impl.js.map +1 -0
- package/ts/logger-impl.d.ts +71 -0
- package/ts/logger-impl.d.ts.map +1 -0
- package/ts/logger-impl.js +412 -0
- package/ts/logger-impl.js.map +1 -0
- package/ts/logger.d.ts +84 -0
- package/ts/logger.d.ts.map +1 -0
- package/ts/logger.js +114 -0
- package/ts/logger.js.map +1 -0
- package/ts/logger.test.d.ts +2 -0
- package/ts/logger.test.d.ts.map +1 -0
- package/ts/logger.test.js +1023 -0
- package/ts/logger.test.js.map +1 -0
- package/ts/node/deno-file-service.d.ts +17 -0
- package/ts/node/deno-file-service.d.ts.map +1 -0
- package/ts/node/deno-file-service.js +65 -0
- package/ts/node/deno-file-service.js.map +1 -0
- package/ts/node/deno-sys-abstraction.d.ts +22 -0
- package/ts/node/deno-sys-abstraction.d.ts.map +1 -0
- package/ts/node/deno-sys-abstraction.js +101 -0
- package/ts/node/deno-sys-abstraction.js.map +1 -0
- package/ts/node/index.d.ts +5 -0
- package/ts/node/index.d.ts.map +1 -0
- package/ts/node/index.js +5 -0
- package/ts/node/index.js.map +1 -0
- package/ts/node/mock-file-service.d.ts +11 -0
- package/ts/node/mock-file-service.d.ts.map +1 -0
- package/ts/node/mock-file-service.js +34 -0
- package/ts/node/mock-file-service.js.map +1 -0
- package/ts/node/mock-file-service.test.d.ts +2 -0
- package/ts/node/mock-file-service.test.d.ts.map +1 -0
- package/ts/node/mock-file-service.test.js +31 -0
- package/ts/node/mock-file-service.test.js.map +1 -0
- package/ts/node/node-file-service.d.ts +16 -0
- package/ts/node/node-file-service.d.ts.map +1 -0
- package/ts/node/node-file-service.js +71 -0
- package/ts/node/node-file-service.js.map +1 -0
- package/ts/node/node-sys-abstraction.d.ts +22 -0
- package/ts/node/node-sys-abstraction.d.ts.map +1 -0
- package/ts/node/node-sys-abstraction.js +99 -0
- package/ts/node/node-sys-abstraction.js.map +1 -0
- package/ts/node/node-sys-abstraction.test.d.ts +2 -0
- package/ts/node/node-sys-abstraction.test.d.ts.map +1 -0
- package/ts/node/node-sys-abstraction.test.js +87 -0
- package/ts/node/node-sys-abstraction.test.js.map +1 -0
- package/ts/option.d.ts +25 -0
- package/ts/option.d.ts.map +1 -0
- package/ts/option.js +47 -0
- package/ts/option.js.map +1 -0
- package/ts/resolve-once.d.ts +46 -0
- package/ts/resolve-once.d.ts.map +1 -0
- package/ts/resolve-once.js +152 -0
- package/ts/resolve-once.js.map +1 -0
- package/ts/resolve-once.test.d.ts +2 -0
- package/ts/resolve-once.test.d.ts.map +1 -0
- package/ts/resolve-once.test.js +283 -0
- package/ts/resolve-once.test.js.map +1 -0
- package/ts/result.d.ts +34 -0
- package/ts/result.d.ts.map +1 -0
- package/ts/result.js +85 -0
- package/ts/result.js.map +1 -0
- package/ts/result.test.d.ts +2 -0
- package/ts/result.test.d.ts.map +1 -0
- package/ts/result.test.js +79 -0
- package/ts/result.test.js.map +1 -0
- package/ts/runtime.d.ts +8 -0
- package/ts/runtime.d.ts.map +1 -0
- package/ts/runtime.js +26 -0
- package/ts/runtime.js.map +1 -0
- package/ts/sys-abstraction.d.ts +36 -0
- package/ts/sys-abstraction.d.ts.map +1 -0
- package/ts/sys-abstraction.js +31 -0
- package/ts/sys-abstraction.js.map +1 -0
- package/ts/sys-env.d.ts +48 -0
- package/ts/sys-env.d.ts.map +1 -0
- package/ts/sys-env.js +176 -0
- package/ts/sys-env.js.map +1 -0
- package/ts/sys-env.test.d.ts +2 -0
- package/ts/sys-env.test.d.ts.map +1 -0
- package/ts/sys-env.test.js +51 -0
- package/ts/sys-env.test.js.map +1 -0
- package/ts/test/log-write-stream.d.ts +27 -0
- package/ts/test/log-write-stream.d.ts.map +1 -0
- package/ts/test/log-write-stream.js +74 -0
- package/ts/test/log-write-stream.js.map +1 -0
- package/ts/test/mock-logger.d.ts +14 -0
- package/ts/test/mock-logger.d.ts.map +1 -0
- package/ts/test/mock-logger.js +29 -0
- package/ts/test/mock-logger.js.map +1 -0
- package/ts/test/mock-logger.test.d.ts +2 -0
- package/ts/test/mock-logger.test.d.ts.map +1 -0
- package/ts/test/mock-logger.test.js +63 -0
- package/ts/test/mock-logger.test.js.map +1 -0
- package/ts/test/test-exit-handler.d.ts +2 -0
- package/ts/test/test-exit-handler.d.ts.map +1 -0
- package/ts/test/test-exit-handler.js +57 -0
- package/ts/test/test-exit-handler.js.map +1 -0
- package/ts/time.d.ts +13 -0
- package/ts/time.d.ts.map +1 -0
- package/ts/time.js +14 -0
- package/ts/time.js.map +1 -0
- package/ts/tracer.d.ts +59 -0
- package/ts/tracer.d.ts.map +1 -0
- package/ts/tracer.js +148 -0
- package/ts/tracer.js.map +1 -0
- package/ts/tracer.test.d.ts +2 -0
- package/ts/tracer.test.d.ts.map +1 -0
- package/ts/tracer.test.js +311 -0
- package/ts/tracer.test.js.map +1 -0
- package/ts/txt-en-decoder.d.ts +10 -0
- package/ts/txt-en-decoder.d.ts.map +1 -0
- package/ts/txt-en-decoder.js +15 -0
- package/ts/txt-en-decoder.js.map +1 -0
- package/ts/uri.d.ts +67 -0
- package/ts/uri.d.ts.map +1 -0
- package/ts/uri.js +283 -0
- package/ts/uri.js.map +1 -0
- package/ts/uri.test.d.ts +2 -0
- package/ts/uri.test.d.ts.map +1 -0
- package/ts/uri.test.js +119 -0
- package/ts/uri.test.js.map +1 -0
- package/ts/utils/console-write-stream.d.ts +21 -0
- package/ts/utils/console-write-stream.d.ts.map +1 -0
- package/ts/utils/console-write-stream.js +62 -0
- package/ts/utils/console-write-stream.js.map +1 -0
- package/ts/utils/fanout-write-stream.d.ts +12 -0
- package/ts/utils/fanout-write-stream.d.ts.map +1 -0
- package/ts/utils/fanout-write-stream.js +24 -0
- package/ts/utils/fanout-write-stream.js.map +1 -0
- package/ts/utils/index.d.ts +7 -0
- package/ts/utils/index.d.ts.map +1 -0
- package/ts/utils/index.js +7 -0
- package/ts/utils/index.js.map +1 -0
- package/ts/utils/rebuffer.d.ts +3 -0
- package/ts/utils/rebuffer.d.ts.map +1 -0
- package/ts/utils/rebuffer.js +60 -0
- package/ts/utils/rebuffer.js.map +1 -0
- package/ts/utils/rebuffer.test.d.ts +2 -0
- package/ts/utils/rebuffer.test.d.ts.map +1 -0
- package/ts/utils/rebuffer.test.js +77 -0
- package/ts/utils/rebuffer.test.js.map +1 -0
- package/ts/utils/stream-map.d.ts +9 -0
- package/ts/utils/stream-map.d.ts.map +1 -0
- package/ts/utils/stream-map.js +62 -0
- package/ts/utils/stream-map.js.map +1 -0
- package/ts/utils/stream-map.test.d.ts +2 -0
- package/ts/utils/stream-map.test.d.ts.map +1 -0
- package/ts/utils/stream-map.test.js +87 -0
- package/ts/utils/stream-map.test.js.map +1 -0
- package/ts/utils/stream-test-helper.d.ts +17 -0
- package/ts/utils/stream-test-helper.d.ts.map +1 -0
- package/ts/utils/stream-test-helper.js +37 -0
- package/ts/utils/stream-test-helper.js.map +1 -0
- package/ts/utils/stream2string.d.ts +3 -0
- package/ts/utils/stream2string.d.ts.map +1 -0
- package/ts/utils/stream2string.js +48 -0
- package/ts/utils/stream2string.js.map +1 -0
- package/ts/utils/stream2string.test.d.ts +2 -0
- package/ts/utils/stream2string.test.d.ts.map +1 -0
- package/ts/utils/stream2string.test.js +29 -0
- package/ts/utils/stream2string.test.js.map +1 -0
- package/ts/utils/string2stream.d.ts +4 -0
- package/ts/utils/string2stream.d.ts.map +1 -0
- package/ts/utils/string2stream.js +13 -0
- package/ts/utils/string2stream.js.map +1 -0
- package/ts/utils/string2stream.test.d.ts +2 -0
- package/ts/utils/string2stream.test.d.ts.map +1 -0
- package/ts/utils/string2stream.test.js +6 -0
- package/ts/utils/string2stream.test.js.map +1 -0
- package/ts/version.d.ts +2 -0
- package/ts/version.d.ts.map +1 -0
- package/ts/version.js +4 -0
- package/ts/version.js.map +1 -0
- package/ts/web/index.d.ts +2 -0
- package/ts/web/index.d.ts.map +1 -0
- package/ts/web/index.js +2 -0
- package/ts/web/index.js.map +1 -0
- package/ts/web/web-sys-abstraction.d.ts +4 -0
- package/ts/web/web-sys-abstraction.d.ts.map +1 -0
- package/ts/web/web-sys-abstraction.js +64 -0
- package/ts/web/web-sys-abstraction.js.map +1 -0
- package/utils/index.cjs +0 -42
- package/utils/index.cjs.map +1 -1
- package/utils/index.d.cts +1 -2
- package/utils/index.d.ts +1 -2
- package/utils/index.js +2 -7
- package/web/index.cjs +25 -7
- package/web/index.cjs.map +1 -1
- package/web/index.d.cts +2 -1
- package/web/index.d.ts +2 -1
- package/web/index.js +3 -3
- package/chunk-DPIL5UIL.js.map +0 -1
- package/chunk-LCPYQVWT.js +0 -21
- package/chunk-OXD3YZZ7.js.map +0 -1
- package/chunk-P5RXA4C4.js.map +0 -1
- package/chunk-YDIUMYIE.js.map +0 -1
@@ -0,0 +1,7 @@
|
|
1
|
+
export * from "./rebuffer.js";
|
2
|
+
export * from "./stream-map.js";
|
3
|
+
export * from "./stream2string.js";
|
4
|
+
export * from "./string2stream.js";
|
5
|
+
export * from "./console-write-stream.js";
|
6
|
+
export * from "./fanout-write-stream.js";
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"rebuffer.d.ts","sourceRoot":"","sources":["../../../src/utils/rebuffer.ts"],"names":[],"mappings":"AAOA,wBAAsB,aAAa,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAE7F;AAmDD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,cAAc,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,cAAc,CAAC,UAAU,CAAC,CAcrG"}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import { array2stream, stream2array } from "./stream-map.js";
|
2
|
+
export async function rebufferArray(a, chunkSize) {
|
3
|
+
return stream2array(rebuffer(array2stream(a), chunkSize));
|
4
|
+
}
|
5
|
+
function reChunk(cs, chunkSize) {
|
6
|
+
const len = cs.reduce((acc, v) => acc + v.length, 0);
|
7
|
+
const last = cs[cs.length - 1];
|
8
|
+
const lastOfs = len - last.length;
|
9
|
+
const rest = last.subarray(chunkSize - lastOfs);
|
10
|
+
cs[cs.length - 1] = last.subarray(0, chunkSize - lastOfs);
|
11
|
+
const chunk = new Uint8Array(chunkSize);
|
12
|
+
let ofs = 0;
|
13
|
+
for (const c of cs) {
|
14
|
+
chunk.set(c, ofs);
|
15
|
+
ofs += c.length;
|
16
|
+
}
|
17
|
+
return { rest, chunk };
|
18
|
+
}
|
19
|
+
function pump(ps, controller, next) {
|
20
|
+
ps.reader.read().then(({ done, value }) => {
|
21
|
+
if (done) {
|
22
|
+
if (ps.tmpLen > 0) {
|
23
|
+
controller.enqueue(reChunk(ps.tmp, ps.tmpLen).chunk);
|
24
|
+
}
|
25
|
+
controller.close();
|
26
|
+
next();
|
27
|
+
return;
|
28
|
+
}
|
29
|
+
if (ps.tmpLen + value.length > ps.chunkSize) {
|
30
|
+
ps.tmp.push(value);
|
31
|
+
const res = reChunk(ps.tmp, ps.chunkSize);
|
32
|
+
controller.enqueue(res.chunk);
|
33
|
+
ps.tmp = [res.rest];
|
34
|
+
ps.tmpLen = res.rest.length;
|
35
|
+
next();
|
36
|
+
return;
|
37
|
+
}
|
38
|
+
else if (value.length) {
|
39
|
+
ps.tmp.push(value);
|
40
|
+
ps.tmpLen += value.length;
|
41
|
+
}
|
42
|
+
pump(ps, controller, next);
|
43
|
+
});
|
44
|
+
}
|
45
|
+
export function rebuffer(a, chunkSize) {
|
46
|
+
const state = {
|
47
|
+
reader: a.getReader(),
|
48
|
+
tmp: [],
|
49
|
+
tmpLen: 0,
|
50
|
+
chunkSize,
|
51
|
+
};
|
52
|
+
return new ReadableStream({
|
53
|
+
async pull(controller) {
|
54
|
+
return new Promise((resolve) => {
|
55
|
+
pump(state, controller, resolve);
|
56
|
+
});
|
57
|
+
},
|
58
|
+
});
|
59
|
+
}
|
60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AAiB;IACvE,MAAM,KAAK,GAAc;QACvB,MAAM,EAAE,CAAC,CAAC,SAAS,EAAE;QACrB,GAAG,EAAE,EAAE;QACP,MAAM,EAAE,CAAC;QACT,SAAS;KACV,CAAC;IACF,OAAO,IAAI,cAAc,CAAa;QACpC,KAAK,CAAC,IAAI,CAAC,UAAU;YACnB,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;gBACnC,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;YACnC,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"rebuffer.test.d.ts","sourceRoot":"","sources":["../../../src/utils/rebuffer.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,77 @@
|
|
1
|
+
import { utils } from "@adviser/cement";
|
2
|
+
import { receiveFromStream, sendToStream } from "./stream-test-helper.js";
|
3
|
+
it("rechunk empty", async () => {
|
4
|
+
const chunks = await utils.rebufferArray([], 10);
|
5
|
+
expect(chunks.length).toEqual(0);
|
6
|
+
});
|
7
|
+
it("rechunk 0 size", async () => {
|
8
|
+
const chunks = await utils.rebufferArray([new Uint8Array(0)], 10);
|
9
|
+
expect(chunks.length).toEqual(0);
|
10
|
+
});
|
11
|
+
it("rechunk smaller 10", async () => {
|
12
|
+
const chunks = await utils.rebufferArray([new Uint8Array(3)], 10);
|
13
|
+
expect(chunks.length).toEqual(1);
|
14
|
+
expect(chunks[0].length).toEqual(3);
|
15
|
+
});
|
16
|
+
it("rechunk smaller 10 pack smaller chunks", async () => {
|
17
|
+
const chunks = await utils.rebufferArray(Array(7)
|
18
|
+
.fill(0)
|
19
|
+
.map((_, i) => {
|
20
|
+
const o = new Uint8Array(3);
|
21
|
+
for (let j = 0; j < o.length; j++) {
|
22
|
+
o[j] = i * o.length + j;
|
23
|
+
}
|
24
|
+
return o;
|
25
|
+
}), 10);
|
26
|
+
expect(chunks.length).toEqual(3);
|
27
|
+
expect(chunks[0].length).toEqual(10);
|
28
|
+
expect(Array.from(chunks[0]).map((i) => i)).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
29
|
+
expect(chunks[1].length).toEqual(10);
|
30
|
+
expect(Array.from(chunks[1]).map((i) => i)).toEqual([10, 11, 12, 13, 14, 15, 16, 17, 18, 19]);
|
31
|
+
expect(chunks[2].length).toEqual(1);
|
32
|
+
expect(Array.from(chunks[2]).map((i) => i)).toEqual([20]);
|
33
|
+
});
|
34
|
+
it("rechunk smaller 10 pack bigger chunks", async () => {
|
35
|
+
const chunks = await utils.rebufferArray(Array(3)
|
36
|
+
.fill(0)
|
37
|
+
.map((_, i) => {
|
38
|
+
const o = new Uint8Array(11);
|
39
|
+
for (let j = 0; j < o.length; j++) {
|
40
|
+
o[j] = i * o.length + j;
|
41
|
+
}
|
42
|
+
return o;
|
43
|
+
}), 10);
|
44
|
+
expect(chunks.length).toEqual(4);
|
45
|
+
expect(chunks[0].length).toEqual(10);
|
46
|
+
expect(Array.from(chunks[0]).map((i) => i)).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
47
|
+
expect(chunks[1].length).toEqual(10);
|
48
|
+
expect(Array.from(chunks[1]).map((i) => i)).toEqual([10, 11, 12, 13, 14, 15, 16, 17, 18, 19]);
|
49
|
+
expect(chunks[2].length).toEqual(10);
|
50
|
+
expect(Array.from(chunks[2]).map((i) => i)).toEqual([20, 21, 22, 23, 24, 25, 26, 27, 28, 29]);
|
51
|
+
expect(chunks[3].length).toEqual(3);
|
52
|
+
expect(Array.from(chunks[3]).map((i) => i)).toEqual([30, 31, 32]);
|
53
|
+
});
|
54
|
+
describe("test streaming through rebuffer", () => {
|
55
|
+
const state = {
|
56
|
+
sendChunks: 10000,
|
57
|
+
sendChunkSize: 3,
|
58
|
+
fillCalls: 0,
|
59
|
+
CollectorFn: vitest.fn(),
|
60
|
+
};
|
61
|
+
const reBufferSize = 11;
|
62
|
+
it("does rebuffer respect backpressure", async () => {
|
63
|
+
const ts = new TransformStream(undefined, undefined, { highWaterMark: 2 });
|
64
|
+
const reb = utils.rebuffer(ts.readable, reBufferSize);
|
65
|
+
await Promise.all([receiveFromStream(reb, state), sendToStream(ts.writable, state)]);
|
66
|
+
expect(state.CollectorFn).toBeCalledTimes(~~((state.sendChunkSize * state.sendChunks) / reBufferSize) + 1 + 1);
|
67
|
+
expect(state.CollectorFn.mock.calls.slice(-1)[0][0].done).toBeTruthy();
|
68
|
+
let lastfillCalls = 0;
|
69
|
+
for (let i = 0; i < state.CollectorFn.mock.calls.length - 1; i++) {
|
70
|
+
const { fillCalls, reBufferCalls, value } = state.CollectorFn.mock.calls[i][0];
|
71
|
+
expect(value === null || value === void 0 ? void 0 : value[0]).toBe(~~((reBufferSize * i) / state.sendChunkSize) % 256);
|
72
|
+
expect(fillCalls * state.sendChunkSize).toBeGreaterThanOrEqual((fillCalls - lastfillCalls) * state.sendChunkSize + reBufferCalls * reBufferSize);
|
73
|
+
lastfillCalls = fillCalls;
|
74
|
+
}
|
75
|
+
});
|
76
|
+
});
|
77
|
+
//# sourceMappingURL=rebuffer.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"rebuffer.test.js","sourceRoot":"","sources":["../../../src/utils/rebuffer.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAsB,MAAM,yBAAyB,CAAC;AAE9F,EAAE,CAAC,eAAe,EAAE,KAAK,IAAI,EAAE;IAC7B,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACjD,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACnC,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,gBAAgB,EAAE,KAAK,IAA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ACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
export interface StreamMap<T, U> {
|
2
|
+
Map(s: T, idx: number): U | Promise<U>;
|
3
|
+
readonly Close?: () => void;
|
4
|
+
}
|
5
|
+
export declare function streamMap<T, U>(s: ReadableStream<T>, sm: StreamMap<T, U>): ReadableStream<U>;
|
6
|
+
export declare function devnull<T>(a: ReadableStream<T>): Promise<number>;
|
7
|
+
export declare function array2stream<T>(a: T[]): ReadableStream<T>;
|
8
|
+
export declare function stream2array<T>(a: ReadableStream<T>): Promise<T[]>;
|
9
|
+
//# sourceMappingURL=stream-map.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"stream-map.d.ts","sourceRoot":"","sources":["../../../src/utils/stream-map.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS,CAAC,CAAC,EAAE,CAAC;IAC7B,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACvC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B;AACD,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAsB5F;AAED,wBAAsB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAWtE;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC,CAYzD;AAED,wBAAsB,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAWxE"}
|
@@ -0,0 +1,62 @@
|
|
1
|
+
export function streamMap(s, sm) {
|
2
|
+
const state = { reader: s.getReader(), streamMap: sm, idx: 0 };
|
3
|
+
return new ReadableStream({
|
4
|
+
async pull(controller) {
|
5
|
+
const { done, value } = await state.reader.read();
|
6
|
+
if (done) {
|
7
|
+
if (state.streamMap.Close) {
|
8
|
+
state.streamMap.Close();
|
9
|
+
}
|
10
|
+
controller.close();
|
11
|
+
return;
|
12
|
+
}
|
13
|
+
const promiseOrU = state.streamMap.Map(value, state.idx++);
|
14
|
+
let mapped;
|
15
|
+
if (promiseOrU instanceof Promise || typeof promiseOrU.then === "function") {
|
16
|
+
mapped = await promiseOrU;
|
17
|
+
}
|
18
|
+
else {
|
19
|
+
mapped = promiseOrU;
|
20
|
+
}
|
21
|
+
controller.enqueue(mapped);
|
22
|
+
},
|
23
|
+
});
|
24
|
+
}
|
25
|
+
export async function devnull(a) {
|
26
|
+
const reader = a.getReader();
|
27
|
+
let cnt = 0;
|
28
|
+
while (true) {
|
29
|
+
const { done } = await reader.read();
|
30
|
+
if (done) {
|
31
|
+
break;
|
32
|
+
}
|
33
|
+
cnt++;
|
34
|
+
}
|
35
|
+
return cnt;
|
36
|
+
}
|
37
|
+
export function array2stream(a) {
|
38
|
+
let i = 0;
|
39
|
+
return new ReadableStream({
|
40
|
+
pull(controller) {
|
41
|
+
if (i >= a.length) {
|
42
|
+
controller.close();
|
43
|
+
return;
|
44
|
+
}
|
45
|
+
controller.enqueue(a[i]);
|
46
|
+
i++;
|
47
|
+
},
|
48
|
+
});
|
49
|
+
}
|
50
|
+
export async function stream2array(a) {
|
51
|
+
const ret = [];
|
52
|
+
const reader = a.getReader();
|
53
|
+
while (true) {
|
54
|
+
const { done, value } = await reader.read();
|
55
|
+
if (done) {
|
56
|
+
break;
|
57
|
+
}
|
58
|
+
ret.push(value);
|
59
|
+
}
|
60
|
+
return ret;
|
61
|
+
}
|
62
|
+
//# sourceMappingURL=stream-map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,CAAC;QACZ,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QACrC,IAAI,IAAI,EAAE,CAAC;YACT,MAAM;QACR,CAAC;QACD,GAAG,EAAE,CAAC;IACR,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,YAAY,CAAI,CAAM;IACpC,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,IAAI,cAAc,CAAI;QAC3B,IAAI,CAAC,UAAU;YACb,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBAClB,UAAU,CAAC,KAAK,EAAE,CAAC;gBACnB,OAAO;YACT,CAAC;YACD,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACzB,CAAC,EAAE,CAAC;QACN,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAAI,CAAoB;IACxD,MAAM,GAAG,GAAQ,EAAE,CAAC;IACpB,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC;IAC7B,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAC5C,IAAI,IAAI,EAAE,CAAC;YACT,MAAM;QACR,CAAC;QACD,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"stream-map.test.d.ts","sourceRoot":"","sources":["../../../src/utils/stream-map.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,87 @@
|
|
1
|
+
import { utils } from "@adviser/cement";
|
2
|
+
import { receiveFromStream, sendToStream } from "./stream-test-helper.js";
|
3
|
+
it("array2stream", async () => {
|
4
|
+
const as = utils.array2stream([1, 2, 3]);
|
5
|
+
let i = 0;
|
6
|
+
const reader = as.getReader();
|
7
|
+
while (true) {
|
8
|
+
const { done, value } = await reader.read();
|
9
|
+
if (done) {
|
10
|
+
break;
|
11
|
+
}
|
12
|
+
expect(1 + i++).toBe(value);
|
13
|
+
}
|
14
|
+
});
|
15
|
+
it("stream2array", async () => {
|
16
|
+
const as = await utils.stream2array(new ReadableStream({
|
17
|
+
start(controller) {
|
18
|
+
controller.enqueue(1);
|
19
|
+
controller.enqueue(2);
|
20
|
+
controller.enqueue(3);
|
21
|
+
controller.close();
|
22
|
+
},
|
23
|
+
}));
|
24
|
+
expect(as).toEqual([1, 2, 3]);
|
25
|
+
});
|
26
|
+
it("devnull", async () => {
|
27
|
+
const cnt = await utils.devnull(utils.streamMap(utils.array2stream([1, 2, 3]), {
|
28
|
+
Map: (i, idx) => (idx + 1) * 10 + i + 1,
|
29
|
+
}));
|
30
|
+
expect(cnt).toBe(3);
|
31
|
+
});
|
32
|
+
it("stream_map", async () => {
|
33
|
+
const closeFn = vitest.fn();
|
34
|
+
const s = await utils.stream2array(utils.streamMap(utils.array2stream([1, 2, 3]), {
|
35
|
+
Map: (i, idx) => (idx + 1) * 10 + i + 1,
|
36
|
+
Close: closeFn,
|
37
|
+
}));
|
38
|
+
expect(closeFn).toBeCalledTimes(1);
|
39
|
+
expect(s).toEqual([12, 23, 34]);
|
40
|
+
});
|
41
|
+
it("stream_map async", async () => {
|
42
|
+
const closeFn = vitest.fn();
|
43
|
+
const s = await utils.stream2array(utils.streamMap(utils.array2stream([1, 2, 3]), {
|
44
|
+
Map: (i, idx) => Promise.resolve((idx + 1) * 10 + i + 1),
|
45
|
+
Close: closeFn,
|
46
|
+
}));
|
47
|
+
expect(closeFn).toBeCalledTimes(1);
|
48
|
+
expect(s).toEqual([12, 23, 34]);
|
49
|
+
});
|
50
|
+
it("map types", async () => {
|
51
|
+
const oo = await utils.stream2array(utils.streamMap(utils.array2stream([1, 2, 3]), {
|
52
|
+
Map: (chunk, idx) => {
|
53
|
+
return "[" + chunk + "/" + idx + "]";
|
54
|
+
},
|
55
|
+
}));
|
56
|
+
expect(oo).toEqual(["[1/0]", "[2/1]", "[3/2]"]);
|
57
|
+
});
|
58
|
+
describe("test streaming through streamMap", () => {
|
59
|
+
const state = {
|
60
|
+
sendChunks: 10000,
|
61
|
+
sendChunkSize: 3,
|
62
|
+
fillCalls: 0,
|
63
|
+
CollectorFn: vitest.fn(),
|
64
|
+
};
|
65
|
+
it("does streamMap respect backpressure", async () => {
|
66
|
+
const ts = new TransformStream(undefined, undefined, { highWaterMark: 2 });
|
67
|
+
const reb = utils.streamMap(ts.readable, {
|
68
|
+
Map: (chunk) => {
|
69
|
+
for (let i = 0; i < chunk.length; i++) {
|
70
|
+
chunk[i] = (chunk[i] + 1) % 256;
|
71
|
+
}
|
72
|
+
return chunk;
|
73
|
+
},
|
74
|
+
});
|
75
|
+
await Promise.all([receiveFromStream(reb, state), sendToStream(ts.writable, state)]);
|
76
|
+
expect(state.CollectorFn).toBeCalledTimes(state.sendChunks + 1);
|
77
|
+
expect(state.CollectorFn.mock.calls.slice(-1)[0][0].done).toBeTruthy();
|
78
|
+
let lastfillCalls = 0;
|
79
|
+
for (let i = 0; i < state.CollectorFn.mock.calls.length - 1; i++) {
|
80
|
+
const { fillCalls, reBufferCalls, value } = state.CollectorFn.mock.calls[i][0];
|
81
|
+
expect(value === null || value === void 0 ? void 0 : value[0]).toBe((i + 1) % 256);
|
82
|
+
expect(fillCalls * state.sendChunkSize).toBeGreaterThanOrEqual((fillCalls - lastfillCalls) * state.sendChunkSize + reBufferCalls * state.sendChunkSize);
|
83
|
+
lastfillCalls = fillCalls;
|
84
|
+
}
|
85
|
+
});
|
86
|
+
});
|
87
|
+
//# sourceMappingURL=stream-map.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"stream-map.test.js","sourceRoot":"","sources":["../../../src/utils/stream-map.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK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CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;YACvC,MAAM,CAAC,SAAS,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC,sBAAsB,CAC5D,CAAC,SAAS,GAAG,aAAa,CAAC,GAAG,KAAK,CAAC,aAAa,GAAG,aAAa,GAAG,KAAK,CAAC,aAAa,CACxF,CAAC;YACF,aAAa,GAAG,SAAS,CAAC;QAC5B,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import type { Mock } from "vitest";
|
2
|
+
interface mockValue {
|
3
|
+
done: boolean;
|
4
|
+
value: Uint8Array | undefined;
|
5
|
+
fillCalls: number;
|
6
|
+
reBufferCalls: number;
|
7
|
+
}
|
8
|
+
export interface streamingTestState {
|
9
|
+
readonly sendChunks: number;
|
10
|
+
readonly sendChunkSize: number;
|
11
|
+
fillCalls: number;
|
12
|
+
CollectorFn: Mock<(mv: mockValue) => void>;
|
13
|
+
}
|
14
|
+
export declare function receiveFromStream(reb: ReadableStream<Uint8Array>, state: streamingTestState): Promise<void>;
|
15
|
+
export declare function sendToStream(reb: WritableStream<Uint8Array>, state: streamingTestState): Promise<void>;
|
16
|
+
export {};
|
17
|
+
//# sourceMappingURL=stream-test-helper.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"stream-test-helper.d.ts","sourceRoot":"","sources":["../../../src/utils/stream-test-helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC,UAAU,SAAS;IACjB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,UAAU,GAAG,SAAS,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB;AACD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,SAAS,KAAK,IAAI,CAAC,CAAC;CAC5C;AAED,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,cAAc,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBjH;AAED,wBAAsB,YAAY,CAAC,GAAG,EAAE,cAAc,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAiB5G"}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
export async function receiveFromStream(reb, state) {
|
2
|
+
return new Promise((resolve) => {
|
3
|
+
let reBufferCalls = 0;
|
4
|
+
const reader = reb.getReader();
|
5
|
+
function pump() {
|
6
|
+
reader.read().then(({ done, value }) => {
|
7
|
+
state.CollectorFn({ done, value, fillCalls: state.fillCalls, reBufferCalls });
|
8
|
+
reBufferCalls++;
|
9
|
+
if (done) {
|
10
|
+
resolve();
|
11
|
+
return;
|
12
|
+
}
|
13
|
+
pump();
|
14
|
+
});
|
15
|
+
}
|
16
|
+
pump();
|
17
|
+
});
|
18
|
+
}
|
19
|
+
export async function sendToStream(reb, state) {
|
20
|
+
return new Promise((resolve) => {
|
21
|
+
const writer = reb.getWriter();
|
22
|
+
function pump(i) {
|
23
|
+
if (i >= state.sendChunks) {
|
24
|
+
writer.close();
|
25
|
+
resolve();
|
26
|
+
return;
|
27
|
+
}
|
28
|
+
writer.ready.then(() => {
|
29
|
+
state.fillCalls++;
|
30
|
+
writer.write(new Uint8Array(Array(state.sendChunkSize).fill(i)));
|
31
|
+
pump(i + 1);
|
32
|
+
});
|
33
|
+
}
|
34
|
+
pump(0);
|
35
|
+
});
|
36
|
+
}
|
37
|
+
//# sourceMappingURL=stream-test-helper.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"stream-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aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACjE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACd,CAAC,CAAC,CAAC;QACL,CAAC;QACD,IAAI,CAAC,CAAC,CAAC,CAAC;IACV,CAAC,CAAC,CAAC;AACL,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"stream2string.d.ts","sourceRoot":"","sources":["../../../src/utils/stream2string.ts"],"names":[],"mappings":"AAAA,wBAAsB,aAAa,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAyBjH;AAED,wBAAsB,iBAAiB,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,CAmBvG"}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
export async function stream2string(stream, maxSize) {
|
2
|
+
if (!stream) {
|
3
|
+
return Promise.resolve("");
|
4
|
+
}
|
5
|
+
const reader = stream.getReader();
|
6
|
+
let res = "";
|
7
|
+
const decoder = new TextDecoder();
|
8
|
+
let rSize = 0;
|
9
|
+
while (typeof maxSize === "undefined" || rSize < maxSize) {
|
10
|
+
try {
|
11
|
+
const read = await reader.read();
|
12
|
+
if (read.done) {
|
13
|
+
break;
|
14
|
+
}
|
15
|
+
if (maxSize && rSize + read.value.length > maxSize) {
|
16
|
+
read.value = read.value.slice(0, maxSize - rSize);
|
17
|
+
}
|
18
|
+
const block = decoder.decode(read.value, { stream: true });
|
19
|
+
rSize += read.value.length;
|
20
|
+
res += block;
|
21
|
+
}
|
22
|
+
catch (err) {
|
23
|
+
return Promise.reject(err);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
return Promise.resolve(res);
|
27
|
+
}
|
28
|
+
export async function stream2uint8array(stream) {
|
29
|
+
if (!stream) {
|
30
|
+
return Promise.resolve(new Uint8Array());
|
31
|
+
}
|
32
|
+
const reader = stream.getReader();
|
33
|
+
let res = new Uint8Array();
|
34
|
+
while (1) {
|
35
|
+
try {
|
36
|
+
const { done, value } = await reader.read();
|
37
|
+
if (done) {
|
38
|
+
break;
|
39
|
+
}
|
40
|
+
res = new Uint8Array([...res, ...value]);
|
41
|
+
}
|
42
|
+
catch (err) {
|
43
|
+
return Promise.reject(err);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
return Promise.resolve(res);
|
47
|
+
}
|
48
|
+
//# sourceMappingURL=stream2string.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"stream2string.js","sourceRoot":"","sources":["../../../src/utils/stream2string.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAA0C,EAAE,OAAgB;IAC9F,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IAClC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,OAAO,OAAO,OAAO,KAAK,WAAW,IAAI,KAAK,GAAG,OAAO,EAAE,CAAC;QACzD,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YACjC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;gBACd,MAAM;YACR,CAAC;YACD,IAAI,OAAO,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,OAAO,EAAE,CAAC;gBACnD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC,CAAC;YACpD,CAAC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 -0,0 +1,29 @@
|
|
1
|
+
import { stream2string } from "./stream2string.js";
|
2
|
+
it("stream2string", async () => {
|
3
|
+
expect(await stream2string(new ReadableStream({
|
4
|
+
start(controller) {
|
5
|
+
const encoder = new TextEncoder();
|
6
|
+
controller.enqueue(encoder.encode("Hello"));
|
7
|
+
controller.enqueue(encoder.encode(" "));
|
8
|
+
controller.enqueue(encoder.encode("World"));
|
9
|
+
controller.enqueue(encoder.encode("!"));
|
10
|
+
controller.close();
|
11
|
+
},
|
12
|
+
}))).toBe("Hello World!");
|
13
|
+
});
|
14
|
+
it("stream2string maxSize", async () => {
|
15
|
+
const instr = "Hello World!";
|
16
|
+
for (let i = 0; i < instr.length; i++) {
|
17
|
+
expect(await stream2string(new ReadableStream({
|
18
|
+
start(controller) {
|
19
|
+
const encoder = new TextEncoder();
|
20
|
+
controller.enqueue(encoder.encode("Hello"));
|
21
|
+
controller.enqueue(encoder.encode(" "));
|
22
|
+
controller.enqueue(encoder.encode("World"));
|
23
|
+
controller.enqueue(encoder.encode("!"));
|
24
|
+
controller.close();
|
25
|
+
},
|
26
|
+
}), i)).toBe(instr.slice(0, i));
|
27
|
+
}
|
28
|
+
});
|
29
|
+
//# sourceMappingURL=stream2string.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"stream2string.test.js","sourceRoot":"","sources":["../../../src/utils/stream2string.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,EAAE,CAAC,eAAe,EAAE,KAAK,IAAI,EAAE;IAC7B,MAAM,CACJ,MAAM,aAAa,CACjB,IAAI,cAAc,CAAC;QACjB,KAAK,CAAC,UAAU;YACd,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;YAClC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;YAC5C,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC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str: string, ende?: TxtEnDecoder): ReadableStream<Uint8Array>;
|
3
|
+
export declare function uint8array2stream(str: Uint8Array): ReadableStream<Uint8Array>;
|
4
|
+
//# sourceMappingURL=string2stream.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"string2stream.d.ts","sourceRoot":"","sources":["../../../src/utils/string2stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA0B,MAAM,sBAAsB,CAAC;AAE5E,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,YAAuC,GAAG,cAAc,CAAC,UAAU,CAAC,CAEpH;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC,CAO7E"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { Utf8EnDecoderSingleton } from "../txt-en-decoder.js";
|
2
|
+
export function string2stream(str, ende = Utf8EnDecoderSingleton()) {
|
3
|
+
return uint8array2stream(ende.encode(str));
|
4
|
+
}
|
5
|
+
export function uint8array2stream(str) {
|
6
|
+
return new ReadableStream({
|
7
|
+
start(controller) {
|
8
|
+
controller.enqueue(str);
|
9
|
+
controller.close();
|
10
|
+
},
|
11
|
+
});
|
12
|
+
}
|
13
|
+
//# sourceMappingURL=string2stream.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"string2stream.js","sourceRoot":"","sources":["../../../src/utils/string2stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAE5E,MAAM,UAAU,aAAa,CAAC,GAAW,EAAE,OAAqB,sBAAsB,EAAE;IACtF,OAAO,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,GAAe;IAC/C,OAAO,IAAI,cAAc,CAAa;QACpC,KAAK,CAAC,UAAU;YACd,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACxB,UAAU,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"string2stream.test.d.ts","sourceRoot":"","sources":["../../../src/utils/string2stream.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"string2stream.test.js","sourceRoot":"","sources":["../../../src/utils/string2stream.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,EAAE,CAAC,eAAe,EAAE,KAAK,IAAI,EAAE;IAC7B,MAAM,KAAK,GAAG,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;IAClD,MAAM,CAAC,MAAM,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;AAChE,CAAC,CAAC,CAAC"}
|
package/ts/version.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,EAEX,MAAM,CAAC"}
|
package/ts/version.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC;IACjC,kBAAkB,EAAE,MAAM;CAC3B,CAAC,CAAC,CAAC,CAAW,CAAC"}
|