DEP0005: Buffer() 构造函数
类型: 运行时(支持 --pending-deprecation)
由于可能导致意外安全问题的 API 可用性问题,Buffer() 函数和 new Buffer() 构造函数已弃用。
作为替代方案,使用以下方法之一构造 Buffer 对象:
Buffer.alloc(size[, fill[, encoding]]): 使用已初始化的内存创建Buffer。Buffer.allocUnsafe(size): 使用未初始化的内存创建Buffer。Buffer.allocUnsafeSlow(size): 使用未初始化的内存创建Buffer。Buffer.from(array): 使用array的副本创建BufferBuffer.from(arrayBuffer[, byteOffset[, length]])- 创建封装给定arrayBuffer的Buffer。Buffer.from(buffer): 创建拷贝buffer的Buffer。Buffer.from(string[, encoding]): 创建拷贝string的Buffer。
没有 --pending-deprecation,运行时警告只会出现在不在 node_modules 中的代码。
这意味着在依赖项中使用 Buffer() 不会出现弃用警告。
对于 --pending-deprecation,无论在何处使用 Buffer(),都会产生运行时警告。
Type: Runtime (supports --pending-deprecation)
The Buffer() function and new Buffer() constructor are deprecated due to
API usability issues that can lead to accidental security issues.
As an alternative, use one of the following methods of constructing Buffer
objects:
Buffer.alloc(size[, fill[, encoding]]): Create aBufferwith initialized memory.Buffer.allocUnsafe(size): Create aBufferwith uninitialized memory.Buffer.allocUnsafeSlow(size): Create aBufferwith uninitialized memory.Buffer.from(array): Create aBufferwith a copy ofarrayBuffer.from(arrayBuffer[, byteOffset[, length]])- Create aBufferthat wraps the givenarrayBuffer.Buffer.from(buffer): Create aBufferthat copiesbuffer.Buffer.from(string[, encoding]): Create aBufferthat copiesstring.
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.