Skip to content

Commit 6bb73c0

Browse files
aduh95RafaelGSS
authored andcommitted
doc: make MDN links to global classes more consistent in buffer.md
PR-URL: #56921 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent a893da9 commit 6bb73c0

File tree

1 file changed

+35
-42
lines changed

1 file changed

+35
-42
lines changed

doc/api/buffer.md

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
`Buffer` objects are used to represent a fixed-length sequence of bytes. Many
1010
Node.js APIs support `Buffer`s.
1111

12-
The `Buffer` class is a subclass of JavaScript's [`Uint8Array`][] class and
12+
The `Buffer` class is a subclass of JavaScript's {Uint8Array} class and
1313
extends it with methods that cover additional use cases. Node.js APIs accept
14-
plain [`Uint8Array`][]s wherever `Buffer`s are supported as well.
14+
plain {Uint8Array}s wherever `Buffer`s are supported as well.
1515

1616
While the `Buffer` class is available within the global scope, it is still
1717
recommended to explicitly reference it via an import or require statement.
@@ -242,10 +242,10 @@ changes:
242242
description: The `Buffer`s class now inherits from `Uint8Array`.
243243
-->
244244

245-
`Buffer` instances are also JavaScript [`Uint8Array`][] and [`TypedArray`][]
246-
instances. All [`TypedArray`][] methods are available on `Buffer`s. There are,
245+
`Buffer` instances are also JavaScript {Uint8Array} and {TypedArray}
246+
instances. All {TypedArray} methods are available on `Buffer`s. There are,
247247
however, subtle incompatibilities between the `Buffer` API and the
248-
[`TypedArray`][] API.
248+
{TypedArray} API.
249249

250250
In particular:
251251

@@ -258,9 +258,9 @@ In particular:
258258
* [`buf.toString()`][] is incompatible with its `TypedArray` equivalent.
259259
* A number of methods, e.g. [`buf.indexOf()`][], support additional arguments.
260260

261-
There are two ways to create new [`TypedArray`][] instances from a `Buffer`:
261+
There are two ways to create new {TypedArray} instances from a `Buffer`:
262262

263-
* Passing a `Buffer` to a [`TypedArray`][] constructor will copy the `Buffer`s
263+
* Passing a `Buffer` to a {TypedArray} constructor will copy the `Buffer`s
264264
contents, interpreted as an array of integers, and not as a byte sequence
265265
of the target type.
266266

@@ -286,8 +286,8 @@ console.log(uint32array);
286286
// Prints: Uint32Array(4) [ 1, 2, 3, 4 ]
287287
```
288288

289-
* Passing the `Buffer`s underlying [`ArrayBuffer`][] will create a
290-
[`TypedArray`][] that shares its memory with the `Buffer`.
289+
* Passing the `Buffer`s underlying {ArrayBuffer} will create a
290+
{TypedArray} that shares its memory with the `Buffer`.
291291

292292
```mjs
293293
import { Buffer } from 'node:buffer';
@@ -318,7 +318,7 @@ console.log(uint16array);
318318
```
319319

320320
It is possible to create a new `Buffer` that shares the same allocated
321-
memory as a [`TypedArray`][] instance by using the `TypedArray` object's
321+
memory as a {TypedArray} instance by using the `TypedArray` object's
322322
`.buffer` property in the same way. [`Buffer.from()`][`Buffer.from(arrayBuf)`]
323323
behaves like `new Uint8Array()` in this context.
324324

@@ -376,8 +376,8 @@ console.log(buf2);
376376
// Prints: <Buffer 88 13 70 17>
377377
```
378378

379-
When creating a `Buffer` using a [`TypedArray`][]'s `.buffer`, it is
380-
possible to use only a portion of the underlying [`ArrayBuffer`][] by passing in
379+
When creating a `Buffer` using a {TypedArray}'s `.buffer`, it is
380+
possible to use only a portion of the underlying {ArrayBuffer} by passing in
381381
`byteOffset` and `length` parameters.
382382

383383
```mjs
@@ -401,7 +401,7 @@ console.log(buf.length);
401401
```
402402

403403
The `Buffer.from()` and [`TypedArray.from()`][] have different signatures and
404-
implementations. Specifically, the [`TypedArray`][] variants accept a second
404+
implementations. Specifically, the {TypedArray} variants accept a second
405405
argument that is a mapping function that is invoked on every element of the
406406
typed array:
407407

