Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 332e384

Browse filesBrowse files
addaleaxBethGriggs
authored andcommitted
buffer: alias UInt ➡️ Uint in buffer methods
It’s *so* hard to remember that it’s `UintXArray` but not `(write|read)UintX`. Let’s fix that by just providing aliases. 😊 PR-URL: #34729 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 1a9496a commit 332e384
Copy full SHA for 332e384

File tree

Expand file treeCollapse file tree

3 files changed

+65
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+65
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/buffer.md‎

Copy file name to clipboardExpand all lines: doc/api/buffer.md
+42Lines changed: 42 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,9 @@ console.log(buf.readIntLE(0, 6).toString(16));
17091709
<!-- YAML
17101710
added: v0.5.0
17111711
changes:
1712+
- version: REPLACEME
1713+
pr-url: https://github.com/nodejs/node/pull/34729
1714+
description: This function is also available as `buf.readUint8()`.
17121715
- version: v10.0.0
17131716
pr-url: https://github.com/nodejs/node/pull/18395
17141717
description: Removed `noAssert` and no implicit coercion of the offset
@@ -1736,6 +1739,9 @@ console.log(buf.readUInt8(2));
17361739
<!-- YAML
17371740
added: v0.5.5
17381741
changes:
1742+
- version: REPLACEME
1743+
pr-url: https://github.com/nodejs/node/pull/34729
1744+
description: This function is also available as `buf.readUint16BE()`.
17391745
- version: v10.0.0
17401746
pr-url: https://github.com/nodejs/node/pull/18395
17411747
description: Removed `noAssert` and no implicit coercion of the offset
@@ -1762,6 +1768,9 @@ console.log(buf.readUInt16BE(1).toString(16));
17621768
<!-- YAML
17631769
added: v0.5.5
17641770
changes:
1771+
- version: REPLACEME
1772+
pr-url: https://github.com/nodejs/node/pull/34729
1773+
description: This function is also available as `buf.readUint16LE()`.
17651774
- version: v10.0.0
17661775
pr-url: https://github.com/nodejs/node/pull/18395
17671776
description: Removed `noAssert` and no implicit coercion of the offset
@@ -1790,6 +1799,9 @@ console.log(buf.readUInt16LE(2).toString(16));
17901799
<!-- YAML
17911800
added: v0.5.5
17921801
changes:
1802+
- version: REPLACEME
1803+
pr-url: https://github.com/nodejs/node/pull/34729
1804+
description: This function is also available as `buf.readUint32BE()`.
17931805
- version: v10.0.0
17941806
pr-url: https://github.com/nodejs/node/pull/18395
17951807
description: Removed `noAssert` and no implicit coercion of the offset
@@ -1814,6 +1826,9 @@ console.log(buf.readUInt32BE(0).toString(16));
18141826
<!-- YAML
18151827
added: v0.5.5
18161828
changes:
1829+
- version: REPLACEME
1830+
pr-url: https://github.com/nodejs/node/pull/34729
1831+
description: This function is also available as `buf.readUint32LE()`.
18171832
- version: v10.0.0
18181833
pr-url: https://github.com/nodejs/node/pull/18395
18191834
description: Removed `noAssert` and no implicit coercion of the offset
@@ -1840,6 +1855,9 @@ console.log(buf.readUInt32LE(1).toString(16));
18401855
<!-- YAML
18411856
added: v0.11.15
18421857
changes:
1858+
- version: REPLACEME
1859+
pr-url: https://github.com/nodejs/node/pull/34729
1860+
description: This function is also available as `buf.readUintBE()`.
18431861
- version: v10.0.0
18441862
pr-url: https://github.com/nodejs/node/pull/18395
18451863
description: Removed `noAssert` and no implicit coercion of the offset
@@ -1869,6 +1887,9 @@ console.log(buf.readUIntBE(1, 6).toString(16));
18691887
<!-- YAML
18701888
added: v0.11.15
18711889
changes:
1890+
- version: REPLACEME
1891+
pr-url: https://github.com/nodejs/node/pull/34729
1892+
description: This function is also available as `buf.readUintLE()`.
18721893
- version: v10.0.0
18731894
pr-url: https://github.com/nodejs/node/pull/18395
18741895
description: Removed `noAssert` and no implicit coercion of the offset
@@ -2651,6 +2672,9 @@ console.log(buf);
26512672
<!-- YAML
26522673
added: v0.5.0
26532674
changes:
2675+
- version: REPLACEME
2676+
pr-url: https://github.com/nodejs/node/pull/34729
2677+
description: This function is also available as `buf.writeUint8()`.
26542678
- version: v10.0.0
26552679
pr-url: https://github.com/nodejs/node/pull/18395
26562680
description: Removed `noAssert` and no implicit coercion of the offset
@@ -2682,6 +2706,9 @@ console.log(buf);
26822706
<!-- YAML
26832707
added: v0.5.5
26842708
changes:
2709+
- version: REPLACEME
2710+
pr-url: https://github.com/nodejs/node/pull/34729
2711+
description: This function is also available as `buf.writeUint16BE()`.
26852712
- version: v10.0.0
26862713
pr-url: https://github.com/nodejs/node/pull/18395
26872714
description: Removed `noAssert` and no implicit coercion of the offset
@@ -2711,6 +2738,9 @@ console.log(buf);
27112738
<!-- YAML
27122739
added: v0.5.5
27132740
changes:
2741+
- version: REPLACEME
2742+
pr-url: https://github.com/nodejs/node/pull/34729
2743+
description: This function is also available as `buf.writeUint16LE()`.
27142744
- version: v10.0.0
27152745
pr-url: https://github.com/nodejs/node/pull/18395
27162746
description: Removed `noAssert` and no implicit coercion of the offset
@@ -2740,6 +2770,9 @@ console.log(buf);
27402770
<!-- YAML
27412771
added: v0.5.5
27422772
changes:
2773+
- version: REPLACEME
2774+
pr-url: https://github.com/nodejs/node/pull/34729
2775+
description: This function is also available as `buf.writeUint32BE()`.
27432776
- version: v10.0.0
27442777
pr-url: https://github.com/nodejs/node/pull/18395
27452778
description: Removed `noAssert` and no implicit coercion of the offset
@@ -2768,6 +2801,9 @@ console.log(buf);
27682801
<!-- YAML
27692802
added: v0.5.5
27702803
changes:
2804+
- version: REPLACEME
2805+
pr-url: https://github.com/nodejs/node/pull/34729
2806+
description: This function is also available as `buf.writeUint32LE()`.
27712807
- version: v10.0.0
27722808
pr-url: https://github.com/nodejs/node/pull/18395
27732809
description: Removed `noAssert` and no implicit coercion of the offset
@@ -2796,6 +2832,9 @@ console.log(buf);
27962832
<!-- YAML
27972833
added: v0.5.5
27982834
changes:
2835+
- version: REPLACEME
2836+
pr-url: https://github.com/nodejs/node/pull/34729
2837+
description: This function is also available as `buf.writeUintBE()`.
27992838
- version: v10.0.0
28002839
pr-url: https://github.com/nodejs/node/pull/18395
28012840
description: Removed `noAssert` and no implicit coercion of the offset
@@ -2826,6 +2865,9 @@ console.log(buf);
28262865
<!-- YAML
28272866
added: v0.5.5
28282867
changes:
2868+
- version: REPLACEME
2869+
pr-url: https://github.com/nodejs/node/pull/34729
2870+
description: This function is also available as `buf.writeUintLE()`.
28292871
- version: v10.0.0
28302872
pr-url: https://github.com/nodejs/node/pull/18395
28312873
description: Removed `noAssert` and no implicit coercion of the offset
Collapse file

