DEP0005:Buffer() 构造函数
【DEP0005: Buffer() constructor】
类型:运行时(支持 --pending-deprecation)
【Type: Runtime (supports --pending-deprecation)】
Buffer() 函数和 new Buffer() 构造函数由于 API 可用性问题而被弃用,这些问题可能导致意外的安全问题。
【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.allocUnsafe(size):创建一个带有未初始化内存的Buffer。Buffer.allocUnsafeSlow(size):创建一个带有未初始化内存的Buffer。Buffer.from(array):使用array创建一个带有副本的BufferBuffer.from(arrayBuffer[, byteOffset[, length]])- 创建一个Buffer,该Buffer封装给定的arrayBuffer。Buffer.from(buffer):创建一个复制buffer的Buffer。Buffer.from(string[, encoding]):创建一个复制string的Buffer。
如果没有使用 --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.】