assert.throws(function() {
  var buf = new Buffer(8);
  buf.writeFloatLE(0.0, -1);
}, /offset is not uint/);
assert.throws(function() {
  var buf = new Buffer(8);
  buf.writeFloatLE(0.0, 0xfffffff);
}, /Trying to access beyond buffer length/);
Example #3
0
assert.throws(function() {
  var buf = new Buffer(8);
  buf.writeFloatLE(0, 5);
}, RangeError);
Example #4
0
for (let i = 0; i < LENGTH; i++) {
  assert.equal(ui[i], 0xC);
  ui[i] = 0xF;
  assert.equal(buf[i], 0xF);
}

buf.writeUInt32LE(0xF00, 0);
buf.writeUInt32BE(0xB47, 4);
buf.writeDoubleLE(3.1415, 8);

assert.equal(dv.getUint32(0, true), 0xF00);
assert.equal(dv.getUint32(4), 0xB47);
assert.equal(dv.getFloat64(8, true), 3.1415);


// Now test protecting users from doing stupid things

assert.throws(function() {
  function AB() { }
  AB.__proto__ = ArrayBuffer;
  AB.prototype.__proto__ = ArrayBuffer.prototype;
  new Buffer(new AB());
}, TypeError);

// write{Double,Float}{LE,BE} with noAssert should not crash, cf. #3766
var b = new Buffer(1);
b.writeFloatLE(11.11, 0, true);
b.writeFloatBE(11.11, 0, true);
b.writeDoubleLE(11.11, 0, true);
b.writeDoubleBE(11.11, 0, true);
Example #5
0
NetWriter.prototype.writeFloatLE = function (value) {
    var buffer = new Buffer(4);
    buffer.writeFloatLE(value, 0, true);
    this.content.push(buffer);
    this.size += 4;
};