Skip to content

Commit 576ce9d

Browse files
authored
Merge pull request #218 from hapijs/buffer
Remove new Buffer usage
2 parents 7d18304 + 57bbbc0 commit 576ce9d

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const wreckWithTimeout = wreck.defaults({
5757
// all attributes are optional
5858
const options = {
5959
baseUrl: 'https://www.example.com',
60-
payload: readableStream || 'foo=bar' || new Buffer('foo=bar'),
60+
payload: readableStream || 'foo=bar' || Buffer.from('foo=bar'),
6161
headers: { /* http headers */ },
6262
redirects: 3,
6363
beforeRedirect: (redirectMethod, statusCode, location, resHeaders, redirectOptions, next) => next(),
@@ -272,7 +272,7 @@ for the provided payload and encoding.
272272
<!-- eslint-disable no-unused-vars -->
273273
<!-- eslint-disable no-undef -->
274274
```javascript
275-
const stream = Wreck.toReadableStream(new Buffer('Hello', 'ascii'), 'ascii');
275+
const stream = Wreck.toReadableStream(Buffer.from('Hello', 'ascii'), 'ascii');
276276
const read = stream.read();
277277
// read -> 'Hello'
278278
```

lib/payload.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = internals.Payload = function (payload, encoding) {
2020
for (let i = 0; i < data.length; ++i) {
2121
const chunk = data[i];
2222
size = size + chunk.length;
23-
data[i] = Buffer.isBuffer(chunk) ? chunk : new Buffer(chunk);
23+
data[i] = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
2424
}
2525

2626
this._data = Buffer.concat(data, size);

lib/recorder.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ internals.Recorder.prototype._write = function (chunk, encoding, next) {
4040

4141
internals.Recorder.prototype.collect = function () {
4242

43-
const buffer = (this.buffers.length === 0 ? new Buffer(0) : (this.buffers.length === 1 ? this.buffers[0] : Buffer.concat(this.buffers, this.length)));
43+
const buffer = (this.buffers.length === 0 ? Buffer.alloc(0) : (this.buffers.length === 1 ? this.buffers[0] : Buffer.concat(this.buffers, this.length)));
4444
return buffer;
4545
};

test/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ describe('request()', () => {
762762
it('requests payload in buffer', async () => {
763763

764764
const server = await internals.server('echo');
765-
const buf = new Buffer(internals.payload, 'ascii');
765+
const buf = Buffer.from(internals.payload, 'ascii');
766766

767767
const res = await Wreck.request('post', 'http://localhost:' + server.address().port, { payload: buf });
768768
const body = await Wreck.read(res);

0 commit comments

Comments
 (0)