Skip to main content
Buffer.swap32 - node__buffer.d.ts - Node documentation
method Buffer.swap32

Usage in Deno

```typescript import { type Buffer } from "node:node__buffer.d.ts"; ```
Buffer.swap32(): this
Interprets `buf` as an array of unsigned 32-bit integers and swaps the byte order _in-place_. Throws `ERR_INVALID_BUFFER_SIZE` if `buf.length` is not a multiple of 4. ```js import { Buffer } from 'node:buffer'; const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]); console.log(buf1); // Prints: buf1.swap32(); console.log(buf1); // Prints: const buf2 = Buffer.from([0x1, 0x2, 0x3]); buf2.swap32(); // Throws ERR_INVALID_BUFFER_SIZE. ```

Return Type

this
A reference to `buf`.