Open generalmimon opened 2 years ago
is marked in VS Code with a deprecation warning:
The warning from VS Code isn't entirely accurate, though:
it thinks that the constructor we call is (str: string, encoding?: BufferEncoding)
, when we actually call these - new Buffer(array)
and new Buffer(buffer)
, which are clearly not the same:
new Buffer(array)
Stability: 0 - Deprecated: Use
Buffer.from(array)
instead.
array
<integer[]>
An array of bytes to copy from.Allocates a new
Buffer
using anarray
of octets.// Creates a new Buffer containing the UTF-8 bytes of the string 'buffer' const buf = new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
new Buffer(buffer)
Stability: 0 - Deprecated: Use
Buffer.from(buffer)
instead.
buffer
<Buffer>
|<Uint8Array>
An existing Buffer orUint8Array
from which to copy data.Copies the passed
buffer
data onto a newBuffer
instance.const buf1 = new Buffer('buffer'); const buf2 = new Buffer(buf1); buf1[0] = 0x61; console.log(buf1.toString()); // Prints: auffer console.log(buf2.toString()); // Prints: buffer
it isn't deprecated since Node.js 10, but even since Node.js 6:
▼ History
Version Changes v10.0.0 Calling this constructor emits a deprecation warning when run from code outside the node_modules directory. v7.2.1 Calling this constructor no longer emits a deprecation warning. v7.0.0 Calling this constructor emits a deprecation warning now. v6.0.0 Deprecated since: v6.0.0
The following line:
https://github.com/kaitai-io/kaitai_struct_javascript_runtime/blob/1ae3924e68a29ff43b32b30debfdadd3e320c8ec/KaitaiStream.js#L585
is marked in VS Code with a deprecation warning:
Related article in Node.js docs: https://nodejs.org/en/docs/guides/buffer-constructor-deprecation/