@adviser/cement 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- package/file_service.d.ts +1 -0
- package/file_service.d.ts.map +1 -1
- package/mock_file_service.d.ts +3 -12
- package/mock_file_service.d.ts.map +1 -1
- package/mock_file_service.js +5 -49
- package/mock_file_service.js.map +1 -1
- package/mock_file_service.test.d.ts +2 -0
- package/mock_file_service.test.d.ts.map +1 -0
- package/mock_file_service.test.js +15 -0
- package/mock_file_service.test.js.map +1 -0
- package/node_file_service.d.ts +1 -0
- package/node_file_service.d.ts.map +1 -1
- package/node_file_service.js +6 -0
- package/node_file_service.js.map +1 -1
- package/package.json +1 -1
- package/utils/index.d.ts +6 -0
- package/utils/index.d.ts.map +1 -0
- package/utils/index.js +22 -0
- package/utils/index.js.map +1 -0
- package/utils/rebuffer.d.ts +3 -0
- package/utils/rebuffer.d.ts.map +1 -0
- package/utils/rebuffer.js +65 -0
- package/utils/rebuffer.js.map +1 -0
- package/utils/rebuffer.test.d.ts +2 -0
- package/utils/rebuffer.test.d.ts.map +1 -0
- package/utils/rebuffer.test.js +79 -0
- package/utils/rebuffer.test.js.map +1 -0
- package/utils/stream2string.d.ts +3 -0
- package/utils/stream2string.d.ts.map +1 -0
- package/utils/stream2string.js +53 -0
- package/utils/stream2string.js.map +1 -0
- package/utils/stream2string.test.d.ts +2 -0
- package/utils/stream2string.test.d.ts.map +1 -0
- package/utils/stream2string.test.js +31 -0
- package/utils/stream2string.test.js.map +1 -0
- package/utils/stream_map.d.ts +9 -0
- package/utils/stream_map.d.ts.map +1 -0
- package/utils/stream_map.js +67 -0
- package/utils/stream_map.js.map +1 -0
- package/utils/stream_map.test.d.ts +2 -0
- package/utils/stream_map.test.d.ts.map +1 -0
- package/utils/stream_map.test.js +89 -0
- package/utils/stream_map.test.js.map +1 -0
- package/utils/stream_test_helper.d.ts +15 -0
- package/utils/stream_test_helper.d.ts.map +1 -0
- package/utils/stream_test_helper.js +42 -0
- package/utils/stream_test_helper.js.map +1 -0
- package/utils/string2stream.d.ts +3 -0
- package/utils/string2stream.d.ts.map +1 -0
- package/utils/string2stream.js +18 -0
- package/utils/string2stream.js.map +1 -0
- package/utils/string2stream.test.d.ts +2 -0
- package/utils/string2stream.test.d.ts.map +1 -0
- package/utils/string2stream.test.js +9 -0
- package/utils/string2stream.test.js.map +1 -0
package/file_service.d.ts
CHANGED
@@ -6,6 +6,7 @@ export interface FileService {
|
|
6
6
|
readonly baseDir: string;
|
7
7
|
create(fname: string): Promise<NamedWritableStream>;
|
8
8
|
readFileString(fname: string): Promise<string>;
|
9
|
+
writeFileString(fname: string, content: string): Promise<void>;
|
9
10
|
abs(fname: string): string;
|
10
11
|
join(...paths: string[]): string;
|
11
12
|
relative(from: string, to?: string): string;
|
package/file_service.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"file_service.d.ts","sourceRoot":"","sources":["../src/file_service.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACpD,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;
|
1
|
+
{"version":3,"file":"file_service.d.ts","sourceRoot":"","sources":["../src/file_service.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACpD,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/C,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/D,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAE3B,IAAI,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAEjC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAE5C,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAEhC,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAElC,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;CACpC"}
|
package/mock_file_service.d.ts
CHANGED
@@ -1,19 +1,10 @@
|
|
1
|
-
import {
|
1
|
+
import { NamedWritableStream } from "./file_service";
|
2
|
+
import { NodeFileService } from "./node_file_service";
|
2
3
|
export interface FileCollector {
|
3
4
|
readonly name: string;
|
4
5
|
content: string;
|
5
6
|
}
|
6
|
-
export declare class MockFileService
|
7
|
-
readonly baseDir: string;
|
8
|
-
constructor(baseDir?: string);
|
9
|
-
nodeImport(fname: string): string;
|
10
|
-
readFileString(fname: string): Promise<string>;
|
11
|
-
dirname(fname: string): string;
|
12
|
-
basename(fname: string): string;
|
13
|
-
join(...paths: string[]): string;
|
14
|
-
relative(from: string, to?: string): string;
|
15
|
-
abs(fname: string): string;
|
16
|
-
isAbsolute(fname: string): boolean;
|
7
|
+
export declare class MockFileService extends NodeFileService {
|
17
8
|
readonly files: Record<string, FileCollector>;
|
18
9
|
create(fname: string): Promise<NamedWritableStream>;
|
19
10
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mock_file_service.d.ts","sourceRoot":"","sources":["../src/mock_file_service.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"mock_file_service.d.ts","sourceRoot":"","sources":["../src/mock_file_service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,eAAgB,SAAQ,eAAe;IAClD,QAAQ,CAAC,KAAK,gCAAuC;IAEtC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;CA0BnE"}
|
package/mock_file_service.js
CHANGED
@@ -1,59 +1,15 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
3
|
exports.MockFileService = void 0;
|
7
|
-
const
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
const node_file_service_1 = require("./node_file_service");
|
5
|
+
class MockFileService extends node_file_service_1.NodeFileService {
|
6
|
+
constructor() {
|
7
|
+
super(...arguments);
|
11
8
|
this.files = {};
|
12
|
-
this.baseDir = this.abs(baseDir);
|
13
|
-
}
|
14
|
-
nodeImport(fname) {
|
15
|
-
if (node_path_1.default.isAbsolute(fname)) {
|
16
|
-
return fname;
|
17
|
-
}
|
18
|
-
else {
|
19
|
-
return "./" + node_path_1.default.normalize(fname);
|
20
|
-
}
|
21
|
-
}
|
22
|
-
readFileString(fname) {
|
23
|
-
return promises_1.default.readFile(fname, { encoding: "utf-8" });
|
24
|
-
}
|
25
|
-
dirname(fname) {
|
26
|
-
return node_path_1.default.dirname(fname);
|
27
|
-
}
|
28
|
-
basename(fname) {
|
29
|
-
return node_path_1.default.basename(fname);
|
30
|
-
}
|
31
|
-
join(...paths) {
|
32
|
-
return node_path_1.default.join(...paths);
|
33
|
-
}
|
34
|
-
relative(from, to) {
|
35
|
-
if (to === undefined) {
|
36
|
-
to = from;
|
37
|
-
from = process.cwd();
|
38
|
-
}
|
39
|
-
const ret = node_path_1.default.relative(from, to);
|
40
|
-
return ret;
|
41
|
-
}
|
42
|
-
abs(fname) {
|
43
|
-
if (this.isAbsolute(fname)) {
|
44
|
-
return fname;
|
45
|
-
}
|
46
|
-
else {
|
47
|
-
const cwd = process.cwd();
|
48
|
-
return node_path_1.default.resolve(cwd, fname);
|
49
|
-
}
|
50
|
-
}
|
51
|
-
isAbsolute(fname) {
|
52
|
-
return node_path_1.default.isAbsolute(fname);
|
53
9
|
}
|
54
10
|
async create(fname) {
|
55
11
|
let oName = fname;
|
56
|
-
if (!
|
12
|
+
if (!this.isAbsolute(fname)) {
|
57
13
|
oName = this.abs(fname);
|
58
14
|
}
|
59
15
|
const fc = {
|
package/mock_file_service.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mock_file_service.js","sourceRoot":"","sources":["../src/mock_file_service.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"mock_file_service.js","sourceRoot":"","sources":["../src/mock_file_service.ts"],"names":[],"mappings":";;;AACA,2DAAsD;AAOtD,MAAa,eAAgB,SAAQ,mCAAe;IAApD;;QACW,UAAK,GAAG,EAAmC,CAAC;IA4BvD,CAAC;IA1BU,KAAK,CAAC,MAAM,CAAC,KAAa;QACjC,IAAI,KAAK,GAAG,KAAK,CAAC;QAClB,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5B,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC;QAED,MAAM,EAAE,GAAG;YACT,IAAI,EAAE,KAAK;YACX,OAAO,EAAE,EAAE;SACZ,CAAC;QACF,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAElC,OAAO;YACL,IAAI,EAAE,KAAK;YACX,MAAM,EAAE,IAAI,cAAc,CAAa;gBACrC,KAAK,CAAC,KAAK;oBACT,EAAE,CAAC,OAAO,GAAG,EAAE,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBAClD,CAAC;gBACD,KAAK,KAAI,CAAC;gBACV,KAAK;oBACH,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;gBACrC,CAAC;aACF,CAAC;SACH,CAAC;IACJ,CAAC;CACF;AA7BD,0CA6BC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mock_file_service.test.d.ts","sourceRoot":"","sources":["../src/mock_file_service.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const mock_file_service_1 = require("./mock_file_service");
|
4
|
+
it("writeFileString", async () => {
|
5
|
+
const f = new mock_file_service_1.MockFileService();
|
6
|
+
const fname = f.abs("test.txt");
|
7
|
+
await f.writeFileString(fname, "hello");
|
8
|
+
expect(f.files).toEqual({
|
9
|
+
[fname]: {
|
10
|
+
name: fname,
|
11
|
+
content: "hello",
|
12
|
+
},
|
13
|
+
});
|
14
|
+
});
|
15
|
+
//# sourceMappingURL=mock_file_service.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mock_file_service.test.js","sourceRoot":"","sources":["../src/mock_file_service.test.ts"],"names":[],"mappings":";;AAAA,2DAAsD;AAEtD,EAAE,CAAC,iBAAiB,EAAE,KAAK,IAAI,EAAE;IAC/B,MAAM,CAAC,GAAG,IAAI,mCAAe,EAAE,CAAC;IAChC,MAAM,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAChC,MAAM,CAAC,CAAC,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACxC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;QACtB,CAAC,KAAK,CAAC,EAAE;YACP,IAAI,EAAE,KAAK;YACX,OAAO,EAAE,OAAO;SACjB;KACF,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/node_file_service.d.ts
CHANGED
@@ -10,6 +10,7 @@ export declare class NodeFileService implements FileService {
|
|
10
10
|
relative(from: string, to?: string): string;
|
11
11
|
abs(fname: string): string;
|
12
12
|
isAbsolute(fname: string): boolean;
|
13
|
+
writeFileString(fname: string, content: string): Promise<void>;
|
13
14
|
create(fname: string): Promise<NamedWritableStream>;
|
14
15
|
}
|
15
16
|
//# sourceMappingURL=node_file_service.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"node_file_service.d.ts","sourceRoot":"","sources":["../src/node_file_service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAElE,qBAAa,eAAgB,YAAW,WAAW;IACjD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBACb,OAAO,GAAE,MAAsB;IAI3C,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IASjC,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI9C,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAG9B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAI/B,IAAI,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM;IAIhC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM;IAU3C,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAS1B,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAI5B,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAwB1D"}
|
1
|
+
{"version":3,"file":"node_file_service.d.ts","sourceRoot":"","sources":["../src/node_file_service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAElE,qBAAa,eAAgB,YAAW,WAAW;IACjD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBACb,OAAO,GAAE,MAAsB;IAI3C,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IASjC,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI9C,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAG9B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAI/B,IAAI,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM;IAIhC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM;IAU3C,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAS1B,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAI5B,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO9D,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAwB1D"}
|
package/node_file_service.js
CHANGED
@@ -50,6 +50,12 @@ class NodeFileService {
|
|
50
50
|
isAbsolute(fname) {
|
51
51
|
return node_path_1.default.isAbsolute(fname);
|
52
52
|
}
|
53
|
+
async writeFileString(fname, content) {
|
54
|
+
const o = await this.create(fname);
|
55
|
+
const wr = o.stream.getWriter();
|
56
|
+
await wr.write(new TextEncoder().encode(content));
|
57
|
+
await wr.close();
|
58
|
+
}
|
53
59
|
async create(fname) {
|
54
60
|
let oName = fname;
|
55
61
|
if (!node_path_1.default.isAbsolute(fname)) {
|
package/node_file_service.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"node_file_service.js","sourceRoot":"","sources":["../src/node_file_service.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA6B;AAC7B,sDAAyB;AAGzB,MAAa,eAAe;IAE1B,YAAY,UAAkB,OAAO,CAAC,GAAG,EAAE;QACzC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAED,UAAU,CAAC,KAAa;QAEtB,IAAI,mBAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAC;QACf,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,GAAG,mBAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IAED,cAAc,CAAC,KAAa;QAC1B,OAAO,iBAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED,OAAO,CAAC,KAAa;QACnB,OAAO,mBAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IACD,QAAQ,CAAC,KAAa;QACpB,OAAO,mBAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAED,IAAI,CAAC,GAAG,KAAe;QACrB,OAAO,mBAAI,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED,QAAQ,CAAC,IAAY,EAAE,EAAW;QAChC,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;YACrB,EAAE,GAAG,IAAI,CAAC;YAC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AI,EAAE,KAAK;YACX,MAAM,EAAE,IAAI,cAAc,CAAa;gBACrC,KAAK,CAAC,KAAK;oBACT,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACnB,CAAC;gBACD,KAAK;oBACH,GAAG,CAAC,KAAK,EAAE,CAAC;gBACd,CAAC;gBACD,KAAK;oBACH,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;gBACrC,CAAC;aACF,CAAC;SACH,CAAC;IACJ,CAAC;CACF;AApFD,0CAoFC"}
|
package/package.json
CHANGED
package/utils/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC"}
|
package/utils/index.js
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./rebuffer"), exports);
|
18
|
+
__exportStar(require("./stream_map"), exports);
|
19
|
+
__exportStar(require("./stream2string"), exports);
|
20
|
+
__exportStar(require("./stream_test_helper"), exports);
|
21
|
+
__exportStar(require("./string2stream"), exports);
|
22
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,+CAA6B;AAC7B,kDAAgC;AAChC,uDAAqC;AACrC,kDAAgC"}
|
@@ -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;AAoDD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,cAAc,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,cAAc,CAAC,UAAU,CAAC,CAcrG"}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.rebuffer = exports.rebufferArray = void 0;
|
4
|
+
const stream_map_1 = require("./stream_map");
|
5
|
+
async function rebufferArray(a, chunkSize) {
|
6
|
+
return (0, stream_map_1.stream2array)(rebuffer((0, stream_map_1.array2stream)(a), chunkSize));
|
7
|
+
}
|
8
|
+
exports.rebufferArray = rebufferArray;
|
9
|
+
function reChunk(cs, chunkSize) {
|
10
|
+
const len = cs.reduce((acc, v) => acc + v.length, 0);
|
11
|
+
const last = cs[cs.length - 1];
|
12
|
+
const lastOfs = len - last.length;
|
13
|
+
const rest = last.subarray(chunkSize - lastOfs);
|
14
|
+
cs[cs.length - 1] = last.subarray(0, chunkSize - lastOfs);
|
15
|
+
const chunk = new Uint8Array(chunkSize);
|
16
|
+
let ofs = 0;
|
17
|
+
for (let i = 0; i < cs.length; i++) {
|
18
|
+
chunk.set(cs[i], ofs);
|
19
|
+
ofs += cs[i].length;
|
20
|
+
}
|
21
|
+
return { rest, chunk };
|
22
|
+
}
|
23
|
+
function pump(ps, controller, next) {
|
24
|
+
ps.reader.read().then(({ done, value }) => {
|
25
|
+
if (done) {
|
26
|
+
if (ps.tmpLen > 0) {
|
27
|
+
controller.enqueue(reChunk(ps.tmp, ps.tmpLen).chunk);
|
28
|
+
}
|
29
|
+
controller.close();
|
30
|
+
next();
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
if (ps.tmpLen + value.length > ps.chunkSize) {
|
34
|
+
ps.tmp.push(value);
|
35
|
+
const res = reChunk(ps.tmp, ps.chunkSize);
|
36
|
+
controller.enqueue(res.chunk);
|
37
|
+
ps.tmp = [res.rest];
|
38
|
+
ps.tmpLen = res.rest.length;
|
39
|
+
next();
|
40
|
+
return;
|
41
|
+
}
|
42
|
+
else if (value.length) {
|
43
|
+
ps.tmp.push(value);
|
44
|
+
ps.tmpLen += value.length;
|
45
|
+
}
|
46
|
+
pump(ps, controller, next);
|
47
|
+
});
|
48
|
+
}
|
49
|
+
function rebuffer(a, chunkSize) {
|
50
|
+
const state = {
|
51
|
+
reader: a.getReader(),
|
52
|
+
tmp: [],
|
53
|
+
tmpLen: 0,
|
54
|
+
chunkSize,
|
55
|
+
};
|
56
|
+
return new ReadableStream({
|
57
|
+
async pull(controller) {
|
58
|
+
return new Promise((resolve) => {
|
59
|
+
pump(state, controller, resolve);
|
60
|
+
});
|
61
|
+
},
|
62
|
+
});
|
63
|
+
}
|
64
|
+
exports.rebuffer = rebuffer;
|
65
|
+
//# sourceMappingURL=rebuffer.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"rebuffer.js","sourceRoot":"","sources":["../../src/utils/rebuffer.ts"],"names":[],"mappings":";;;AAAA,6CAA0D;AAOnD,KAAK,UAAU,aAAa,CAAC,CAAe,EA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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;AAdD,4BAcC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"rebuffer.test.d.ts","sourceRoot":"","sources":["../../src/utils/rebuffer.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,79 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const rebuffer_1 = require("./rebuffer");
|
4
|
+
const stream_test_helper_1 = require("./stream_test_helper");
|
5
|
+
it("rechunk empty", async () => {
|
6
|
+
const chunks = await (0, rebuffer_1.rebufferArray)([], 10);
|
7
|
+
expect(chunks.length).toEqual(0);
|
8
|
+
});
|
9
|
+
it("rechunk 0 size", async () => {
|
10
|
+
const chunks = await (0, rebuffer_1.rebufferArray)([new Uint8Array(0)], 10);
|
11
|
+
expect(chunks.length).toEqual(0);
|
12
|
+
});
|
13
|
+
it("rechunk smaller 10", async () => {
|
14
|
+
const chunks = await (0, rebuffer_1.rebufferArray)([new Uint8Array(3)], 10);
|
15
|
+
expect(chunks.length).toEqual(1);
|
16
|
+
expect(chunks[0].length).toEqual(3);
|
17
|
+
});
|
18
|
+
it("rechunk smaller 10 pack smaller chunks", async () => {
|
19
|
+
const chunks = await (0, rebuffer_1.rebufferArray)(Array(7)
|
20
|
+
.fill(0)
|
21
|
+
.map((_, i) => {
|
22
|
+
const o = new Uint8Array(3);
|
23
|
+
for (let j = 0; j < o.length; j++) {
|
24
|
+
o[j] = i * o.length + j;
|
25
|
+
}
|
26
|
+
return o;
|
27
|
+
}), 10);
|
28
|
+
expect(chunks.length).toEqual(3);
|
29
|
+
expect(chunks[0].length).toEqual(10);
|
30
|
+
expect(Array.from(chunks[0]).map((i) => i)).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
31
|
+
expect(chunks[1].length).toEqual(10);
|
32
|
+
expect(Array.from(chunks[1]).map((i) => i)).toEqual([10, 11, 12, 13, 14, 15, 16, 17, 18, 19]);
|
33
|
+
expect(chunks[2].length).toEqual(1);
|
34
|
+
expect(Array.from(chunks[2]).map((i) => i)).toEqual([20]);
|
35
|
+
});
|
36
|
+
it("rechunk smaller 10 pack bigger chunks", async () => {
|
37
|
+
const chunks = await (0, rebuffer_1.rebufferArray)(Array(3)
|
38
|
+
.fill(0)
|
39
|
+
.map((_, i) => {
|
40
|
+
const o = new Uint8Array(11);
|
41
|
+
for (let j = 0; j < o.length; j++) {
|
42
|
+
o[j] = i * o.length + j;
|
43
|
+
}
|
44
|
+
return o;
|
45
|
+
}), 10);
|
46
|
+
expect(chunks.length).toEqual(4);
|
47
|
+
expect(chunks[0].length).toEqual(10);
|
48
|
+
expect(Array.from(chunks[0]).map((i) => i)).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
49
|
+
expect(chunks[1].length).toEqual(10);
|
50
|
+
expect(Array.from(chunks[1]).map((i) => i)).toEqual([10, 11, 12, 13, 14, 15, 16, 17, 18, 19]);
|
51
|
+
expect(chunks[2].length).toEqual(10);
|
52
|
+
expect(Array.from(chunks[2]).map((i) => i)).toEqual([20, 21, 22, 23, 24, 25, 26, 27, 28, 29]);
|
53
|
+
expect(chunks[3].length).toEqual(3);
|
54
|
+
expect(Array.from(chunks[3]).map((i) => i)).toEqual([30, 31, 32]);
|
55
|
+
});
|
56
|
+
describe("test streaming through rebuffer", () => {
|
57
|
+
const state = {
|
58
|
+
sendChunks: 10000,
|
59
|
+
sendChunkSize: 3,
|
60
|
+
fillCalls: 0,
|
61
|
+
CollectorFn: jest.fn(),
|
62
|
+
};
|
63
|
+
const reBufferSize = 11;
|
64
|
+
it("does rebuffer respect backpressure", async () => {
|
65
|
+
const ts = new TransformStream(undefined, undefined, { highWaterMark: 2 });
|
66
|
+
const reb = (0, rebuffer_1.rebuffer)(ts.readable, reBufferSize);
|
67
|
+
await Promise.all([(0, stream_test_helper_1.receiveFromStream)(reb, state), (0, stream_test_helper_1.sendToStream)(ts.writable, state)]);
|
68
|
+
expect(state.CollectorFn).toBeCalledTimes(~~((state.sendChunkSize * state.sendChunks) / reBufferSize) + 1 + 1);
|
69
|
+
expect(state.CollectorFn.mock.calls.slice(-1)[0][0].done).toBeTruthy();
|
70
|
+
let lastfillCalls = 0;
|
71
|
+
for (let i = 0; i < state.CollectorFn.mock.calls.length - 1; i++) {
|
72
|
+
const { fillCalls, reBufferCalls, value } = state.CollectorFn.mock.calls[i][0];
|
73
|
+
expect(value[0]).toBe(~~((reBufferSize * i) / state.sendChunkSize) % 256);
|
74
|
+
expect(fillCalls * state.sendChunkSize).toBeGreaterThanOrEqual((fillCalls - lastfillCalls) * state.sendChunkSize + reBufferCalls * reBufferSize);
|
75
|
+
lastfillCalls = fillCalls;
|
76
|
+
}
|
77
|
+
});
|
78
|
+
});
|
79
|
+
//# 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,yCAAqD;AACrD,6DAA2F;AAE3F,EAAE,CAAC,eAAe,EAAE,KAAK,IAAI,EAAE;IAC7B,MAAM,MAAM,GAAG,MAAM,IAAA,wBAAa,EAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAC3C,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACnC,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,gBAAgB,EAAE,KAAK,IAAI,EAAE;IAC9B,MAAM,MAAM,GAAG,MAAM,IAAA,wBAAa,EAAC,CAAC,IAAI,UAAU,CAAC,C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../../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,CA0BjH;AAED,wBAAsB,iBAAiB,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,CAmBvG"}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.stream2uint8array = exports.stream2string = void 0;
|
4
|
+
async function stream2string(stream, maxSize) {
|
5
|
+
if (!stream) {
|
6
|
+
return Promise.resolve("");
|
7
|
+
}
|
8
|
+
const reader = stream.getReader();
|
9
|
+
let res = "";
|
10
|
+
const decoder = new TextDecoder();
|
11
|
+
let rSize = 0;
|
12
|
+
while (typeof maxSize === "undefined" || rSize < maxSize) {
|
13
|
+
try {
|
14
|
+
const read = await reader.read();
|
15
|
+
if (read.done) {
|
16
|
+
break;
|
17
|
+
}
|
18
|
+
if (maxSize && rSize + read.value.length > maxSize) {
|
19
|
+
read.value = read.value.slice(0, maxSize - rSize);
|
20
|
+
}
|
21
|
+
const block = decoder.decode(read.value, { stream: true });
|
22
|
+
rSize += read.value.length;
|
23
|
+
res += block;
|
24
|
+
}
|
25
|
+
catch (err) {
|
26
|
+
return Promise.reject(err);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
return Promise.resolve(res);
|
30
|
+
}
|
31
|
+
exports.stream2string = stream2string;
|
32
|
+
async function stream2uint8array(stream) {
|
33
|
+
if (!stream) {
|
34
|
+
return Promise.resolve(new Uint8Array());
|
35
|
+
}
|
36
|
+
const reader = stream.getReader();
|
37
|
+
let res = new Uint8Array();
|
38
|
+
while (1) {
|
39
|
+
try {
|
40
|
+
const { done, value } = await reader.read();
|
41
|
+
if (done) {
|
42
|
+
break;
|
43
|
+
}
|
44
|
+
res = new Uint8Array([...res, ...value]);
|
45
|
+
}
|
46
|
+
catch (err) {
|
47
|
+
return Promise.reject(err);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
return Promise.resolve(res);
|
51
|
+
}
|
52
|
+
exports.stream2uint8array = stream2uint8array;
|
53
|
+
//# sourceMappingURL=stream2string.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"stream2string.js","sourceRoot":"","sources":["../../src/utils/stream2string.ts"],"names":[],"mappings":";;;AAAO,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;IAEd,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;YACD,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;YAC3D,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;YAC3B,GAAG,IAAI,KAAK,CAAC;QACf,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAC9B,CAAC;AA1BD,sCA0BC;AAEM,KAAK,UAAU,iBAAiB,CAAC,MAA0C;IAChF,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,UAAU,EAAE,CAAC,CAAC;IAC3C,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IAClC,IAAI,GAAG,GAAG,IAAI,UAAU,EAAE,CAAC;IAE3B,OAAO,CAAC,EAAE,CAAC;QACT,IAAI,CAAC;YACH,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YAC5C,IAAI,IAAI,EAAE,CAAC;gBACT,MAAM;YACR,CAAC;YACD,GAAG,GAAG,IAAI,UAAU,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;QAC3C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAC9B,CAAC;AAnBD,8CAmBC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"stream2string.test.d.ts","sourceRoot":"","sources":["../../src/utils/stream2string.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const stream2string_1 = require("./stream2string");
|
4
|
+
it("stream2string", async () => {
|
5
|
+
expect(await (0, stream2string_1.stream2string)(new ReadableStream({
|
6
|
+
start(controller) {
|
7
|
+
const encoder = new TextEncoder();
|
8
|
+
controller.enqueue(encoder.encode("Hello"));
|
9
|
+
controller.enqueue(encoder.encode(" "));
|
10
|
+
controller.enqueue(encoder.encode("World"));
|
11
|
+
controller.enqueue(encoder.encode("!"));
|
12
|
+
controller.close();
|
13
|
+
},
|
14
|
+
}))).toBe("Hello World!");
|
15
|
+
});
|
16
|
+
it("stream2string maxSize", async () => {
|
17
|
+
const instr = "Hello World!";
|
18
|
+
for (let i = 0; i < instr.length; i++) {
|
19
|
+
expect(await (0, stream2string_1.stream2string)(new ReadableStream({
|
20
|
+
start(controller) {
|
21
|
+
const encoder = new TextEncoder();
|
22
|
+
controller.enqueue(encoder.encode("Hello"));
|
23
|
+
controller.enqueue(encoder.encode(" "));
|
24
|
+
controller.enqueue(encoder.encode("World"));
|
25
|
+
controller.enqueue(encoder.encode("!"));
|
26
|
+
controller.close();
|
27
|
+
},
|
28
|
+
}), i)).toBe(instr.slice(0, i));
|
29
|
+
}
|
30
|
+
});
|
31
|
+
//# 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,mDAAgD;AAEhD,EAAE,CAAC,eAAe,EAAE,KAAK,IAAI,EAAE;IAC7B,MAAM,CACJ,MAAM,IAAA,6BAAa,EACjB,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,GAAG,CAAC,CAAC,CAAC;YACxC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM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: 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,CAoB5F;AAED,wBAAsB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAYtE;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,CAYxE"}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.stream2array = exports.array2stream = exports.devnull = exports.streamMap = void 0;
|
4
|
+
function streamMap(s, sm) {
|
5
|
+
const state = { reader: s.getReader(), streamMap: sm, idx: 0 };
|
6
|
+
return new ReadableStream({
|
7
|
+
async pull(controller) {
|
8
|
+
const { done, value } = await state.reader.read();
|
9
|
+
if (done) {
|
10
|
+
state.streamMap.Close && state.streamMap.Close();
|
11
|
+
controller.close();
|
12
|
+
return;
|
13
|
+
}
|
14
|
+
const promiseOrU = state.streamMap.Map(value, state.idx++);
|
15
|
+
let mapped;
|
16
|
+
if (promiseOrU instanceof Promise || typeof promiseOrU.then === "function") {
|
17
|
+
mapped = await promiseOrU;
|
18
|
+
}
|
19
|
+
else {
|
20
|
+
mapped = promiseOrU;
|
21
|
+
}
|
22
|
+
controller.enqueue(mapped);
|
23
|
+
},
|
24
|
+
});
|
25
|
+
}
|
26
|
+
exports.streamMap = streamMap;
|
27
|
+
async function devnull(a) {
|
28
|
+
const reader = a.getReader();
|
29
|
+
let cnt = 0;
|
30
|
+
while (true) {
|
31
|
+
const { done } = await reader.read();
|
32
|
+
if (done) {
|
33
|
+
break;
|
34
|
+
}
|
35
|
+
cnt++;
|
36
|
+
}
|
37
|
+
return cnt;
|
38
|
+
}
|
39
|
+
exports.devnull = devnull;
|
40
|
+
function array2stream(a) {
|
41
|
+
let i = 0;
|
42
|
+
return new ReadableStream({
|
43
|
+
pull(controller) {
|
44
|
+
if (i >= a.length) {
|
45
|
+
controller.close();
|
46
|
+
return;
|
47
|
+
}
|
48
|
+
controller.enqueue(a[i]);
|
49
|
+
i++;
|
50
|
+
},
|
51
|
+
});
|
52
|
+
}
|
53
|
+
exports.array2stream = array2stream;
|
54
|
+
async function stream2array(a) {
|
55
|
+
const ret = [];
|
56
|
+
const reader = a.getReader();
|
57
|
+
while (true) {
|
58
|
+
const { done, value } = await reader.read();
|
59
|
+
if (done) {
|
60
|
+
break;
|
61
|
+
}
|
62
|
+
ret.push(value);
|
63
|
+
}
|
64
|
+
return ret;
|
65
|
+
}
|
66
|
+
exports.stream2array = stream2array;
|
67
|
+
//# sourceMappingURL=stream_map.js.map
|
@@ -0,0 +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AM,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;AAZD,0BAYC;AAED,SAAgB,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;AAZD,oCAYC;AAEM,KAAK,UAAU,YAAY,CAAI,CAAoB;IACxD,MAAM,GAAG,GAAQ,EAAE,CAAC;IACpB,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC;IAE7B,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;AAZD,oCAYC"}
|
@@ -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,89 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const stream_test_helper_1 = require("./stream_test_helper");
|
4
|
+
const stream_map_1 = require("./stream_map");
|
5
|
+
it("array2stream", async () => {
|
6
|
+
const as = (0, stream_map_1.array2stream)([1, 2, 3]);
|
7
|
+
let i = 0;
|
8
|
+
const reader = as.getReader();
|
9
|
+
while (true) {
|
10
|
+
const { done, value } = await reader.read();
|
11
|
+
if (done) {
|
12
|
+
break;
|
13
|
+
}
|
14
|
+
expect(1 + i++).toBe(value);
|
15
|
+
}
|
16
|
+
});
|
17
|
+
it("stream2array", async () => {
|
18
|
+
const as = await (0, stream_map_1.stream2array)(new ReadableStream({
|
19
|
+
start(controller) {
|
20
|
+
controller.enqueue(1);
|
21
|
+
controller.enqueue(2);
|
22
|
+
controller.enqueue(3);
|
23
|
+
controller.close();
|
24
|
+
},
|
25
|
+
}));
|
26
|
+
expect(as).toEqual([1, 2, 3]);
|
27
|
+
});
|
28
|
+
it("devnull", async () => {
|
29
|
+
const cnt = await (0, stream_map_1.devnull)((0, stream_map_1.streamMap)((0, stream_map_1.array2stream)([1, 2, 3]), {
|
30
|
+
Map: (i, idx) => (idx + 1) * 10 + i + 1,
|
31
|
+
}));
|
32
|
+
expect(cnt).toBe(3);
|
33
|
+
});
|
34
|
+
it("stream_map", async () => {
|
35
|
+
const closeFn = jest.fn();
|
36
|
+
const s = await (0, stream_map_1.stream2array)((0, stream_map_1.streamMap)((0, stream_map_1.array2stream)([1, 2, 3]), {
|
37
|
+
Map: (i, idx) => (idx + 1) * 10 + i + 1,
|
38
|
+
Close: closeFn,
|
39
|
+
}));
|
40
|
+
expect(closeFn).toBeCalledTimes(1);
|
41
|
+
expect(s).toEqual([12, 23, 34]);
|
42
|
+
});
|
43
|
+
it("stream_map async", async () => {
|
44
|
+
const closeFn = jest.fn();
|
45
|
+
const s = await (0, stream_map_1.stream2array)((0, stream_map_1.streamMap)((0, stream_map_1.array2stream)([1, 2, 3]), {
|
46
|
+
Map: (i, idx) => Promise.resolve((idx + 1) * 10 + i + 1),
|
47
|
+
Close: closeFn,
|
48
|
+
}));
|
49
|
+
expect(closeFn).toBeCalledTimes(1);
|
50
|
+
expect(s).toEqual([12, 23, 34]);
|
51
|
+
});
|
52
|
+
it("map types", async () => {
|
53
|
+
const oo = await (0, stream_map_1.stream2array)((0, stream_map_1.streamMap)((0, stream_map_1.array2stream)([1, 2, 3]), {
|
54
|
+
Map: (chunk, idx) => {
|
55
|
+
return "[" + chunk + "/" + idx + "]";
|
56
|
+
},
|
57
|
+
}));
|
58
|
+
expect(oo).toEqual(["[1/0]", "[2/1]", "[3/2]"]);
|
59
|
+
});
|
60
|
+
describe("test streaming through streamMap", () => {
|
61
|
+
const state = {
|
62
|
+
sendChunks: 10000,
|
63
|
+
sendChunkSize: 3,
|
64
|
+
fillCalls: 0,
|
65
|
+
CollectorFn: jest.fn(),
|
66
|
+
};
|
67
|
+
it("does streamMap respect backpressure", async () => {
|
68
|
+
const ts = new TransformStream(undefined, undefined, { highWaterMark: 2 });
|
69
|
+
const reb = (0, stream_map_1.streamMap)(ts.readable, {
|
70
|
+
Map: (chunk) => {
|
71
|
+
for (let i = 0; i < chunk.length; i++) {
|
72
|
+
chunk[i] = (chunk[i] + 1) % 256;
|
73
|
+
}
|
74
|
+
return chunk;
|
75
|
+
},
|
76
|
+
});
|
77
|
+
await Promise.all([(0, stream_test_helper_1.receiveFromStream)(reb, state), (0, stream_test_helper_1.sendToStream)(ts.writable, state)]);
|
78
|
+
expect(state.CollectorFn).toBeCalledTimes(state.sendChunks + 1);
|
79
|
+
expect(state.CollectorFn.mock.calls.slice(-1)[0][0].done).toBeTruthy();
|
80
|
+
let lastfillCalls = 0;
|
81
|
+
for (let i = 0; i < state.CollectorFn.mock.calls.length - 1; i++) {
|
82
|
+
const { fillCalls, reBufferCalls, value } = state.CollectorFn.mock.calls[i][0];
|
83
|
+
expect(value[0]).toBe((i + 1) % 256);
|
84
|
+
expect(fillCalls * state.sendChunkSize).toBeGreaterThanOrEqual((fillCalls - lastfillCalls) * state.sendChunkSize + reBufferCalls * state.sendChunkSize);
|
85
|
+
lastfillCalls = fillCalls;
|
86
|
+
}
|
87
|
+
});
|
88
|
+
});
|
89
|
+
//# 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,6DAA2F;AAC3F,6CAA8E;AAE9E,EAAE,CAAC,cAAc,EAAE,KAAK,IAAI,EAAE;IAC5B,MAAM,EAAE,GAAG,IAAA,yBAAY,EAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACnC,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,MAAM,MAAM,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC;IAE9B,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,MAAM,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,cAAc,EAAE,KAAK,IAAI,EAAE;IAC5B,MAAM,EAAE,GAAG,MAAM,IAAA,yBAAY,EAC3B,IAAI,cAAc,CAAC;QACjB,KAAK,CAAC,UAAU;YACd,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACtB,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACtB,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACtB,UAAU,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;KACF,CAAC,CACH,CAAC;IACF,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAChC,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE;IACvB,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GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;YACtC,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,15 @@
|
|
1
|
+
/// <reference types="jest" />
|
2
|
+
export interface streamingTestState {
|
3
|
+
readonly sendChunks: number;
|
4
|
+
readonly sendChunkSize: number;
|
5
|
+
fillCalls: number;
|
6
|
+
CollectorFn: jest.Mock<void, [{
|
7
|
+
done: boolean;
|
8
|
+
value: Uint8Array | undefined;
|
9
|
+
fillCalls: number;
|
10
|
+
reBufferCalls: number;
|
11
|
+
}]>;
|
12
|
+
}
|
13
|
+
export declare function receiveFromStream(reb: ReadableStream<Uint8Array>, state: streamingTestState): Promise<void>;
|
14
|
+
export declare function sendToStream(reb: WritableStream<Uint8Array>, state: streamingTestState): Promise<void>;
|
15
|
+
//# 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,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,IAAI,CAAC,IAAI,EAAE,CAAC;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;CAC5H;AAED,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,cAAc,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,kBAAkB,iBAiBjG;AAED,wBAAsB,YAAY,CAAC,GAAG,EAAE,cAAc,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,kBAAkB,iBAiB5F"}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.sendToStream = exports.receiveFromStream = void 0;
|
4
|
+
async function receiveFromStream(reb, state) {
|
5
|
+
return new Promise((resolve) => {
|
6
|
+
let reBufferCalls = 0;
|
7
|
+
const reader = reb.getReader();
|
8
|
+
function pump() {
|
9
|
+
reader.read().then(({ done, value }) => {
|
10
|
+
state.CollectorFn({ done, value, fillCalls: state.fillCalls, reBufferCalls });
|
11
|
+
reBufferCalls++;
|
12
|
+
if (done) {
|
13
|
+
resolve();
|
14
|
+
return;
|
15
|
+
}
|
16
|
+
pump();
|
17
|
+
});
|
18
|
+
}
|
19
|
+
pump();
|
20
|
+
});
|
21
|
+
}
|
22
|
+
exports.receiveFromStream = receiveFromStream;
|
23
|
+
async function sendToStream(reb, state) {
|
24
|
+
return new Promise((resolve) => {
|
25
|
+
const writer = reb.getWriter();
|
26
|
+
function pump(i) {
|
27
|
+
if (i >= state.sendChunks) {
|
28
|
+
writer.close();
|
29
|
+
resolve();
|
30
|
+
return;
|
31
|
+
}
|
32
|
+
writer.ready.then(() => {
|
33
|
+
state.fillCalls++;
|
34
|
+
writer.write(new Uint8Array(Array(state.sendChunkSize).fill(i)));
|
35
|
+
pump(i + 1);
|
36
|
+
});
|
37
|
+
}
|
38
|
+
pump(0);
|
39
|
+
});
|
40
|
+
}
|
41
|
+
exports.sendToStream = sendToStream;
|
42
|
+
//# sourceMappingURL=stream_test_helper.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"stream_test_helper.js","sourceRoot":"","sources":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,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;AAjBD,oCAiBC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"string2stream.d.ts","sourceRoot":"","sources":["../../src/utils/string2stream.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAC,UAAU,CAAC,CAGrE;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC,CAO7E"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.uint8array2stream = exports.string2stream = void 0;
|
4
|
+
function string2stream(str) {
|
5
|
+
const encoder = new TextEncoder();
|
6
|
+
return uint8array2stream(encoder.encode(str));
|
7
|
+
}
|
8
|
+
exports.string2stream = string2stream;
|
9
|
+
function uint8array2stream(str) {
|
10
|
+
return new ReadableStream({
|
11
|
+
start(controller) {
|
12
|
+
controller.enqueue(str);
|
13
|
+
controller.close();
|
14
|
+
},
|
15
|
+
});
|
16
|
+
}
|
17
|
+
exports.uint8array2stream = uint8array2stream;
|
18
|
+
//# sourceMappingURL=string2stream.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"string2stream.js","sourceRoot":"","sources":["../../src/utils/string2stream.ts"],"names":[],"mappings":";;;AAAA,SAAgB,aAAa,CAAC,GAAW;IACvC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,OAAO,iBAAiB,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAChD,CAAC;AAHD,sCAGC;AAED,SAAgB,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;AAPD,8CAOC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"string2stream.test.d.ts","sourceRoot":"","sources":["../../src/utils/string2stream.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const stream2string_1 = require("./stream2string");
|
4
|
+
const string2stream_1 = require("./string2stream");
|
5
|
+
it("string2stream", async () => {
|
6
|
+
const inStr = (0, string2stream_1.string2stream)("Hello World!");
|
7
|
+
expect(await (0, stream2string_1.stream2string)(inStr)).toBe("Hello World!");
|
8
|
+
});
|
9
|
+
//# sourceMappingURL=string2stream.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"string2stream.test.js","sourceRoot":"","sources":["../../src/utils/string2stream.test.ts"],"names":[],"mappings":";;AAAA,mDAAgD;AAChD,mDAAgD;AAEhD,EAAE,CAAC,eAAe,EAAE,KAAK,IAAI,EAAE;IAC7B,MAAM,KAAK,GAAG,IAAA,6BAAa,EAAC,cAAc,CAAC,CAAC;IAC5C,MAAM,CAAC,MAAM,IAAA,6BAAa,EAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;AAC1D,CAAC,CAAC,CAAC"}
|