Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use safe-buffer #282

Merged
merged 2 commits into from
May 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/common-replacements.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports.objectKeysReplacement = [
module.exports.bufferShimFix = [
/^('use strict';)$/m,
`/*<replacement>*/
const bufferShim = require('buffer-shims');
const bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/`
]

Expand Down
20 changes: 6 additions & 14 deletions build/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,12 @@ const headRegexp = /(^module.exports = \w+;?)/m

`
]
, bufferShimFix = [
, safeBufferFix = [
/const Buffer = require\('buffer'\)\.Buffer;/,
`const Buffer = require('buffer').Buffer;
/*<replacement>*/
const bufferShim = require('buffer-shims');
`/*<replacement>*/
const Buffer = require('safe-buffer').Buffer
/*</replacement>*/`
]
, bufferStaticMethods = [
/Buffer\.((?:alloc)|(?:allocUnsafe)|(?:from))/g,
`bufferShim.$1`
]
, internalDirectory = [
/require\('internal\/streams\/BufferList'\)/,
'require(\'./internal/streams/BufferList\')'
Expand Down Expand Up @@ -238,8 +233,7 @@ module.exports['_stream_readable.js'] = [
, processNextTickImport
, processNextTickReplacement
, eventEmittterListenerCountReplacement
, bufferShimFix
, bufferStaticMethods
, safeBufferFix
, internalDirectory
]

Expand Down Expand Up @@ -270,14 +264,12 @@ module.exports['_stream_writable.js'] = [
, processNextTickReplacement
, internalUtilReplacement
, fixSyncWrite
, bufferShimFix
, bufferStaticMethods
, safeBufferFix
, fixInstanceCheck
, removeOnWriteBind
, removeCorkedFinishBind
, removeOnCorkedFinish
]
module.exports['internal/streams/BufferList.js'] = [
bufferShimFix
, bufferStaticMethods
safeBufferFix
]
7 changes: 3 additions & 4 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ var EElistenerCount = function (emitter, type) {
var Stream = require('./internal/streams/stream');
/*</replacement>*/

var Buffer = require('buffer').Buffer;
/*<replacement>*/
var bufferShim = require('buffer-shims');
var Buffer = require('safe-buffer').Buffer;
/*</replacement>*/

/*<replacement>*/
Expand Down Expand Up @@ -163,7 +162,7 @@ Readable.prototype.push = function (chunk, encoding) {
if (!state.objectMode && typeof chunk === 'string') {
encoding = encoding || state.defaultEncoding;
if (encoding !== state.encoding) {
chunk = bufferShim.from(chunk, encoding);
chunk = Buffer.from(chunk, encoding);
encoding = '';
}
}
Expand Down Expand Up @@ -873,7 +872,7 @@ function copyFromBufferString(n, list) {
// This function is designed to be inlinable, so please take care when making
// changes to the function body.
function copyFromBuffer(n, list) {
var ret = bufferShim.allocUnsafe(n);
var ret = Buffer.allocUnsafe(n);
var p = list.head;
var c = 1;
p.data.copy(ret);
Expand Down
5 changes: 2 additions & 3 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ var internalUtil = {
var Stream = require('./internal/streams/stream');
/*</replacement>*/

var Buffer = require('buffer').Buffer;
/*<replacement>*/
var bufferShim = require('buffer-shims');
var Buffer = require('safe-buffer').Buffer;
/*</replacement>*/

util.inherits(Writable, Stream);
Expand Down Expand Up @@ -293,7 +292,7 @@ Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {

function decodeChunk(state, chunk, encoding) {
if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
chunk = bufferShim.from(chunk, encoding);
chunk = Buffer.from(chunk, encoding);
}
return chunk;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/internal/streams/BufferList.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

var Buffer = require('buffer').Buffer;
/*<replacement>*/
var bufferShim = require('buffer-shims');

var Buffer = require('safe-buffer').Buffer;
/*</replacement>*/

module.exports = BufferList;
Expand Down Expand Up @@ -50,9 +50,9 @@ BufferList.prototype.join = function (s) {
};

BufferList.prototype.concat = function (n) {
if (this.length === 0) return bufferShim.alloc(0);
if (this.length === 0) return Buffer.alloc(0);
if (this.length === 1) return this.head.data;
var ret = bufferShim.allocUnsafe(n >>> 0);
var ret = Buffer.allocUnsafe(n >>> 0);
var p = this.head;
var i = 0;
while (p) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"description": "Streams3, a user-land copy of the stream library from Node.js",
"main": "readable.js",
"dependencies": {
"buffer-shims": "~1.0.0",
"core-util-is": "~1.0.0",
"isarray": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "~1.0.0",
"process-nextick-args": "~1.0.6",
"safe-buffer": "^5.0.1",
"string_decoder": "~1.0.0",
"util-deprecate": "~1.0.1"
},
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-big-packet.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
require('../common');
var assert = require('assert/');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-big-push.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
var common = require('../common');
var assert = require('assert/');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-buffer-list.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Flags: --expose_internals
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
require('../common');
var assert = require('assert/');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-decoder-objectmode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
require('../common');
var stream = require('../../');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-duplex.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
require('../common');
var assert = require('assert/');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-end-paused.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
var common = require('../common');
var assert = require('assert/');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-events-prepend.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
var common = require('../common');
var stream = require('../../');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-ispaused.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
require('../common');
var assert = require('assert/');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-pipe-after-end.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
var common = require('../common');
var assert = require('assert/');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
var common = require('../common');
var stream = require('../../');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
var common = require('../common');
var stream = require('../../');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-pipe-await-drain.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
var common = require('../common');
var stream = require('../../');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-pipe-cleanup-pause.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
var common = require('../common');
var stream = require('../../');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-pipe-cleanup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
// This test asserts that Stream.prototype.pipe does not leave listeners
// hanging on the source or dest.
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-pipe-error-handling.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
var common = require('../common');
var assert = require('assert/');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-pipe-event.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
require('../common');
var stream = require('../../');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-pipe-multiple-pipes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
var common = require('../common');
var stream = require('../../');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-pipe-unpipe-streams.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
var common = require('../common');
var assert = require('assert/');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-pipe-without-listenerCount.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
var common = require('../common');
var stream = require('../../');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-push-order.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
require('../common');
var Readable = require('../../').Readable;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-push-strings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
require('../common');
var assert = require('assert/');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
require('../common');
var assert = require('assert/');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-readable-emittedReadable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
var common = require('../common');
var assert = require('assert/');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-readable-event.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
var common = require('../common');
var assert = require('assert/');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-readable-flow-recursion.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
require('../common');
var assert = require('assert/');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-readable-invalid-chunk.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
require('../common');
var stream = require('../../');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-readable-needReadable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
var common = require('../common');
var assert = require('assert/');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-readable-reading-readingMore.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
var common = require('../common');
var assert = require('assert/');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-readable-resumeScheduled.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
var common = require('../common');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
require('../common');
var stream = require('../../');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-readableListening-state.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/

var common = require('../common');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
require('../common');
var assert = require('assert/');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-transform-flush-data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/

require('../common');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
var common = require('../common');
var assert = require('assert/');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-transform-split-objectmode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
require('../common');
var assert = require('assert/');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-unshift-empty-chunk.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
require('../common');
var assert = require('assert/');
Expand Down
Loading