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

Remove Buffer constructor usage (#409) #410

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ bleno.startAdvertisingIBeacon(uuid, major, minor, measuredPower[, callback(error
##### Start advertising with EIR data (__Linux only__)

```javascript
var scanData = new Buffer(...); // maximum 31 bytes
var advertisementData = new Buffer(...); // maximum 31 bytes
var scanData = Buffer.alloc(...); // maximum 31 bytes
var advertisementData = Buffer.alloc(...); // maximum 31 bytes

bleno.startAdvertisingWithEIRData(advertisementData[, scanData, callback(error)]);
```
Expand Down Expand Up @@ -227,7 +227,7 @@ Parameters to handler are

```javascript
var result = Characteristic.RESULT_SUCCESS;
var data = new Buffer( ... );
var data = Buffer.alloc( ... );

callback(result, data);
```
Expand Down
6 changes: 3 additions & 3 deletions examples/battery-service/battery-level-characteristic.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var BatteryLevelCharacteristic = function() {
}),
new Descriptor({
uuid: '2904',
value: new Buffer([0x04, 0x01, 0x27, 0xAD, 0x01, 0x00, 0x00 ]) // maybe 12 0xC unsigned 8 bit
value: Buffer.from([0x04, 0x01, 0x27, 0xAD, 0x01, 0x00, 0x00 ]) // maybe 12 0xC unsigned 8 bit
})
]
});
Expand All @@ -34,11 +34,11 @@ BatteryLevelCharacteristic.prototype.onReadRequest = function(offset, callback)
var percent = data.split('\t')[1].split(';')[0];
console.log(percent);
percent = parseInt(percent, 10);
callback(this.RESULT_SUCCESS, new Buffer([percent]));
callback(this.RESULT_SUCCESS, Buffer.from([percent]));
});
} else {
// return hardcoded value
callback(this.RESULT_SUCCESS, new Buffer([98]));
callback(this.RESULT_SUCCESS, Buffer.from([98]));
}
};

