Remove deprecated Buffer constructor usage

Fixes #1709
This commit is contained in:
Nick O'Leary 2018-10-24 13:45:34 +01:00
parent 7dcca2c907
commit e4d518749f
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
13 changed files with 26 additions and 26 deletions

View File

@ -34,7 +34,7 @@ var encryptionKey;
function decryptCredentials(key,credentials) {
var creds = credentials["$"];
var initVector = new Buffer(creds.substring(0, 32),'hex');
var initVector = Buffer.from(creds.substring(0, 32),'hex');
creds = creds.substring(32);
var decipher = crypto.createDecipheriv(encryptionAlgorithm, key, initVector);
var decrypted = decipher.update(creds, 'base64', 'utf8') + decipher.final('utf8');

View File

@ -70,7 +70,7 @@ function ensureBuffer(o) {
} else if (typeof o !== "string") {
o = ""+o;
}
return new Buffer(o);
return Buffer.from(o);
}
/**

View File

@ -506,7 +506,7 @@ describe('debug node', function() {
helper.load(debugNode, flow, function() {
var n1 = helper.getNode("n1");
websocket_test(function() {
n1.emit("input", {payload: new Buffer.from('HELLO', 'utf8')});
n1.emit("input", {payload: Buffer.from('HELLO', 'utf8')});
}, function(msg) {
JSON.parse(msg).should.eql([{
topic:"debug",

View File

@ -177,7 +177,7 @@ describe('exec node', function() {
function(arg1, arg2, arg3, arg4) {
//console.log(arg1);
// arg3(error,stdout,stderr);
arg3("error",new Buffer([0x01,0x02,0x03,0x88]),new Buffer([0x01,0x02,0x03,0x88]));
arg3("error",Buffer.from([0x01,0x02,0x03,0x88]),Buffer.from([0x01,0x02,0x03,0x88]));
});
helper.load(execNode, flow, function() {
var n1 = helper.getNode("n1");
@ -595,7 +595,7 @@ describe('exec node', function() {
}
catch(err) { done(err); }
});
n1.receive({payload:new Buffer([0x01,0x02,0x03,0x88])});
n1.receive({payload:Buffer.from([0x01,0x02,0x03,0x88])});
});
});

View File

@ -251,7 +251,7 @@ describe('function node', function() {
testNonObjectMessage('return "foo"', done)
});
it('should drop and log non-object message types - buffer', function(done) {
testNonObjectMessage('return new Buffer("hello")', done)
testNonObjectMessage('return Buffer.from("hello")', done)
});
it('should drop and log non-object message types - array', function(done) {
testNonObjectMessage('return [[[1,2,3]]]', done)

View File

@ -390,7 +390,7 @@ describe('HTTP Request Node', function() {
done(err);
}
});
n1.receive({payload:new Buffer('hello'), headers: { 'content-type': 'text/plain'}});
n1.receive({payload:Buffer.from('hello'), headers: { 'content-type': 'text/plain'}});
});
});

View File

@ -454,7 +454,7 @@ describe('websocket Node', function() {
});
getSocket("n1").on("open", function() {
helper.getNode("n3").send({
payload: new Buffer("hello")
payload: Buffer.from("hello")
});
});
});

View File

@ -236,7 +236,7 @@ describe('SPLIT node', function() {
done(err);
}
});
var b = new Buffer.from("12345678");
var b = Buffer.from("12345678");
sn1.receive({payload:b});
});
});
@ -260,8 +260,8 @@ describe('SPLIT node', function() {
done(err);
}
});
var b1 = new Buffer.from("123412");
var b2 = new Buffer.from("341234");
var b1 = Buffer.from("123412");
var b2 = Buffer.from("341234");
sn1.receive({payload:b1});
sn1.receive({payload:b2});
});
@ -364,7 +364,7 @@ describe('SPLIT node', function() {
if (msg.parts.index === 0) { msg.payload.length.should.equal(2); }
if (msg.parts.index === 1) { msg.payload.length.should.equal(1); done(); }
});
var b = new Buffer.from("123");
var b = Buffer.from("123");
sn1.receive({ payload: b });
});
});
@ -382,7 +382,7 @@ describe('SPLIT node', function() {
if (msg.parts.index === 0) { msg.payload.length.should.equal(2); }
if (msg.parts.index === 1) { msg.payload.length.should.equal(1); done(); }
});
var b = new Buffer.from("123");
var b = Buffer.from("123");
sn1.receive({ payload: b });
});
});

View File

@ -127,7 +127,7 @@ describe('JSON node', function() {
},150);
jn1.receive({payload:true});
jn1.receive({payload:1});
jn1.receive({payload:new Buffer("a")});
jn1.receive({payload:Buffer.from("a")});
});
});

View File

@ -169,7 +169,7 @@ describe('YAML node', function() {
},150);
yn1.receive({payload:true});
yn1.receive({payload:1});
yn1.receive({payload:new Buffer("a")});
yn1.receive({payload:Buffer.from("a")});
});
});

View File

@ -574,7 +574,7 @@ describe('file Nodes', function() {
}
});
for(var i = 0; i < file_count; i++) {
var data = new Buffer(len);
var data = Buffer.alloc?Buffer.alloc(len):new Buffer(len);
data.fill(i);
var name = path.join(tmp_path, String(i));
var msg = {payload:data, filename:name};
@ -617,7 +617,7 @@ describe('file Nodes', function() {
}
});
for(var i = 0; i < file_count; i++) {
var data = new Buffer(len);
var data = Buffer.alloc?Buffer.alloc(len):new Buffer(len);
data.fill(i);
var name = path.join(tmp_path, String(i));
var msg = {payload:data, filename:name};

View File

@ -84,7 +84,7 @@ describe("api/editor/ui", function() {
res.data += chunk;
});
res.on('end', function () {
callback(null, new Buffer(res.data, 'binary'));
callback(null, Buffer.from(res.data, 'binary'));
});
}
function compareBuffers(b1,b2) {

View File

@ -59,9 +59,9 @@ describe("@node-red/util/util", function() {
util.compareObjects({"b":1,"a":1},{"a":1,"b":1}).should.equal(true);
});
it('Buffer', function() {
util.compareObjects(new Buffer("hello"),new Buffer("hello")).should.equal(true);
util.compareObjects(new Buffer("hello"),new Buffer("hello ")).should.equal(false);
util.compareObjects(new Buffer("hello"),"hello").should.equal(false);
util.compareObjects(Buffer.from("hello"),Buffer.from("hello")).should.equal(true);
util.compareObjects(Buffer.from("hello"),Buffer.from("hello ")).should.equal(false);
util.compareObjects(Buffer.from("hello"),"hello").should.equal(false);
});
});
@ -71,7 +71,7 @@ describe("@node-red/util/util", function() {
util.ensureString('string').should.equal('string');
});
it('Buffer is converted', function() {
var s = util.ensureString(new Buffer('foo'));
var s = util.ensureString(Buffer.from('foo'));
s.should.equal('foo');
(typeof s).should.equal('string');
});
@ -89,12 +89,12 @@ describe("@node-red/util/util", function() {
describe('ensureBuffer', function() {
it('Buffers are preserved', function() {
var b = new Buffer('');
var b = Buffer.from('');
util.ensureBuffer(b).should.equal(b);
});
it('string is converted', function() {
var b = util.ensureBuffer('foo');
var expected = new Buffer('foo');
var expected = Buffer.from('foo');
for (var i = 0; i < expected.length; i++) {
b[i].should.equal(expected[i]);
}
@ -109,7 +109,7 @@ describe("@node-red/util/util", function() {
it('stringifies other things', function() {
var b = util.ensureBuffer(123);
Buffer.isBuffer(b).should.equal(true);
var expected = new Buffer('123');
var expected = Buffer.from('123');
for (var i = 0; i < expected.length; i++) {
b[i].should.equal(expected[i]);
}
@ -747,7 +747,7 @@ describe("@node-red/util/util", function() {
resultJson[2].data.should.eql('-Infinity');
});
it('constructor of Buffer in msg', function() {
var msg = { msg:{buffer:new Buffer([1,2,3,4])} };
var msg = { msg:{buffer:Buffer.from([1,2,3,4])} };
var result = util.encodeObject(msg,{maxLength:2});
result.format.should.eql("Object");
var resultJson = JSON.parse(result.msg);