@whatwg-node/node-fetch 0.7.14 → 0.7.15-alpha-20250321154634-b14f719d75c6c0d147a101272257466e1b201bc1

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/cjs/Body.js CHANGED
@@ -129,11 +129,13 @@ class PonyfillBody {
129
129
  return collectValue();
130
130
  }
131
131
  const _body = this.generateBody();
132
+ this._chunks = [];
132
133
  if (!_body) {
133
- this._chunks = [];
134
134
  return (0, utils_js_1.fakePromise)(this._chunks);
135
135
  }
136
- this._chunks = [];
136
+ if (_body.readable?.destroyed) {
137
+ return (0, promise_helpers_1.fakeRejectPromise)(new Error('Readable stream has already been consumed or destroyed.'));
138
+ }
137
139
  _body.readable.on('data', chunk => {
138
140
  this._chunks.push(chunk);
139
141
  });
package/esm/Body.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { Buffer } from 'node:buffer';
3
3
  import { Readable } from 'node:stream';
4
4
  import busboy from 'busboy';
5
- import { handleMaybePromise } from '@whatwg-node/promise-helpers';
5
+ import { fakeRejectPromise, handleMaybePromise } from '@whatwg-node/promise-helpers';
6
6
  import { hasArrayBufferMethod, hasBufferMethod, hasBytesMethod, PonyfillBlob } from './Blob.js';
7
7
  import { PonyfillFile } from './File.js';
8
8
  import { getStreamFromFormData, PonyfillFormData } from './FormData.js';
@@ -125,11 +125,13 @@ export class PonyfillBody {
125
125
  return collectValue();
126
126
  }
127
127
  const _body = this.generateBody();
128
+ this._chunks = [];
128
129
  if (!_body) {
129
- this._chunks = [];
130
130
  return fakePromise(this._chunks);
131
131
  }
132
- this._chunks = [];
132
+ if (_body.readable?.destroyed) {
133
+ return fakeRejectPromise(new Error('Readable stream has already been consumed or destroyed.'));
134
+ }
133
135
  _body.readable.on('data', chunk => {
134
136
  this._chunks.push(chunk);
135
137
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.7.14",
3
+ "version": "0.7.15-alpha-20250321154634-b14f719d75c6c0d147a101272257466e1b201bc1",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
@@ -34,7 +34,7 @@ export declare class PonyfillBody<TJSON = any> implements Body {
34
34
  }, forceSet?: boolean): void;
35
35
  get body(): PonyfillReadableStream<Uint8Array> | null;
36
36
  _chunks: Uint8Array[] | null;
37
- _collectChunksFromReadable(): MaybePromise<Uint8Array<ArrayBufferLike>[]>;
37
+ _collectChunksFromReadable(): Promise<Buffer<ArrayBufferLike>[]> | MaybePromise<Uint8Array<ArrayBufferLike>[]>;
38
38
  _blob: PonyfillBlob | null;
39
39
  blob(): Promise<PonyfillBlob>;
40
40
  _formData: PonyfillFormData | null;
package/typings/Body.d.ts CHANGED
@@ -34,7 +34,7 @@ export declare class PonyfillBody<TJSON = any> implements Body {
34
34
  }, forceSet?: boolean): void;
35
35
  get body(): PonyfillReadableStream<Uint8Array> | null;
36
36
  _chunks: Uint8Array[] | null;
37
- _collectChunksFromReadable(): MaybePromise<Uint8Array<ArrayBufferLike>[]>;
37
+ _collectChunksFromReadable(): Promise<Buffer<ArrayBufferLike>[]> | MaybePromise<Uint8Array<ArrayBufferLike>[]>;
38
38
  _blob: PonyfillBlob | null;
39
39
  blob(): Promise<PonyfillBlob>;
40
40
  _formData: PonyfillFormData | null;