buf.length


返回 buf 中的字节数。

import { Buffer } from 'node:buffer';

// 创建 `Buffer` 并使用 UTF-8 向其写入一个较短的字符串。

const buf = Buffer.alloc(1234);

console.log(buf.length);
// 打印: 1234

buf.write('some string', 0, 'utf8');

console.log(buf.length);
// 打印: 1234const { Buffer } = require('node:buffer');

// 创建 `Buffer` 并使用 UTF-8 向其写入一个较短的字符串。

const buf = Buffer.alloc(1234);

console.log(buf.length);
// 打印: 1234

buf.write('some string', 0, 'utf8');

console.log(buf.length);
// 打印: 1234

Returns the number of bytes in buf.

import { Buffer } from 'node:buffer';

// Create a `Buffer` and write a shorter string to it using UTF-8.

const buf = Buffer.alloc(1234);

console.log(buf.length);
// Prints: 1234

buf.write('some string', 0, 'utf8');

console.log(buf.length);
// Prints: 1234const { Buffer } = require('node:buffer');

// Create a `Buffer` and write a shorter string to it using UTF-8.

const buf = Buffer.alloc(1234);

console.log(buf.length);
// Prints: 1234

buf.write('some string', 0, 'utf8');

console.log(buf.length);
// Prints: 1234