DEP0005:Buffer() 构造函数
¥DEP0005: Buffer() constructor
类型:应用(仅限非 node_modules 代码)
¥Type: Application (non-node_modules code only)
由于可能导致意外安全问题的 API 可用性问题,Buffer() 函数和 new Buffer() 构造函数已弃用。
¥The Buffer() function and new Buffer() constructor are deprecated due to
API usability issues that can lead to accidental security issues.
作为替代方案,使用以下方法之一构造 Buffer 对象:
¥As an alternative, use one of the following methods of constructing Buffer
objects:
-
Buffer.alloc(size[, fill[, encoding]]):创建一个带有初始化内存的Buffer。¥
Buffer.alloc(size[, fill[, encoding]]): Create aBufferwith initialized memory. -
Buffer.allocUnsafe(size):使用未初始化的内存创建Buffer。¥
Buffer.allocUnsafe(size): Create aBufferwith uninitialized memory. -
Buffer.allocUnsafeSlow(size):使用未初始化的内存创建Buffer。¥
Buffer.allocUnsafeSlow(size): Create aBufferwith uninitialized memory. -
Buffer.from(array):使用array的副本创建Buffer¥
Buffer.from(array): Create aBufferwith a copy ofarray -
Buffer.from(arrayBuffer[, byteOffset[, length]])- 创建一个封装给定arrayBuffer的Buffer。¥
Buffer.from(arrayBuffer[, byteOffset[, length]])- Create aBufferthat wraps the givenarrayBuffer. -
Buffer.from(buffer):创建一个复制buffer的Buffer。¥
Buffer.from(buffer): Create aBufferthat copiesbuffer. -
Buffer.from(string[, encoding]):创建一个复制string的Buffer。¥
Buffer.from(string[, encoding]): Create aBufferthat copiesstring.
如果没有 --pending-deprecation,运行时警告只会出现在不在 node_modules 中的代码中。这意味着在依赖中使用 Buffer() 不会有弃用警告。对于 --pending-deprecation,无论在何处使用 Buffer(),都会产生运行时警告。
¥Without --pending-deprecation, runtime warnings occur only for code not in
node_modules. This means there will not be deprecation warnings for
Buffer() usage in dependencies. With --pending-deprecation, a runtime
warning results no matter where the Buffer() usage occurs.