@autonomys/asynchronous 1.4.36 → 1.5.1
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/dist/streams/index.d.ts +1 -0
- package/dist/streams/index.d.ts.map +1 -1
- package/dist/streams/index.js +18 -1
- package/package.json +2 -2
- package/src/streams/index.ts +14 -0
package/dist/streams/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Readable } from 'stream';
|
|
2
2
|
export declare function forkStream(stream: Readable): Promise<[Readable, Readable]>;
|
|
3
3
|
export declare const streamToBuffer: (stream: Readable) => Promise<Buffer>;
|
|
4
|
+
export declare const httpBodyToStream: (body: ReadableStream) => Readable;
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/streams/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAG9C,wBAAsB,UAAU,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAQhF;AAED,eAAO,MAAM,cAAc,GAAU,QAAQ,QAAQ,KAAG,OAAO,CAAC,MAAM,CAOrE,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/streams/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAG9C,wBAAsB,UAAU,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAQhF;AAED,eAAO,MAAM,cAAc,GAAU,QAAQ,QAAQ,KAAG,OAAO,CAAC,MAAM,CAOrE,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,MAAM,cAAc,KAAG,QAYvD,CAAA"}
|
package/dist/streams/index.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.streamToBuffer = void 0;
|
|
15
|
+
exports.httpBodyToStream = exports.streamToBuffer = void 0;
|
|
16
16
|
exports.forkStream = forkStream;
|
|
17
17
|
const stream_1 = require("stream");
|
|
18
18
|
const stream_fork_1 = __importDefault(require("stream-fork"));
|
|
@@ -34,3 +34,20 @@ const streamToBuffer = (stream) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
34
34
|
});
|
|
35
35
|
});
|
|
36
36
|
exports.streamToBuffer = streamToBuffer;
|
|
37
|
+
const httpBodyToStream = (body) => {
|
|
38
|
+
const reader = body.getReader();
|
|
39
|
+
return new stream_1.Readable({
|
|
40
|
+
read() {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const { done, value } = yield reader.read();
|
|
43
|
+
if (done) {
|
|
44
|
+
this.push(null);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
this.push(value);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
exports.httpBodyToStream = httpBodyToStream;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autonomys/asynchronous",
|
|
3
3
|
"packageManager": "yarn@4.7.0",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.5.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"ts-jest": "^29.3.1",
|
|
31
31
|
"typescript": "^5.8.3"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "91ccdc57a7bc69d3587915ac654b770aba1681a4",
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"stream-fork": "^1.0.5"
|
|
36
36
|
}
|
package/src/streams/index.ts
CHANGED
|
@@ -19,3 +19,17 @@ export const streamToBuffer = async (stream: Readable): Promise<Buffer> => {
|
|
|
19
19
|
stream.on('error', (error) => reject(error))
|
|
20
20
|
})
|
|
21
21
|
}
|
|
22
|
+
|
|
23
|
+
export const httpBodyToStream = (body: ReadableStream): Readable => {
|
|
24
|
+
const reader = body.getReader()
|
|
25
|
+
return new Readable({
|
|
26
|
+
async read() {
|
|
27
|
+
const { done, value } = await reader.read()
|
|
28
|
+
if (done) {
|
|
29
|
+
this.push(null)
|
|
30
|
+
} else {
|
|
31
|
+
this.push(value)
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
}
|