温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/node/buffer/Buffer/swap16
点击访问原文链接

Buffer.swap16 method | Node.js buffer module | Bun

Buffer.swap16 method | Node.js buffer module | BunBuildDocsReferenceGuidesBlogDiscord/node:buffer/Buffer/swap16Mswap16

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/node:buffer/Buffer/swap16Mswap16

method

buffer.Buffer.swap16 buf1.swap16(); console.log(buf1); // Prints: const buf2 = Buffer.from([0x1, 0x2, 0x3]); buf2.swap16(); // Throws ERR_INVALID_BUFFER_SIZE. ``` One convenient use of `buf.swap16()` is to perform a fast in-place conversion between UTF-16 little-endian and UTF-16 big-endian: ```js import { Buffer } from 'node:buffer'; const buf = Buffer.from('This is little-endian UTF-16', 'utf16le'); buf.swap16(); // Convert to big-endian UTF-16 text. ```" data-algolia-static="false" data-algolia-merged="false" data-type="Method">swap16(): this;Interprets buf as an array of unsigned 16-bit integers and swaps the byte order in-place. Throws ERR_INVALID_BUFFER_SIZE if buf.length is not a multiple of 2.

import { Buffer } from 'node:buffer'; const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]); console.log(buf1); // Prints: buf1.swap16(); console.log(buf1); // Prints: const buf2 = Buffer.from([0x1, 0x2, 0x3]); buf2.swap16(); // Throws ERR_INVALID_BUFFER_SIZE. One convenient use of buf.swap16() is to perform a fast in-place conversion between UTF-16 little-endian and UTF-16 big-endian:

import { Buffer } from 'node:buffer'; const buf = Buffer.from('This is little-endian UTF-16', 'utf16le'); buf.swap16(); // Convert to big-endian UTF-16 text. @returnsA reference to buf.

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicenseBaked with ❤️ in San Francisco

We're hiring →

智能索引记录