Skip to content

Commit 1c775f1

Browse files
authored
chore: completely remove .buffer() (node-fetch#1485)
BREAKING CHANGE: `body.buffer()` has been removed
1 parent 8c1fe41 commit 1c775f1

File tree

5 files changed

+7
-40
lines changed

5 files changed

+7
-40
lines changed

@types/index.test-d.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ async function run() {
2121
}
2222
}
2323

24-
// Test Buffer
25-
expectType<Buffer>(await getResponse.buffer());
26-
2724
// Test arrayBuffer
2825
expectType<ArrayBuffer>(await getResponse.arrayBuffer());
2926

src/body.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,8 @@ export default class Body {
158158
const buffer = await consumeBody(this);
159159
return buffer.toString();
160160
}
161-
162-
/**
163-
* Decode response as buffer (non-spec api)
164-
*
165-
* @return Promise
166-
*/
167-
buffer() {
168-
return consumeBody(this);
169-
}
170161
}
171162

172-
Body.prototype.buffer = deprecate(Body.prototype.buffer, 'Please use \'response.arrayBuffer()\' instead of \'response.buffer()\'', 'node-fetch#buffer');
173-
174163
// In browsers, all properties are enumerable.
175164
Object.defineProperties(Body.prototype, {
176165
body: {enumerable: true},

test/main.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,7 @@ describe('node-fetch', () => {
18571857
res.end(crypto.randomBytes(firstPacketMaxSize + secondPacketSize));
18581858
});
18591859
return expect(
1860-
fetch(url).then(res => res.clone().buffer())
1860+
fetch(url).then(res => res.clone().arrayBuffer())
18611861
).to.timeout;
18621862
});
18631863

@@ -1869,7 +1869,7 @@ describe('node-fetch', () => {
18691869
res.end(crypto.randomBytes(firstPacketMaxSize + secondPacketSize));
18701870
});
18711871
return expect(
1872-
fetch(url, {highWaterMark: 10}).then(res => res.clone().buffer())
1872+
fetch(url, {highWaterMark: 10}).then(res => res.clone().arrayBuffer())
18731873
).to.timeout;
18741874
});
18751875

@@ -1886,7 +1886,7 @@ describe('node-fetch', () => {
18861886
res.end(crypto.randomBytes(firstPacketMaxSize + secondPacketSize - 1));
18871887
});
18881888
return expect(
1889-
fetch(url).then(res => res.clone().buffer())
1889+
fetch(url).then(res => res.clone().arrayBuffer())
18901890
).not.to.timeout;
18911891
});
18921892

@@ -1903,7 +1903,7 @@ describe('node-fetch', () => {
19031903
res.end(crypto.randomBytes(firstPacketMaxSize + secondPacketSize - 1));
19041904
});
19051905
return expect(
1906-
fetch(url, {highWaterMark: 10}).then(res => res.clone().buffer())
1906+
fetch(url, {highWaterMark: 10}).then(res => res.clone().arrayBuffer())
19071907
).not.to.timeout;
19081908
});
19091909

@@ -1918,7 +1918,7 @@ describe('node-fetch', () => {
19181918
res.end(crypto.randomBytes((2 * 512 * 1024) - 1));
19191919
});
19201920
return expect(
1921-
fetch(url, {highWaterMark: 512 * 1024}).then(res => res.clone().buffer())
1921+
fetch(url, {highWaterMark: 512 * 1024}).then(res => res.clone().arrayBuffer())
19221922
).not.to.timeout;
19231923
});
19241924

@@ -2079,13 +2079,13 @@ describe('node-fetch', () => {
20792079
expect(headers.a).to.equal('2');
20802080
});
20812081

2082-
it('should support arrayBuffer(), blob(), text(), json() and buffer() method in Body constructor', () => {
2082+
it('should support arrayBuffer(), blob(), text(), and json() method in Body constructor', () => {
20832083
const body = new Body('a=1');
20842084
expect(body).to.have.property('arrayBuffer');
20852085
expect(body).to.have.property('blob');
20862086
expect(body).to.have.property('text');
20872087
expect(body).to.have.property('json');
2088-
expect(body).to.have.property('buffer');
2088+
expect(body).to.not.have.property('buffer');
20892089
});
20902090

20912091
/* eslint-disable-next-line func-names */

test/request.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,18 +189,6 @@ describe('Request', () => {
189189
});
190190
});
191191

192-
it('should support buffer() method', () => {
193-
const url = base;
194-
const request = new Request(url, {
195-
method: 'POST',
196-
body: 'a=1'
197-
});
198-
expect(request.url).to.equal(url);
199-
return request.buffer().then(result => {
200-
expect(result.toString()).to.equal('a=1');
201-
});
202-
});
203-
204192
it('should support blob() method', async () => {
205193
const url = base;
206194
const request = new Request(url, {

test/response.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,6 @@ describe('Response', () => {
9191
});
9292
});
9393

94-
it('should support buffer() method', () => {
95-
const res = new Response('a=1');
96-
return res.buffer().then(result => {
97-
expect(result.toString()).to.equal('a=1');
98-
});
99-
});
100-
10194
it('should support blob() method', () => {
10295
const res = new Response('a=1', {
10396
method: 'POST',

0 commit comments

Comments
 (0)