@autonomys/asynchronous 1.4.35 → 1.5.0

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,4 @@
1
1
  import { Readable } from 'stream';
2
2
  export declare function forkStream(stream: Readable): Promise<[Readable, Readable]>;
3
+ export declare const streamToBuffer: (stream: Readable) => Promise<Buffer>;
3
4
  //# 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"}
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"}
@@ -12,6 +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
16
  exports.forkStream = forkStream;
16
17
  const stream_1 = require("stream");
17
18
  const stream_fork_1 = __importDefault(require("stream-fork"));
@@ -24,3 +25,12 @@ function forkStream(stream) {
24
25
  return [passThrough1, passThrough2];
25
26
  });
26
27
  }
28
+ const streamToBuffer = (stream) => __awaiter(void 0, void 0, void 0, function* () {
29
+ return new Promise((resolve, reject) => {
30
+ const chunks = [];
31
+ stream.on('data', (chunk) => chunks.push(chunk));
32
+ stream.on('end', () => resolve(Buffer.concat(chunks)));
33
+ stream.on('error', (error) => reject(error));
34
+ });
35
+ });
36
+ exports.streamToBuffer = streamToBuffer;
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.35",
4
+ "version": "1.5.0",
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": "939cf33bc0da04b5d65d32d78177211a7350a197",
33
+ "gitHead": "27ce75d189f2a9b0f3459cf19cc05dc07ff16100",
34
34
  "dependencies": {
35
35
  "stream-fork": "^1.0.5"
36
36
  }
@@ -10,3 +10,12 @@ export async function forkStream(stream: Readable): Promise<[Readable, Readable]
10
10
 
11
11
  return [passThrough1, passThrough2]
12
12
  }
13
+
14
+ export const streamToBuffer = async (stream: Readable): Promise<Buffer> => {
15
+ return new Promise((resolve, reject) => {
16
+ const chunks: Buffer[] = []
17
+ stream.on('data', (chunk) => chunks.push(chunk))
18
+ stream.on('end', () => resolve(Buffer.concat(chunks)))
19
+ stream.on('error', (error) => reject(error))
20
+ })
21
+ }