可以使用 Uint8Array 实例调用缓冲区方法


🌐 Buffer methods are callable with Uint8Array instances

Buffer 原型上的所有方法都可以通过 Uint8Array 实例调用。

🌐 All methods on the Buffer prototype are callable with a Uint8Array instance.

const { toString, write } = Buffer.prototype;

const uint8array = new Uint8Array(5);

write.call(uint8array, 'hello', 0, 5, 'utf8'); // 5
// <Uint8Array 68 65 6c 6c 6f>

toString.call(uint8array, 'utf8'); // 'hello' 

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