@scelar/nodepod 1.0.5 → 1.0.6

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.
@@ -1404,9 +1404,41 @@ export const Stream = function Stream(this: any) {
1404
1404
  Object.setPrototypeOf(Stream.prototype, EventEmitter.prototype);
1405
1405
 
1406
1406
  Stream.prototype.pipe = function pipe(dest: any): any {
1407
+ const src = this;
1408
+ const onData = (chunk: any) => {
1409
+ if (dest.write) dest.write(chunk);
1410
+ };
1411
+ src.on("data", onData);
1412
+ const onEnd = () => {
1413
+ if (dest.end) dest.end();
1414
+ };
1415
+ src.on("end", onEnd);
1416
+ // store for unpipe
1417
+ if (!src._pipeDests) src._pipeDests = [];
1418
+ src._pipeDests.push({ dest, onData, onEnd });
1407
1419
  return dest;
1408
1420
  };
1409
1421
 
1422
+ Stream.prototype.unpipe = function unpipe(dest?: any): any {
1423
+ const dests: Array<{ dest: any; onData: Function; onEnd: Function }> =
1424
+ this._pipeDests || [];
1425
+ if (dest) {
1426
+ const idx = dests.findIndex((d: any) => d.dest === dest);
1427
+ if (idx !== -1) {
1428
+ this.removeListener("data", dests[idx].onData as any);
1429
+ this.removeListener("end", dests[idx].onEnd as any);
1430
+ dests.splice(idx, 1);
1431
+ }
1432
+ } else {
1433
+ for (const d of dests) {
1434
+ this.removeListener("data", d.onData as any);
1435
+ this.removeListener("end", d.onEnd as any);
1436
+ }
1437
+ this._pipeDests = [];
1438
+ }
1439
+ return this;
1440
+ };
1441
+
1410
1442
  export function addAbortSignal(
1411
1443
  signal: AbortSignal,
1412
1444
  stream: any,
@@ -1454,6 +1486,19 @@ export function pipeline(...args: unknown[]): unknown {
1454
1486
  return streams[0];
1455
1487
  }
1456
1488
 
1489
+ // web ReadableStreams (like fetch response.body) don't have .pipe(), wrap them
1490
+ for (let i = 0; i < streams.length; i++) {
1491
+ const s = streams[i];
1492
+ if (
1493
+ s &&
1494
+ typeof s.getReader === "function" &&
1495
+ typeof s.pipe !== "function" &&
1496
+ typeof s.on !== "function"
1497
+ ) {
1498
+ streams[i] = Readable.fromWeb(s);
1499
+ }
1500
+ }
1501
+
1457
1502
  let errorOccurred = false;
1458
1503
  const onError = (...errArgs: unknown[]) => {
1459
1504
  const err = errArgs[0] as Error;