@@ -967,9 +967,8 @@ console.log(`${str}: ${str.length} characters, ` +
967967
// Prints: ½ + ¼ = ¾: 9 characters, 12 bytes
968968
```
969969

970-
When `string` is a `Buffer`/[`DataView`][]/[`TypedArray`][]/[`ArrayBuffer`][]/
971-
[`SharedArrayBuffer`][], the byte length as reported by `.byteLength`
972-
is returned.
970+
When `string` is a {Buffer|DataView|TypedArray|ArrayBuffer|SharedArrayBuffer},
971+
the byte length as reported by `.byteLength` is returned.
973972

974973
### Static method: `Buffer.compare(buf1, buf2)`
975974

@@ -1024,7 +1023,7 @@ changes:
10241023
description: The elements of `list` can now be `Uint8Array`s.
10251024
-->
10261025

1027-
* `list` {Buffer\[] | Uint8Array\[]} List of `Buffer` or [`Uint8Array`][]
1026+
* `list` {Buffer\[] | Uint8Array\[]} List of `Buffer` or {Uint8Array}
10281027
instances to concatenate.
10291028
* `totalLength` {integer} Total length of the `Buffer` instances in `list`
10301029
when concatenated.
@@ -1158,18 +1157,18 @@ appropriate for `Buffer.from()` variants.
11581157
added: v5.10.0
11591158
-->
11601159

1161-
* `arrayBuffer` {ArrayBuffer|SharedArrayBuffer} An [`ArrayBuffer`][],
1162-
[`SharedArrayBuffer`][], for example the `.buffer` property of a
1163-
[`TypedArray`][].
1160+
* `arrayBuffer` {ArrayBuffer|SharedArrayBuffer} An {ArrayBuffer},
1161+
{SharedArrayBuffer}, for example the `.buffer` property of a
1162+
{TypedArray}.
11641163
* `byteOffset` {integer} Index of first byte to expose. **Default:** `0`.
11651164
* `length` {integer} Number of bytes to expose.
11661165
**Default:** `arrayBuffer.byteLength - byteOffset`.
11671166
* Returns: {Buffer}
11681167

1169-
This creates a view of the [`ArrayBuffer`][] without copying the underlying
1168+
This creates a view of the {ArrayBuffer} without copying the underlying
11701169
memory. For example, when passed a reference to the `.buffer` property of a
1171-
[`TypedArray`][] instance, the newly created `Buffer` will share the same
1172-
allocated memory as the [`TypedArray`][]'s underlying `ArrayBuffer`.
1170+
{TypedArray} instance, the newly created `Buffer` will share the same
1171+
allocated memory as the {TypedArray}'s underlying `ArrayBuffer`.
11731172

11741173
```mjs
11751174
import { Buffer } from 'node:buffer';
@@ -1236,8 +1235,8 @@ console.log(buf.length);
12361235
// Prints: 2
12371236
```
12381237

1239-
A `TypeError` will be thrown if `arrayBuffer` is not an [`ArrayBuffer`][] or a
1240-
[`SharedArrayBuffer`][] or another type appropriate for `Buffer.from()`
1238+
A `TypeError` will be thrown if `arrayBuffer` is not an {ArrayBuffer} or a
1239+
{SharedArrayBuffer} or another type appropriate for `Buffer.from()`
12411240
variants.
12421241

12431242
It is important to remember that a backing `ArrayBuffer` can cover a range
@@ -1275,7 +1274,7 @@ console.log(buf);
12751274
added: v5.10.0
12761275
-->
12771276

1278-
* `buffer` {Buffer|Uint8Array} An existing `Buffer` or [`Uint8Array`][] from
1277+
* `buffer` {Buffer|Uint8Array} An existing `Buffer` or {Uint8Array} from
12791278
which to copy data.
12801279
* Returns: {Buffer}
12811280

@@ -1635,7 +1634,7 @@ changes:
16351634
description: Additional parameters for specifying offsets are supported now.
16361635
-->
16371636

1638-
* `target` {Buffer|Uint8Array} A `Buffer` or [`Uint8Array`][] with which to
1637+
* `target` {Buffer|Uint8Array} A `Buffer` or {Uint8Array} with which to
16391638
compare `buf`.
16401639
* `targetStart` {integer} The offset within `target` at which to begin
16411640
comparison. **Default:** `0`.
@@ -1740,7 +1739,7 @@ console.log(buf1.compare(buf2, 5, 6, 5));
17401739
added: v0.1.90
17411740
-->
17421741

1743-
* `target` {Buffer|Uint8Array} A `Buffer` or [`Uint8Array`][] to copy into.
1742+
* `target` {Buffer|Uint8Array} A `Buffer` or {Uint8Array} to copy into.
17441743
* `targetStart` {integer} The offset within `target` at which to begin
17451744
writing. **Default:** `0`.
17461745
* `sourceStart` {integer} The offset within `buf` from which to begin copying.
@@ -1895,7 +1894,7 @@ changes:
18951894
description: The arguments can now be `Uint8Array`s.
18961895
-->
18971896

1898-
* `otherBuffer` {Buffer|Uint8Array} A `Buffer` or [`Uint8Array`][] with which to
1897+
* `otherBuffer` {Buffer|Uint8Array} A `Buffer` or {Uint8Array} with which to
18991898
compare `buf`.
19001899
* Returns: {boolean}
19011900

@@ -2140,7 +2139,7 @@ If `value` is:
21402139

21412140
* a string, `value` is interpreted according to the character encoding in
21422141
`encoding`.
2143-
* a `Buffer` or [`Uint8Array`][], `value` will be used in its entirety.
2142+
* a `Buffer` or {Uint8Array}, `value` will be used in its entirety.
21442143
To compare a partial `Buffer`, use [`buf.subarray`][].
21452144
* a number, `value` will be interpreted as an unsigned 8-bit integer
21462145
value between `0` and `255`.
@@ -5009,8 +5008,8 @@ changes:
50095008
> [`Buffer.from(arrayBuffer[, byteOffset[, length]])`][`Buffer.from(arrayBuf)`]
50105009
> instead.
50115010
5012-
* `arrayBuffer` {ArrayBuffer|SharedArrayBuffer} An [`ArrayBuffer`][],
5013-
[`SharedArrayBuffer`][] or the `.buffer` property of a [`TypedArray`][].
5011+
* `arrayBuffer` {ArrayBuffer|SharedArrayBuffer} An {ArrayBuffer},
5012+
{SharedArrayBuffer} or the `.buffer` property of a {TypedArray}.
50145013
* `byteOffset` {integer} Index of first byte to expose. **Default:** `0`.
50155014
* `length` {integer} Number of bytes to expose.
50165015
**Default:** `arrayBuffer.byteLength - byteOffset`.
@@ -5037,7 +5036,7 @@ changes:
50375036

50385037
> Stability: 0 - Deprecated: Use [`Buffer.from(buffer)`][] instead.
50395038
5040-
* `buffer` {Buffer|Uint8Array} An existing `Buffer` or [`Uint8Array`][] from
5039+
* `buffer` {Buffer|Uint8Array} An existing `Buffer` or {Uint8Array} from
50415040
which to copy data.
50425041

50435042
See [`Buffer.from(buffer)`][].
@@ -5110,7 +5109,7 @@ changes:
51105109

51115110
* Extends: {Blob}
51125111

5113-
A [`File`][] provides information about files.
5112+
A {File} provides information about files.
51145113

51155114
### `new buffer.File(sources, fileName[, options])`
51165115

@@ -5427,7 +5426,7 @@ differently based on what arguments are provided:
54275426
Buffer(num)` return a `Buffer` with initialized memory.
54285427
* Passing a string, array, or `Buffer` as the first argument copies the
54295428
passed object's data into the `Buffer`.
5430-
* Passing an [`ArrayBuffer`][] or a [`SharedArrayBuffer`][] returns a `Buffer`
5429+
* Passing an {ArrayBuffer} or a {SharedArrayBuffer} returns a `Buffer`
54315430
that shares allocated memory with the given array buffer.
54325431

54335432
Because the behavior of `new Buffer()` is different depending on the type of the
@@ -5461,7 +5460,7 @@ to one of these new APIs._
54615460
provided octets.
54625461
* [`Buffer.from(arrayBuffer[, byteOffset[, length]])`][`Buffer.from(arrayBuf)`]
54635462
returns a new `Buffer` that _shares the same allocated memory_ as the given
5464-
[`ArrayBuffer`][].
5463+
{ArrayBuffer}.
54655464
* [`Buffer.from(buffer)`][] returns a new `Buffer` that _contains a copy_ of the
54665465
contents of the given `Buffer`.
54675466
* [`Buffer.from(string[, encoding])`][`Buffer.from(string)`] returns a new
@@ -5523,7 +5522,6 @@ introducing security vulnerabilities into an application.
55235522
[UTF-16]: https://en.wikipedia.org/wiki/UTF-16
55245523
[UTF-8]: https://en.wikipedia.org/wiki/UTF-8
55255524
[WHATWG Encoding Standard]: https://encoding.spec.whatwg.org/
5526-
[`ArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
55275525
[`Blob`]: https://developer.mozilla.org/en-US/docs/Web/API/Blob
55285526
[`Buffer.alloc()`]: #static-method-bufferallocsize-fill-encoding
55295527
[`Buffer.allocUnsafe()`]: #static-method-bufferallocunsafesize
@@ -5535,21 +5533,16 @@ introducing security vulnerabilities into an application.
55355533
[`Buffer.from(buffer)`]: #static-method-bufferfrombuffer
55365534
[`Buffer.from(string)`]: #static-method-bufferfromstring-encoding
55375535
[`Buffer.poolSize`]: #class-property-bufferpoolsize
5538-
[`DataView`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
55395536
[`ERR_INVALID_BUFFER_SIZE`]: errors.md#err_invalid_buffer_size
55405537
[`ERR_OUT_OF_RANGE`]: errors.md#err_out_of_range
5541-
[`File`]: https://developer.mozilla.org/en-US/docs/Web/API/File
55425538
[`JSON.stringify()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
5543-
[`SharedArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer
55445539
[`String.prototype.indexOf()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf
55455540
[`String.prototype.lastIndexOf()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf
55465541
[`String.prototype.length`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length
55475542
[`TypedArray.from()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from
55485543
[`TypedArray.prototype.set()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/set
55495544
[`TypedArray.prototype.slice()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice
55505545
[`TypedArray.prototype.subarray()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
5551-
[`TypedArray`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
5552-
[`Uint8Array`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
55535546
[`buf.buffer`]: #bufbuffer
55545547
[`buf.compare()`]: #bufcomparetarget-targetstart-targetend-sourcestart-sourceend
55555548
[`buf.entries()`]: #bufentries

0 commit comments

Comments
 (0)