Skip to content

Commit

Permalink
Replace new Buffer with either Buffer.from or Buffer.alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
the1337guy authored and rwaldron committed Aug 24, 2018
1 parent f12ca34 commit 2bc9e5e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/firmata.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ var SYSEX_RESPONSE = {};

SYSEX_RESPONSE[QUERY_FIRMWARE] = function(board) {
var length = board.currentBuffer.length - 2;
var buffer = new Buffer(Math.round((length - 4) / 2));
var buffer = Buffer.alloc(Math.round((length - 4) / 2));
var byte = 0;
var offset = 0;

Expand Down Expand Up @@ -348,7 +348,7 @@ SYSEX_RESPONSE[ONEWIRE_READ_REPLY] = function(board) {
*/

SYSEX_RESPONSE[STRING_DATA] = function(board) {
var string = new Buffer(board.currentBuffer.slice(2, -1)).toString("utf8").replace(/\0/g, "");
var string = Buffer.from(board.currentBuffer.slice(2, -1)).toString("utf8").replace(/\0/g, "");
board.emit("string", string);
};

Expand Down Expand Up @@ -796,7 +796,7 @@ Board.prototype = Object.create(Emitter.prototype, {
*/
function writeToTransport(board, data) {
board.pending++;
board.transport.write(new Buffer(data), function() {
board.transport.write(Buffer.from(data), function() {
board.pending--;
});
}
Expand Down Expand Up @@ -1022,7 +1022,7 @@ Board.prototype.queryPinState = function(pin, callback) {
*/

Board.prototype.sendString = function(string) {
var bytes = new Buffer(string + "\0", "utf8");
var bytes = Buffer.from(string + "\0", "utf8");
var data = [];
data.push(START_SYSEX);
data.push(STRING_DATA);
Expand Down Expand Up @@ -1227,7 +1227,7 @@ Board.prototype.i2cWrite = function(address, registerOrData, inBytes) {
}
}

bytes = new Buffer([registerOrData].concat(inBytes));
bytes = Buffer.from([registerOrData].concat(inBytes));

for (var i = 0, length = bytes.length; i < length; i++) {
data.push(
Expand Down

0 comments on commit 2bc9e5e

Please sign in to comment.