Expand Down
2 changes: 1 addition & 1 deletion examples/blink1/blink1-fade-rgb-characteristic.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Blink1FaceRGBCharacteristic.prototype.onWriteRequest = function(data, offset, wi

this.blink1.fadeToRGB(fadeMillis, r, g, b, function() {
if (this.updateValueCallback) {
this.updateValueCallback(new Buffer([r, g, b]));
this.updateValueCallback(Buffer.from([r, g, b]));
}
}.bind(this));

Expand Down
2 changes: 1 addition & 1 deletion examples/blink1/hardware-revision-characteristic.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ HardwareRevisionCharacteristic.prototype.onReadRequest = function(offset, callba
callback(this.RESULT_ATTR_NOT_LONG, null);
} else {
this.blink1.version(function(version) {
callback(this.RESULT_SUCCESS, new Buffer(version));
callback(this.RESULT_SUCCESS, Buffer.from(version));
}.bind(this));
}
};
Expand Down
2 changes: 1 addition & 1 deletion examples/blink1/serial-number-characteristic.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function SerialNumberCharacteristic(blink1) {
SerialNumberCharacteristic.super_.call(this, {
uuid: '2a25',
properties: ['read'],
value: new Buffer(blink1.serialNumber),
value: Buffer.from(blink1.serialNumber),
descriptors: [
new BlenoDescriptor({
uuid: '2901',
Expand Down
2 changes: 1 addition & 1 deletion examples/echo/characteristic.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var EchoCharacteristic = function() {
value: null
});

this._value = new Buffer(0);
this._value = Buffer.alloc(0);
this._updateValueCallback = null;
};

Expand Down
2 changes: 1 addition & 1 deletion examples/pizza/pizza-bake-characteristic.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ PizzaBakeCharacteristic.prototype.onWriteRequest = function(data, offset, withou
var self = this;
this.pizza.once('ready', function(result) {
if (self.updateValueCallback) {
var data = new Buffer(1);
var data = Buffer.alloc(1);
data.writeUInt8(result, 0);
self.updateValueCallback(data);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/pizza/pizza-crust-characteristic.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ PizzaCrustCharacteristic.prototype.onReadRequest = function(offset, callback) {
callback(this.RESULT_ATTR_NOT_LONG, null);
}
else {
var data = new Buffer(1);
var data = Buffer.alloc(1);
data.writeUInt8(this.pizza.crust, 0);
callback(this.RESULT_SUCCESS, data);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/pizza/pizza-toppings-characteristic.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ PizzaToppingsCharacteristic.prototype.onReadRequest = function(offset, callback)
callback(this.RESULT_ATTR_NOT_LONG, null);
}
else {
var data = new Buffer(2);
var data = Buffer.alloc(2);
data.writeUInt16BE(this.pizza.toppings, 0);
callback(this.RESULT_SUCCESS, data);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/bleno.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ Bleno.prototype.startAdvertisingIBeacon = function(uuid, major, minor, measuredP
}
} else {
var undashedUuid = UuidUtil.removeDashes(uuid);
var uuidData = new Buffer(undashedUuid, 'hex');
var uuidData = Buffer.from(undashedUuid, 'hex');
var uuidDataLength = uuidData.length;
var iBeaconData = new Buffer(uuidData.length + 5);
var iBeaconData = Buffer.alloc(uuidData.length + 5);

for (var i = 0; i < uuidDataLength; i++) {
iBeaconData[i] = uuidData[i];
Expand Down
2 changes: 1 addition & 1 deletion lib/descriptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var UuidUtil = require('./uuid-util');

function Descriptor(options) {
this.uuid = UuidUtil.removeDashes(options.uuid);
this.value = options.value || new Buffer(0);
this.value = options.value || Buffer.alloc(0);
}

Descriptor.prototype.toString = function() {
Expand Down
6 changes: 3 additions & 3 deletions lib/hci-socket/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function c1(k, r, pres, preq, iat, ia, rat, ra) {
var p2 = Buffer.concat([
ra,
ia,
new Buffer('00000000', 'hex')
Buffer.from('00000000', 'hex')
]);

var res = xor(r, p1);
Expand Down Expand Up @@ -47,7 +47,7 @@ function e(key, data) {
}

function xor(b1, b2) {
var result = new Buffer(b1.length);
var result = Buffer.alloc(b1.length);

for (var i = 0; i < b1.length; i++) {
result[i] = b1[i] ^ b2[i];
Expand All @@ -57,7 +57,7 @@ function xor(b1, b2) {
}

function swap(input) {
var output = new Buffer(input.length);
var output = Buffer.alloc(input.length);

for (var i = 0; i < output.length; i++) {
output[i] = input[input.length - i - 1];
Expand Down
16 changes: 8 additions & 8 deletions lib/hci-socket/gap.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Gap.prototype.startAdvertising = function(name, serviceUuids) {

if (serviceUuids && serviceUuids.length) {
for (i = 0; i < serviceUuids.length; i++) {
var serviceUuid = new Buffer(serviceUuids[i].match(/.{1,2}/g).reverse().join(''), 'hex');
var serviceUuid = Buffer.from(serviceUuids[i].match(/.{1,2}/g).reverse().join(''), 'hex');

if (serviceUuid.length === 2) {
serviceUuids16bit.push(serviceUuid);
Expand All @@ -59,8 +59,8 @@ Gap.prototype.startAdvertising = function(name, serviceUuids) {
advertisementDataLength += 2 + 16 * serviceUuids128bit.length;
}

var advertisementData = new Buffer(advertisementDataLength);
var scanData = new Buffer(scanDataLength);
var advertisementData = Buffer.alloc(advertisementDataLength);
var scanData = Buffer.alloc(scanDataLength);

// flags
advertisementData.writeUInt8(2, 0);
Expand Down Expand Up @@ -97,7 +97,7 @@ Gap.prototype.startAdvertising = function(name, serviceUuids) {

// name
if (name && name.length) {
var nameBuffer = new Buffer(name);
var nameBuffer = Buffer.from(name);

scanData.writeUInt8(1 + nameBuffer.length, 0);
scanData.writeUInt8(0x08, 1);
Expand All @@ -116,8 +116,8 @@ Gap.prototype.startAdvertisingIBeacon = function(data) {
var advertisementDataLength = 5 + manufacturerDataLength;
var scanDataLength = 0;

var advertisementData = new Buffer(advertisementDataLength);
var scanData = new Buffer(0);
var advertisementData = Buffer.alloc(advertisementDataLength);
var scanData = Buffer.alloc(0);

// flags
advertisementData.writeUInt8(2, 0);
Expand All @@ -136,8 +136,8 @@ Gap.prototype.startAdvertisingIBeacon = function(data) {
};

Gap.prototype.startAdvertisingWithEIRData = function(advertisementData, scanData) {
advertisementData = advertisementData || new Buffer(0);
scanData = scanData || new Buffer(0);
advertisementData = advertisementData || Buffer.alloc(0);
scanData = scanData || Buffer.alloc(0);

debug('startAdvertisingWithEIRData: advertisement data = ' + advertisementData.toString('hex') + ', scan data = ' + scanData.toString('hex'));

Expand Down
Loading