‎lib/internal/buffer.js‎

Copy file name to clipboardExpand all lines: lib/internal/buffer.js
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,13 @@ function addBufferPrototypeMethods(proto) {
965965
proto.readUIntBE = readUIntBE;
966966
proto.readUInt32BE = readUInt32BE;
967967
proto.readUInt16BE = readUInt16BE;
968+
proto.readUintLE = readUIntLE;
969+
proto.readUint32LE = readUInt32LE;
970+
proto.readUint16LE = readUInt16LE;
971+
proto.readUint8 = readUInt8;
972+
proto.readUintBE = readUIntBE;
973+
proto.readUint32BE = readUInt32BE;
974+
proto.readUint16BE = readUInt16BE;
968975
proto.readIntLE = readIntLE;
969976
proto.readInt32LE = readInt32LE;
970977
proto.readInt16LE = readInt16LE;
@@ -980,6 +987,13 @@ function addBufferPrototypeMethods(proto) {
980987
proto.writeUIntBE = writeUIntBE;
981988
proto.writeUInt32BE = writeUInt32BE;
982989
proto.writeUInt16BE = writeUInt16BE;
990+
proto.writeUintLE = writeUIntLE;
991+
proto.writeUint32LE = writeUInt32LE;
992+
proto.writeUint16LE = writeUInt16LE;
993+
proto.writeUint8 = writeUInt8;
994+
proto.writeUintBE = writeUIntBE;
995+
proto.writeUint32BE = writeUInt32BE;
996+
proto.writeUint16BE = writeUInt16BE;
983997
proto.writeIntLE = writeIntLE;
984998
proto.writeInt32LE = writeInt32LE;
985999
proto.writeInt16LE = writeInt16LE;
Collapse file

‎test/parallel/test-buffer-writeuint.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-buffer-writeuint.js
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,12 @@ const assert = require('assert');
220220
val *= 0x100;
221221
}
222222
}
223+
224+
for (const fn of [
225+
'UInt8', 'UInt16LE', 'UInt16BE', 'UInt32LE', 'UInt32BE', 'UIntLE', 'UIntBE'
226+
]) {
227+
const p = Buffer.prototype;
228+
const lowerFn = fn.replace(/UInt/, 'Uint');
229+
assert.strictEqual(p[`write${fn}`], p[`write${lowerFn}`]);
230+
assert.strictEqual(p[`read${fn}`], p[`read${lowerFn}`]);
231+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.