Skip to content

Commit

Permalink
doc: fix errors in sample code comments
Browse files Browse the repository at this point in the history
The errors thrown have changed in a few places. Update the comments to
reflect the current errors.

The `noAssert` option has been removed but it is still shown in sample
code in a few places. Remove that sample code.

PR-URL: #19963
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Daniel Bevenius <[email protected]>
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
  • Loading branch information
Trott authored and jasnell committed Apr 16, 2018
1 parent 90fc496 commit cdc1171
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions doc/api/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -1525,10 +1525,7 @@ console.log(buf.readDoubleBE(0));
console.log(buf.readDoubleLE(0));
// Prints: 5.447603722011605e-270
console.log(buf.readDoubleLE(1));
// Throws an exception: RangeError: Index out of range
console.log(buf.readDoubleLE(1, true));
// Warning: reads passed end of buffer!
// This will result in a segmentation fault! Don't do this!
// Throws ERR_OUT_OF_RANGE
```

### buf.readFloatBE(offset)
Expand Down Expand Up @@ -1558,10 +1555,7 @@ console.log(buf.readFloatBE(0));
console.log(buf.readFloatLE(0));
// Prints: 1.539989614439558e-36
console.log(buf.readFloatLE(1));
// Throws an exception: RangeError: Index out of range
console.log(buf.readFloatLE(1, true));
// Warning: reads passed end of buffer!
// This will result in a segmentation fault! Don't do this!
// Throws ERR_OUT_OF_RANGE
```

### buf.readInt8(offset)
Expand Down Expand Up @@ -1590,7 +1584,7 @@ console.log(buf.readInt8(0));
console.log(buf.readInt8(1));
// Prints: 5
console.log(buf.readInt8(2));
// Throws an exception: RangeError: Index out of range
// Throws ERR_OUT_OF_RANGE
```

### buf.readInt16BE(offset)
Expand Down Expand Up @@ -1622,7 +1616,7 @@ console.log(buf.readInt16BE(0));
console.log(buf.readInt16LE(0));
// Prints: 1280
console.log(buf.readInt16LE(1));
// Throws an exception: RangeError: Index out of range
// Throws ERR_OUT_OF_RANGE
```

### buf.readInt32BE(offset)
Expand Down Expand Up @@ -1654,7 +1648,7 @@ console.log(buf.readInt32BE(0));
console.log(buf.readInt32LE(0));
// Prints: 83886080
console.log(buf.readInt32LE(1));
// Throws an exception: RangeError: Index out of range
// Throws ERR_OUT_OF_RANGE
```

### buf.readIntBE(offset, byteLength)
Expand Down Expand Up @@ -1686,9 +1680,9 @@ console.log(buf.readIntLE(0, 6).toString(16));
console.log(buf.readIntBE(0, 6).toString(16));
// Prints: 1234567890ab
console.log(buf.readIntBE(1, 6).toString(16));
// Throws ERR_INDEX_OUT_OF_RANGE:
// Throws ERR_INDEX_OUT_OF_RANGE
console.log(buf.readIntBE(1, 0).toString(16));
// Throws ERR_OUT_OF_RANGE:
// Throws ERR_OUT_OF_RANGE
```

### buf.readUInt8(offset)
Expand All @@ -1715,7 +1709,7 @@ console.log(buf.readUInt8(0));
console.log(buf.readUInt8(1));
// Prints: 254
console.log(buf.readUInt8(2));
// Throws an exception: RangeError: Index out of range
// Throws ERR_OUT_OF_RANGE
```

### buf.readUInt16BE(offset)
Expand Down Expand Up @@ -1749,7 +1743,7 @@ console.log(buf.readUInt16BE(1).toString(16));
console.log(buf.readUInt16LE(1).toString(16));
// Prints: 5634
console.log(buf.readUInt16LE(2).toString(16));
// Throws an exception: RangeError: Index out of range
// Throws ERR_OUT_OF_RANGE
```

### buf.readUInt32BE(offset)
Expand Down Expand Up @@ -1779,7 +1773,7 @@ console.log(buf.readUInt32BE(0).toString(16));
console.log(buf.readUInt32LE(0).toString(16));
// Prints: 78563412
console.log(buf.readUInt32LE(1).toString(16));
// Throws an exception: RangeError: Index out of range
// Throws ERR_OUT_OF_RANGE
```

### buf.readUIntBE(offset, byteLength)
Expand Down Expand Up @@ -1811,7 +1805,7 @@ console.log(buf.readUIntBE(0, 6).toString(16));
console.log(buf.readUIntLE(0, 6).toString(16));
// Prints: ab9078563412
console.log(buf.readUIntBE(1, 6).toString(16));
// Throws an exception: RangeError: Index out of range
// Throws ERR_OUT_OF_RANGE
```

### buf.slice([start[, end]])
Expand Down Expand Up @@ -1907,7 +1901,7 @@ console.log(buf1);
const buf2 = Buffer.from([0x1, 0x2, 0x3]);

buf2.swap16();
// Throws an exception: RangeError: Buffer size must be a multiple of 16-bits
// Throws ERR_INVALID_BUFFER_SIZE
```

### buf.swap32()
Expand All @@ -1934,7 +1928,7 @@ console.log(buf1);
const buf2 = Buffer.from([0x1, 0x2, 0x3]);

buf2.swap32();
// Throws an exception: RangeError: Buffer size must be a multiple of 32-bits
// Throws ERR_INVALID_BUFFER_SIZE
```

### buf.swap64()
Expand All @@ -1961,7 +1955,7 @@ console.log(buf1);
const buf2 = Buffer.from([0x1, 0x2, 0x3]);

buf2.swap64();
// Throws an exception: RangeError: Buffer size must be a multiple of 64-bits
// Throws ERR_INVALID_BUFFER_SIZE
```

Note that JavaScript cannot encode 64-bit integers. This method is intended
Expand Down

0 comments on commit cdc1171

Please sign in to comment.