@whatwg-node/node-fetch 0.5.12 → 0.5.13-rc-20240720155335-786d406edf2a8e2def3091aa22b969e5384fe7ea

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/Blob.js CHANGED
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PonyfillBlob = void 0;
4
+ exports.hasBufferMethod = hasBufferMethod;
5
+ exports.hasArrayBufferMethod = hasArrayBufferMethod;
6
+ exports.hasBytesMethod = hasBytesMethod;
7
+ exports.hasTextMethod = hasTextMethod;
8
+ exports.hasSizeProperty = hasSizeProperty;
9
+ exports.hasStreamMethod = hasStreamMethod;
10
+ exports.hasBlobSignature = hasBlobSignature;
4
11
  /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
5
12
  const ReadableStream_js_1 = require("./ReadableStream.js");
6
13
  const utils_js_1 = require("./utils.js");
@@ -18,38 +25,89 @@ function getBlobPartAsBuffer(blobPart) {
18
25
  return Buffer.from(blobPart);
19
26
  }
20
27
  }
21
- function isBlob(obj) {
28
+ function hasBufferMethod(obj) {
29
+ return obj != null && obj.buffer != null;
30
+ }
31
+ function hasArrayBufferMethod(obj) {
22
32
  return obj != null && obj.arrayBuffer != null;
23
33
  }
34
+ function hasBytesMethod(obj) {
35
+ return obj != null && obj.bytes != null;
36
+ }
37
+ function hasTextMethod(obj) {
38
+ return obj != null && obj.text != null;
39
+ }
40
+ function hasSizeProperty(obj) {
41
+ return obj != null && typeof obj.size === 'number';
42
+ }
43
+ function hasStreamMethod(obj) {
44
+ return obj != null && obj.stream != null;
45
+ }
46
+ function hasBlobSignature(obj) {
47
+ return obj != null && obj[Symbol.toStringTag] === 'Blob';
48
+ }
24
49
  // Will be removed after v14 reaches EOL
25
50
  // Needed because v14 doesn't have .stream() implemented
26
51
  class PonyfillBlob {
27
52
  constructor(blobParts, options) {
28
53
  this.blobParts = blobParts;
29
54
  this._size = null;
55
+ this._buffer = null;
56
+ this._text = null;
30
57
  this.type = options?.type || 'application/octet-stream';
31
58
  this.encoding = options?.encoding || 'utf8';
32
59
  this._size = options?.size || null;
33
- if (blobParts.length === 1 && isBlob(blobParts[0])) {
60
+ if (blobParts.length === 1 && hasBlobSignature(blobParts[0])) {
34
61
  return blobParts[0];
35
62
  }
36
63
  }
37
- arrayBuffer() {
64
+ buffer() {
65
+ if (this._buffer) {
66
+ return (0, utils_js_1.fakePromise)(this._buffer);
67
+ }
38
68
  if (this.blobParts.length === 1) {
39
69
  const blobPart = this.blobParts[0];
40
- if (isBlob(blobPart)) {
41
- return blobPart.arrayBuffer();
70
+ if (hasBufferMethod(blobPart)) {
71
+ return blobPart.buffer().then(buf => {
72
+ this._buffer = buf;
73
+ return this._buffer;
74
+ });
42
75
  }
43
- return (0, utils_js_1.fakePromise)(getBlobPartAsBuffer(blobPart));
76
+ if (hasBytesMethod(blobPart)) {
77
+ return blobPart.bytes().then(bytes => {
78
+ this._buffer = Buffer.from(bytes);
79
+ return this._buffer;
80
+ });
81
+ }
82
+ if (hasArrayBufferMethod(blobPart)) {
83
+ return blobPart.arrayBuffer().then(arrayBuf => {
84
+ this._buffer = Buffer.from(arrayBuf, undefined, blobPart.size);
85
+ return this._buffer;
86
+ });
87
+ }
88
+ this._buffer = getBlobPartAsBuffer(blobPart);
89
+ return (0, utils_js_1.fakePromise)(this._buffer);
44
90
  }
45
91
  const jobs = [];
46
92
  const bufferChunks = this.blobParts.map((blobPart, i) => {
47
- if (isBlob(blobPart)) {
93
+ if (hasBufferMethod(blobPart)) {
94
+ jobs.push(blobPart.buffer().then(buf => {
95
+ bufferChunks[i] = buf;
96
+ }));
97
+ return undefined;
98
+ }
99
+ else if (hasArrayBufferMethod(blobPart)) {
48
100
  jobs.push(blobPart.arrayBuffer().then(arrayBuf => {
49
101
  bufferChunks[i] = Buffer.from(arrayBuf, undefined, blobPart.size);
50
102
  }));
51
103
  return undefined;
52
104
  }
105
+ else if (hasBytesMethod(blobPart)) {
106
+ jobs.push(blobPart.bytes().then(bytes => {
107
+ bufferChunks[i] = Buffer.from(bytes);
108
+ }));
109
+ return undefined;
110
+ }
53
111
  else {
54
112
  return getBlobPartAsBuffer(blobPart);
55
113
  }
@@ -59,19 +117,33 @@ class PonyfillBlob {
59
117
  }
60
118
  return (0, utils_js_1.fakePromise)(Buffer.concat(bufferChunks, this._size || undefined));
61
119
  }
120
+ arrayBuffer() {
121
+ return this.buffer();
122
+ }
62
123
  text() {
124
+ if (this._text) {
125
+ return (0, utils_js_1.fakePromise)(this._text);
126
+ }
63
127
  if (this.blobParts.length === 1) {
64
128
  const blobPart = this.blobParts[0];
65
129
  if (typeof blobPart === 'string') {
66
- return (0, utils_js_1.fakePromise)(blobPart);
130
+ this._text = blobPart;
131
+ return (0, utils_js_1.fakePromise)(this._text);
67
132
  }
68
- if (isBlob(blobPart)) {
69
- return blobPart.text();
133
+ if (hasTextMethod(blobPart)) {
134
+ return blobPart.text().then(text => {
135
+ this._text = text;
136
+ return this._text;
137
+ });
70
138
  }
71
139
  const buf = getBlobPartAsBuffer(blobPart);
72
- return (0, utils_js_1.fakePromise)(buf.toString(this.encoding));
140
+ this._text = buf.toString(this.encoding);
141
+ return (0, utils_js_1.fakePromise)(this._text);
73
142
  }
74
- return this.arrayBuffer().then(buf => buf.toString(this.encoding));
143
+ return this.buffer().then(buf => {
144
+ this._text = buf.toString(this.encoding);
145
+ return this._text;
146
+ });
75
147
  }
76
148
  get size() {
77
149
  if (this._size == null) {
@@ -80,7 +152,7 @@ class PonyfillBlob {
80
152
  if (typeof blobPart === 'string') {
81
153
  this._size += Buffer.byteLength(blobPart);
82
154
  }
83
- else if (isBlob(blobPart)) {
155
+ else if (hasSizeProperty(blobPart)) {
84
156
  this._size += blobPart.size;
85
157
  }
86
158
  else if ((0, utils_js_1.isArrayBufferView)(blobPart)) {
@@ -93,7 +165,7 @@ class PonyfillBlob {
93
165
  stream() {
94
166
  if (this.blobParts.length === 1) {
95
167
  const blobPart = this.blobParts[0];
96
- if (isBlob(blobPart)) {
168
+ if (hasStreamMethod(blobPart)) {
97
169
  return blobPart.stream();
98
170
  }
99
171
  const buf = getBlobPartAsBuffer(blobPart);
@@ -104,6 +176,14 @@ class PonyfillBlob {
104
176
  },
105
177
  });
106
178
  }
179
+ if (this._buffer != null) {
180
+ return new ReadableStream_js_1.PonyfillReadableStream({
181
+ start: controller => {
182
+ controller.enqueue(this._buffer);
183
+ controller.close();
184
+ },
185
+ });
186
+ }
107
187
  let blobPartIterator;
108
188
  return new ReadableStream_js_1.PonyfillReadableStream({
109
189
  start: controller => {
@@ -120,7 +200,18 @@ class PonyfillBlob {
120
200
  return;
121
201
  }
122
202
  if (blobPart) {
123
- if (isBlob(blobPart)) {
203
+ if (hasBufferMethod(blobPart)) {
204
+ return blobPart.buffer().then(buf => {
205
+ controller.enqueue(buf);
206
+ });
207
+ }
208
+ if (hasBytesMethod(blobPart)) {
209
+ return blobPart.bytes().then(bytes => {
210
+ const buf = Buffer.from(bytes);
211
+ controller.enqueue(buf);
212
+ });
213
+ }
214
+ if (hasArrayBufferMethod(blobPart)) {
124
215
  return blobPart.arrayBuffer().then(arrayBuffer => {
125
216
  const buf = Buffer.from(arrayBuffer, undefined, blobPart.size);
126
217
  controller.enqueue(buf);
package/cjs/Body.js CHANGED
@@ -189,22 +189,29 @@ class PonyfillBody {
189
189
  _body?.readable.pipe(bb);
190
190
  });
191
191
  }
192
- arrayBuffer() {
192
+ buffer() {
193
193
  if (this._buffer) {
194
194
  return (0, utils_js_1.fakePromise)(this._buffer);
195
195
  }
196
196
  if (this.bodyType === BodyInitType.Blob) {
197
- if (this.bodyInit instanceof Blob_js_1.PonyfillBlob) {
198
- return this.bodyInit.arrayBuffer().then(buf => {
197
+ if ((0, Blob_js_1.hasBufferMethod)(this.bodyInit)) {
198
+ return this.bodyInit.buffer().then(buf => {
199
199
  this._buffer = buf;
200
200
  return this._buffer;
201
201
  });
202
202
  }
203
- const bodyInitTyped = this.bodyInit;
204
- return bodyInitTyped.arrayBuffer().then(arrayBuffer => {
205
- this._buffer = Buffer.from(arrayBuffer, undefined, bodyInitTyped.size);
206
- return this._buffer;
207
- });
203
+ if ((0, Blob_js_1.hasBytesMethod)(this.bodyInit)) {
204
+ return this.bodyInit.bytes().then(bytes => {
205
+ this._buffer = Buffer.from(bytes);
206
+ return this._buffer;
207
+ });
208
+ }
209
+ if ((0, Blob_js_1.hasArrayBufferMethod)(this.bodyInit)) {
210
+ return this.bodyInit.arrayBuffer().then(buf => {
211
+ this._buffer = Buffer.from(buf, undefined, buf.byteLength);
212
+ return this._buffer;
213
+ });
214
+ }
208
215
  }
209
216
  return this._collectChunksFromReadable().then(chunks => {
210
217
  if (chunks.length === 1) {
@@ -215,12 +222,26 @@ class PonyfillBody {
215
222
  return this._buffer;
216
223
  });
217
224
  }
225
+ bytes() {
226
+ return this.buffer();
227
+ }
228
+ arrayBuffer() {
229
+ return this.buffer();
230
+ }
218
231
  json() {
219
232
  if (this._json) {
220
233
  return (0, utils_js_1.fakePromise)(this._json);
221
234
  }
222
235
  return this.text().then(text => {
223
- this._json = JSON.parse(text);
236
+ try {
237
+ this._json = JSON.parse(text);
238
+ }
239
+ catch (e) {
240
+ if (e instanceof SyntaxError) {
241
+ e.message += `, "${text}" is not valid JSON`;
242
+ }
243
+ throw e;
244
+ }
224
245
  return this._json;
225
246
  });
226
247
  }
@@ -232,7 +253,7 @@ class PonyfillBody {
232
253
  this._text = this.bodyInit;
233
254
  return (0, utils_js_1.fakePromise)(this._text);
234
255
  }
235
- return this.arrayBuffer().then(buffer => {
256
+ return this.buffer().then(buffer => {
236
257
  this._text = buffer.toString('utf-8');
237
258
  return this._text;
238
259
  });
package/esm/Blob.js CHANGED
@@ -15,38 +15,89 @@ function getBlobPartAsBuffer(blobPart) {
15
15
  return Buffer.from(blobPart);
16
16
  }
17
17
  }
18
- function isBlob(obj) {
18
+ export function hasBufferMethod(obj) {
19
+ return obj != null && obj.buffer != null;
20
+ }
21
+ export function hasArrayBufferMethod(obj) {
19
22
  return obj != null && obj.arrayBuffer != null;
20
23
  }
24
+ export function hasBytesMethod(obj) {
25
+ return obj != null && obj.bytes != null;
26
+ }
27
+ export function hasTextMethod(obj) {
28
+ return obj != null && obj.text != null;
29
+ }
30
+ export function hasSizeProperty(obj) {
31
+ return obj != null && typeof obj.size === 'number';
32
+ }
33
+ export function hasStreamMethod(obj) {
34
+ return obj != null && obj.stream != null;
35
+ }
36
+ export function hasBlobSignature(obj) {
37
+ return obj != null && obj[Symbol.toStringTag] === 'Blob';
38
+ }
21
39
  // Will be removed after v14 reaches EOL
22
40
  // Needed because v14 doesn't have .stream() implemented
23
41
  export class PonyfillBlob {
24
42
  constructor(blobParts, options) {
25
43
  this.blobParts = blobParts;
26
44
  this._size = null;
45
+ this._buffer = null;
46
+ this._text = null;
27
47
  this.type = options?.type || 'application/octet-stream';
28
48
  this.encoding = options?.encoding || 'utf8';
29
49
  this._size = options?.size || null;
30
- if (blobParts.length === 1 && isBlob(blobParts[0])) {
50
+ if (blobParts.length === 1 && hasBlobSignature(blobParts[0])) {
31
51
  return blobParts[0];
32
52
  }
33
53
  }
34
- arrayBuffer() {
54
+ buffer() {
55
+ if (this._buffer) {
56
+ return fakePromise(this._buffer);
57
+ }
35
58
  if (this.blobParts.length === 1) {
36
59
  const blobPart = this.blobParts[0];
37
- if (isBlob(blobPart)) {
38
- return blobPart.arrayBuffer();
60
+ if (hasBufferMethod(blobPart)) {
61
+ return blobPart.buffer().then(buf => {
62
+ this._buffer = buf;
63
+ return this._buffer;
64
+ });
39
65
  }
40
- return fakePromise(getBlobPartAsBuffer(blobPart));
66
+ if (hasBytesMethod(blobPart)) {
67
+ return blobPart.bytes().then(bytes => {
68
+ this._buffer = Buffer.from(bytes);
69
+ return this._buffer;
70
+ });
71
+ }
72
+ if (hasArrayBufferMethod(blobPart)) {
73
+ return blobPart.arrayBuffer().then(arrayBuf => {
74
+ this._buffer = Buffer.from(arrayBuf, undefined, blobPart.size);
75
+ return this._buffer;
76
+ });
77
+ }
78
+ this._buffer = getBlobPartAsBuffer(blobPart);
79
+ return fakePromise(this._buffer);
41
80
  }
42
81
  const jobs = [];
43
82
  const bufferChunks = this.blobParts.map((blobPart, i) => {
44
- if (isBlob(blobPart)) {
83
+ if (hasBufferMethod(blobPart)) {
84
+ jobs.push(blobPart.buffer().then(buf => {
85
+ bufferChunks[i] = buf;
86
+ }));
87
+ return undefined;
88
+ }
89
+ else if (hasArrayBufferMethod(blobPart)) {
45
90
  jobs.push(blobPart.arrayBuffer().then(arrayBuf => {
46
91
  bufferChunks[i] = Buffer.from(arrayBuf, undefined, blobPart.size);
47
92
  }));
48
93
  return undefined;
49
94
  }
95
+ else if (hasBytesMethod(blobPart)) {
96
+ jobs.push(blobPart.bytes().then(bytes => {
97
+ bufferChunks[i] = Buffer.from(bytes);
98
+ }));
99
+ return undefined;
100
+ }
50
101
  else {
51
102
  return getBlobPartAsBuffer(blobPart);
52
103
  }
@@ -56,19 +107,33 @@ export class PonyfillBlob {
56
107
  }
57
108
  return fakePromise(Buffer.concat(bufferChunks, this._size || undefined));
58
109
  }
110
+ arrayBuffer() {
111
+ return this.buffer();
112
+ }
59
113
  text() {
114
+ if (this._text) {
115
+ return fakePromise(this._text);
116
+ }
60
117
  if (this.blobParts.length === 1) {
61
118
  const blobPart = this.blobParts[0];
62
119
  if (typeof blobPart === 'string') {
63
- return fakePromise(blobPart);
120
+ this._text = blobPart;
121
+ return fakePromise(this._text);
64
122
  }
65
- if (isBlob(blobPart)) {
66
- return blobPart.text();
123
+ if (hasTextMethod(blobPart)) {
124
+ return blobPart.text().then(text => {
125
+ this._text = text;
126
+ return this._text;
127
+ });
67
128
  }
68
129
  const buf = getBlobPartAsBuffer(blobPart);
69
- return fakePromise(buf.toString(this.encoding));
130
+ this._text = buf.toString(this.encoding);
131
+ return fakePromise(this._text);
70
132
  }
71
- return this.arrayBuffer().then(buf => buf.toString(this.encoding));
133
+ return this.buffer().then(buf => {
134
+ this._text = buf.toString(this.encoding);
135
+ return this._text;
136
+ });
72
137
  }
73
138
  get size() {
74
139
  if (this._size == null) {
@@ -77,7 +142,7 @@ export class PonyfillBlob {
77
142
  if (typeof blobPart === 'string') {
78
143
  this._size += Buffer.byteLength(blobPart);
79
144
  }
80
- else if (isBlob(blobPart)) {
145
+ else if (hasSizeProperty(blobPart)) {
81
146
  this._size += blobPart.size;
82
147
  }
83
148
  else if (isArrayBufferView(blobPart)) {
@@ -90,7 +155,7 @@ export class PonyfillBlob {
90
155
  stream() {
91
156
  if (this.blobParts.length === 1) {
92
157
  const blobPart = this.blobParts[0];
93
- if (isBlob(blobPart)) {
158
+ if (hasStreamMethod(blobPart)) {
94
159
  return blobPart.stream();
95
160
  }
96
161
  const buf = getBlobPartAsBuffer(blobPart);
@@ -101,6 +166,14 @@ export class PonyfillBlob {
101
166
  },
102
167
  });
103
168
  }
169
+ if (this._buffer != null) {
170
+ return new PonyfillReadableStream({
171
+ start: controller => {
172
+ controller.enqueue(this._buffer);
173
+ controller.close();
174
+ },
175
+ });
176
+ }
104
177
  let blobPartIterator;
105
178
  return new PonyfillReadableStream({
106
179
  start: controller => {
@@ -117,7 +190,18 @@ export class PonyfillBlob {
117
190
  return;
118
191
  }
119
192
  if (blobPart) {
120
- if (isBlob(blobPart)) {
193
+ if (hasBufferMethod(blobPart)) {
194
+ return blobPart.buffer().then(buf => {
195
+ controller.enqueue(buf);
196
+ });
197
+ }
198
+ if (hasBytesMethod(blobPart)) {
199
+ return blobPart.bytes().then(bytes => {
200
+ const buf = Buffer.from(bytes);
201
+ controller.enqueue(buf);
202
+ });
203
+ }
204
+ if (hasArrayBufferMethod(blobPart)) {
121
205
  return blobPart.arrayBuffer().then(arrayBuffer => {
122
206
  const buf = Buffer.from(arrayBuffer, undefined, blobPart.size);
123
207
  controller.enqueue(buf);
package/esm/Body.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Readable } from 'stream';
2
2
  import busboy from 'busboy';
3
- import { PonyfillBlob } from './Blob.js';
3
+ import { hasArrayBufferMethod, hasBufferMethod, hasBytesMethod, PonyfillBlob } from './Blob.js';
4
4
  import { PonyfillFile } from './File.js';
5
5
  import { getStreamFromFormData, PonyfillFormData } from './FormData.js';
6
6
  import { PonyfillReadableStream } from './ReadableStream.js';
@@ -185,22 +185,29 @@ export class PonyfillBody {
185
185
  _body?.readable.pipe(bb);
186
186
  });
187
187
  }
188
- arrayBuffer() {
188
+ buffer() {
189
189
  if (this._buffer) {
190
190
  return fakePromise(this._buffer);
191
191
  }
192
192
  if (this.bodyType === BodyInitType.Blob) {
193
- if (this.bodyInit instanceof PonyfillBlob) {
194
- return this.bodyInit.arrayBuffer().then(buf => {
193
+ if (hasBufferMethod(this.bodyInit)) {
194
+ return this.bodyInit.buffer().then(buf => {
195
195
  this._buffer = buf;
196
196
  return this._buffer;
197
197
  });
198
198
  }
199
- const bodyInitTyped = this.bodyInit;
200
- return bodyInitTyped.arrayBuffer().then(arrayBuffer => {
201
- this._buffer = Buffer.from(arrayBuffer, undefined, bodyInitTyped.size);
202
- return this._buffer;
203
- });
199
+ if (hasBytesMethod(this.bodyInit)) {
200
+ return this.bodyInit.bytes().then(bytes => {
201
+ this._buffer = Buffer.from(bytes);
202
+ return this._buffer;
203
+ });
204
+ }
205
+ if (hasArrayBufferMethod(this.bodyInit)) {
206
+ return this.bodyInit.arrayBuffer().then(buf => {
207
+ this._buffer = Buffer.from(buf, undefined, buf.byteLength);
208
+ return this._buffer;
209
+ });
210
+ }
204
211
  }
205
212
  return this._collectChunksFromReadable().then(chunks => {
206
213
  if (chunks.length === 1) {
@@ -211,12 +218,26 @@ export class PonyfillBody {
211
218
  return this._buffer;
212
219
  });
213
220
  }
221
+ bytes() {
222
+ return this.buffer();
223
+ }
224
+ arrayBuffer() {
225
+ return this.buffer();
226
+ }
214
227
  json() {
215
228
  if (this._json) {
216
229
  return fakePromise(this._json);
217
230
  }
218
231
  return this.text().then(text => {
219
- this._json = JSON.parse(text);
232
+ try {
233
+ this._json = JSON.parse(text);
234
+ }
235
+ catch (e) {
236
+ if (e instanceof SyntaxError) {
237
+ e.message += `, "${text}" is not valid JSON`;
238
+ }
239
+ throw e;
240
+ }
220
241
  return this._json;
221
242
  });
222
243
  }
@@ -228,7 +249,7 @@ export class PonyfillBody {
228
249
  this._text = this.bodyInit;
229
250
  return fakePromise(this._text);
230
251
  }
231
- return this.arrayBuffer().then(buffer => {
252
+ return this.buffer().then(buffer => {
232
253
  this._text = buffer.toString('utf-8');
233
254
  return this._text;
234
255
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.5.12",
3
+ "version": "0.5.13-rc-20240720155335-786d406edf2a8e2def3091aa22b969e5384fe7ea",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
@@ -14,13 +14,35 @@ interface BlobOptions {
14
14
  */
15
15
  size?: number | null;
16
16
  }
17
+ export declare function hasBufferMethod(obj: any): obj is {
18
+ buffer(): Promise<Buffer>;
19
+ };
20
+ export declare function hasArrayBufferMethod(obj: any): obj is {
21
+ arrayBuffer(): Promise<ArrayBuffer>;
22
+ };
23
+ export declare function hasBytesMethod(obj: any): obj is {
24
+ bytes(): Promise<Uint8Array>;
25
+ };
26
+ export declare function hasTextMethod(obj: any): obj is {
27
+ text(): Promise<string>;
28
+ };
29
+ export declare function hasSizeProperty(obj: any): obj is {
30
+ size: number;
31
+ };
32
+ export declare function hasStreamMethod(obj: any): obj is {
33
+ stream(): any;
34
+ };
35
+ export declare function hasBlobSignature(obj: any): obj is Blob;
17
36
  export declare class PonyfillBlob implements Blob {
18
37
  private blobParts;
19
38
  type: string;
20
39
  private encoding;
21
40
  private _size;
22
41
  constructor(blobParts: BlobPart[], options?: BlobOptions);
23
- arrayBuffer(): Promise<Buffer>;
42
+ _buffer: Buffer | null;
43
+ buffer(): Promise<Buffer>;
44
+ arrayBuffer(): Promise<ArrayBuffer>;
45
+ _text: string | null;
24
46
  text(): Promise<string>;
25
47
  get size(): number;
26
48
  stream(): any;
package/typings/Blob.d.ts CHANGED
@@ -14,13 +14,35 @@ interface BlobOptions {
14
14
  */
15
15
  size?: number | null;
16
16
  }
17
+ export declare function hasBufferMethod(obj: any): obj is {
18
+ buffer(): Promise<Buffer>;
19
+ };
20
+ export declare function hasArrayBufferMethod(obj: any): obj is {
21
+ arrayBuffer(): Promise<ArrayBuffer>;
22
+ };
23
+ export declare function hasBytesMethod(obj: any): obj is {
24
+ bytes(): Promise<Uint8Array>;
25
+ };
26
+ export declare function hasTextMethod(obj: any): obj is {
27
+ text(): Promise<string>;
28
+ };
29
+ export declare function hasSizeProperty(obj: any): obj is {
30
+ size: number;
31
+ };
32
+ export declare function hasStreamMethod(obj: any): obj is {
33
+ stream(): any;
34
+ };
35
+ export declare function hasBlobSignature(obj: any): obj is Blob;
17
36
  export declare class PonyfillBlob implements Blob {
18
37
  private blobParts;
19
38
  type: string;
20
39
  private encoding;
21
40
  private _size;
22
41
  constructor(blobParts: BlobPart[], options?: BlobOptions);
23
- arrayBuffer(): Promise<Buffer>;
42
+ _buffer: Buffer | null;
43
+ buffer(): Promise<Buffer>;
44
+ arrayBuffer(): Promise<ArrayBuffer>;
45
+ _text: string | null;
24
46
  text(): Promise<string>;
25
47
  get size(): number;
26
48
  stream(): any;
@@ -36,7 +36,9 @@ export declare class PonyfillBody<TJSON = any> implements Body {
36
36
  formData(opts?: {
37
37
  formDataLimits: FormDataLimits;
38
38
  }): Promise<PonyfillFormData>;
39
- arrayBuffer(): Promise<Buffer>;
39
+ buffer(): Promise<Buffer>;
40
+ bytes(): Promise<Uint8Array>;
41
+ arrayBuffer(): Promise<ArrayBuffer>;
40
42
  _json: TJSON | null;
41
43
  json(): Promise<TJSON>;
42
44
  _text: string | null;
package/typings/Body.d.ts CHANGED
@@ -36,7 +36,9 @@ export declare class PonyfillBody<TJSON = any> implements Body {
36
36
  formData(opts?: {
37
37
  formDataLimits: FormDataLimits;
38
38
  }): Promise<PonyfillFormData>;
39
- arrayBuffer(): Promise<Buffer>;
39
+ buffer(): Promise<Buffer>;
40
+ bytes(): Promise<Uint8Array>;
41
+ arrayBuffer(): Promise<ArrayBuffer>;
40
42
  _json: TJSON | null;
41
43
  json(): Promise<TJSON>;
42
44
  _text: string | null;