Skip to content

Commit bfb33fe

Browse files
leahjessierzr
authored andcommitted
Porting to Buffer.from()/Buffer.alloc()
1 parent dbcad4e commit bfb33fe

21 files changed

+1657
-120
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ bleno.startAdvertisingIBeacon(uuid, major, minor, measuredPower[, callback(error
134134
##### Start advertising with EIR data (__Linux only__)
135135

136136
```javascript
137-
var scanData = new Buffer(...); // maximum 31 bytes
138-
var advertisementData = new Buffer(...); // maximum 31 bytes
137+
var scanData = Buffer.alloc(...); // maximum 31 bytes
138+
var advertisementData = Buffer.alloc(...); // maximum 31 bytes
139139

140140
bleno.startAdvertisingWithEIRData(advertisementData[, scanData, callback(error)]);
141141
```
@@ -227,7 +227,7 @@ Parameters to handler are
227227

228228
```javascript
229229
var result = Characteristic.RESULT_SUCCESS;
230-
var data = new Buffer( ... );
230+
var data = Buffer.alloc( ... );
231231

232232
callback(result, data);
233233
```

examples/battery-service/battery-level-characteristic.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var BatteryLevelCharacteristic = function() {
1818
}),
1919
new Descriptor({
2020
uuid: '2904',
21-
value: new Buffer([0x04, 0x01, 0x27, 0xAD, 0x01, 0x00, 0x00 ]) // maybe 12 0xC unsigned 8 bit
21+
value: Buffer.from([0x04, 0x01, 0x27, 0xAD, 0x01, 0x00, 0x00 ]) // maybe 12 0xC unsigned 8 bit
2222
})
2323
]
2424
});
@@ -34,11 +34,11 @@ BatteryLevelCharacteristic.prototype.onReadRequest = function(offset, callback)
3434
var percent = data.split('\t')[1].split(';')[0];
3535
console.log(percent);
3636
percent = parseInt(percent, 10);
37-
callback(this.RESULT_SUCCESS, new Buffer([percent]));
37+
callback(this.RESULT_SUCCESS, Buffer.from([percent]));
3838
});
3939
} else {
4040
// return hardcoded value
41-
callback(this.RESULT_SUCCESS, new Buffer([98]));
41+
callback(this.RESULT_SUCCESS, Buffer.from([98]));
4242
}
4343
};
4444

0 commit comments

Comments
 (0)