Skip to content
This repository has been archived by the owner on Apr 5, 2018. It is now read-only.

Commit

Permalink
Merge pull request #3 from calvinmetcalf/safe-buffer
Browse files Browse the repository at this point in the history
safe-buffer
  • Loading branch information
mcollina authored May 19, 2017
2 parents 0cd0754 + bee3d7b commit c9629de
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 17 deletions.
10 changes: 1 addition & 9 deletions build/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,7 @@ module.exports['string_decoder.js'] = [

, [
/const Buffer = require\('buffer'\).Buffer;/
, 'var Buffer = require(\'buffer\').Buffer;\n' +
'var bufferShim = require(\'buffer-shims\');'
]

// allocUnsafe

, [
/Buffer\.((?:alloc)|(?:allocUnsafe)|(?:from))/g,
'bufferShim.$1'
, 'var Buffer = require(\'safe-buffer\').Buffer;\n'
]

// add Buffer.isEncoding where missing
Expand Down
3 changes: 1 addition & 2 deletions build/test-replacements.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports.all = [

, [
/^('use strict';)$/m,
'$1\nconst bufferShim = require(\'buffer-shims\');'
'$1\nconst bufferShim = require(\'safe-buffer\').Buffer;'
]

]
Expand Down Expand Up @@ -60,4 +60,3 @@ module.exports['test-string-decoder.js'] = [
, ''
]
]

5 changes: 2 additions & 3 deletions lib/string_decoder.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

var Buffer = require('buffer').Buffer;
var bufferShim = require('buffer-shims');
var Buffer = require('safe-buffer').Buffer;

var isEncoding = Buffer.isEncoding || function (encoding) {
encoding = '' + encoding;
Expand Down Expand Up @@ -78,7 +77,7 @@ function StringDecoder(encoding) {
}
this.lastNeed = 0;
this.lastTotal = 0;
this.lastChar = bufferShim.allocUnsafe(nb);
this.lastChar = Buffer.allocUnsafe(nb);
}

StringDecoder.prototype.write = function (buf) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "The string_decoder module from Node core",
"main": "lib/string_decoder.js",
"dependencies": {
"buffer-shims": "~1.0.0"
"safe-buffer": "^5.0.1"
},
"devDependencies": {
"babel-polyfill": "^6.23.0",
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-string-decoder-end.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
// verify that the string decoder works getting 1 byte at a time,
// the whole buffer at once, and that both match the .toString(enc)
// result of the entire buffer.
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-string-decoder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var bufferShim = require('buffer-shims');
var bufferShim = require('safe-buffer').Buffer;
require('../common');
var assert = require('assert');
var inspect = require('util').inspect;
Expand Down

0 comments on commit c9629de

Please sign in to comment.