Skip to content

Commit

Permalink
chore: completely remove .buffer() (#1485)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `body.buffer()` has been removed
  • Loading branch information
jimmywarting committed Jan 27, 2022
1 parent 8c1fe41 commit 1c775f1
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 40 deletions.
3 changes: 0 additions & 3 deletions @types/index.test-d.ts
Expand Up @@ -21,9 +21,6 @@ async function run() {
}
}

// Test Buffer
expectType<Buffer>(await getResponse.buffer());

// Test arrayBuffer
expectType<ArrayBuffer>(await getResponse.arrayBuffer());

Expand Down
11 changes: 0 additions & 11 deletions src/body.js
Expand Up @@ -158,19 +158,8 @@ export default class Body {
const buffer = await consumeBody(this);
return buffer.toString();
}

/**
* Decode response as buffer (non-spec api)
*
* @return Promise
*/
buffer() {
return consumeBody(this);
}
}

Body.prototype.buffer = deprecate(Body.prototype.buffer, 'Please use \'response.arrayBuffer()\' instead of \'response.buffer()\'', 'node-fetch#buffer');

// In browsers, all properties are enumerable.
Object.defineProperties(Body.prototype, {
body: {enumerable: true},
Expand Down
14 changes: 7 additions & 7 deletions test/main.js
Expand Up @@ -1857,7 +1857,7 @@ describe('node-fetch', () => {
res.end(crypto.randomBytes(firstPacketMaxSize + secondPacketSize));
});
return expect(
fetch(url).then(res => res.clone().buffer())
fetch(url).then(res => res.clone().arrayBuffer())
).to.timeout;
});

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

Expand All @@ -1886,7 +1886,7 @@ describe('node-fetch', () => {
res.end(crypto.randomBytes(firstPacketMaxSize + secondPacketSize - 1));
});
return expect(
fetch(url).then(res => res.clone().buffer())
fetch(url).then(res => res.clone().arrayBuffer())
).not.to.timeout;
});

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

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

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

it('should support arrayBuffer(), blob(), text(), json() and buffer() method in Body constructor', () => {
it('should support arrayBuffer(), blob(), text(), and json() method in Body constructor', () => {
const body = new Body('a=1');
expect(body).to.have.property('arrayBuffer');
expect(body).to.have.property('blob');
expect(body).to.have.property('text');
expect(body).to.have.property('json');
expect(body).to.have.property('buffer');
expect(body).to.not.have.property('buffer');
});

/* eslint-disable-next-line func-names */
Expand Down
12 changes: 0 additions & 12 deletions test/request.js
Expand Up @@ -189,18 +189,6 @@ describe('Request', () => {
});
});

it('should support buffer() method', () => {
const url = base;
const request = new Request(url, {
method: 'POST',
body: 'a=1'
});
expect(request.url).to.equal(url);
return request.buffer().then(result => {
expect(result.toString()).to.equal('a=1');
});
});

it('should support blob() method', async () => {
const url = base;
const request = new Request(url, {
Expand Down
7 changes: 0 additions & 7 deletions test/response.js
Expand Up @@ -91,13 +91,6 @@ describe('Response', () => {
});
});

it('should support buffer() method', () => {
const res = new Response('a=1');
return res.buffer().then(result => {
expect(result.toString()).to.equal('a=1');
});
});

it('should support blob() method', () => {
const res = new Response('a=1', {
method: 'POST',
Expand Down

0 comments on commit 1c775f1

Please sign in to comment.