@whatwg-node/node-fetch 0.7.23-alpha-20250726012104-80b722590ec2d4fb9c98bfa7a74d8daf31fcf4bf → 0.7.23-alpha-20250726021227-e4372202f654829422254520007390cd597e7720

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.
Files changed (3) hide show
  1. package/cjs/Body.js +22 -0
  2. package/esm/Body.js +23 -1
  3. package/package.json +1 -1
package/cjs/Body.js CHANGED
@@ -38,12 +38,34 @@ class PonyfillBody {
38
38
  this.contentLength = contentLength;
39
39
  this.bodyType = bodyType;
40
40
  this._buffer = buffer;
41
+ if (!buffer) {
42
+ this._chunks = this._doCollectChunksFromReadableJob();
43
+ }
41
44
  }
42
45
  bodyType;
43
46
  _bodyFactory = () => null;
44
47
  _generatedBody = null;
45
48
  _buffer;
46
49
  generateBody() {
50
+ if (!this._buffer && this._chunks) {
51
+ if ((0, promise_helpers_1.isPromise)(this._chunks)) {
52
+ return new ReadableStream_js_1.PonyfillReadableStream({
53
+ start: async (controller) => {
54
+ const chunks = await this._chunks;
55
+ if (!chunks?.length) {
56
+ this._buffer = node_buffer_1.Buffer.alloc(0);
57
+ controller.close();
58
+ return;
59
+ }
60
+ this._buffer = node_buffer_1.Buffer.concat(chunks);
61
+ for (const chunk of chunks) {
62
+ controller.enqueue(chunk);
63
+ }
64
+ controller.close();
65
+ },
66
+ });
67
+ }
68
+ }
47
69
  if (this._generatedBody?.readable?.destroyed && this._buffer) {
48
70
  this._generatedBody.readable = node_stream_1.Readable.from(this._buffer);
49
71
  }
package/esm/Body.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { Buffer } from 'node:buffer';
3
3
  import { addAbortSignal, Readable } from 'node:stream';
4
4
  import { Busboy } from '@fastify/busboy';
5
- import { handleMaybePromise } from '@whatwg-node/promise-helpers';
5
+ import { handleMaybePromise, isPromise } 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';
@@ -35,12 +35,34 @@ export class PonyfillBody {
35
35
  this.contentLength = contentLength;
36
36
  this.bodyType = bodyType;
37
37
  this._buffer = buffer;
38
+ if (!buffer) {
39
+ this._chunks = this._doCollectChunksFromReadableJob();
40
+ }
38
41
  }
39
42
  bodyType;
40
43
  _bodyFactory = () => null;
41
44
  _generatedBody = null;
42
45
  _buffer;
43
46
  generateBody() {
47
+ if (!this._buffer && this._chunks) {
48
+ if (isPromise(this._chunks)) {
49
+ return new PonyfillReadableStream({
50
+ start: async (controller) => {
51
+ const chunks = await this._chunks;
52
+ if (!chunks?.length) {
53
+ this._buffer = Buffer.alloc(0);
54
+ controller.close();
55
+ return;
56
+ }
57
+ this._buffer = Buffer.concat(chunks);
58
+ for (const chunk of chunks) {
59
+ controller.enqueue(chunk);
60
+ }
61
+ controller.close();
62
+ },
63
+ });
64
+ }
65
+ }
44
66
  if (this._generatedBody?.readable?.destroyed && this._buffer) {
45
67
  this._generatedBody.readable = Readable.from(this._buffer);
46
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.7.23-alpha-20250726012104-80b722590ec2d4fb9c98bfa7a74d8daf31fcf4bf",
3
+ "version": "0.7.23-alpha-20250726021227-e4372202f654829422254520007390cd597e7720",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {