Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"new Buffer()" is deprecated since Node.js 6 #27

Open
generalmimon opened this issue Feb 9, 2022 · 1 comment · May be fixed by #26
Open

"new Buffer()" is deprecated since Node.js 6 #27

generalmimon opened this issue Feb 9, 2022 · 1 comment · May be fixed by #26
Labels

Comments

@generalmimon
Copy link
Member

The following line:

return new Buffer(arr).toString(encoding);

is marked in VS Code with a deprecation warning:

image

Related article in Node.js docs: https://nodejs.org/en/docs/guides/buffer-constructor-deprecation/

@generalmimon
Copy link
Member Author

generalmimon commented Feb 9, 2022

is marked in VS Code with a deprecation warning:

The warning from VS Code isn't entirely accurate, though:

  1. 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.

    Allocates a new Buffer using an array 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.

    Copies the passed buffer data onto a new Buffer 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
  2. 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

@generalmimon generalmimon changed the title "new Buffer()" is deprecated since Node.js 10 "new Buffer()" is deprecated since Node.js 6 Feb 9, 2022
Mingun added a commit to Mingun/kaitai_struct_javascript_runtime that referenced this issue Apr 23, 2022
Mingun added a commit to Mingun/kaitai_struct_javascript_runtime that referenced this issue Aug 11, 2022
Mingun added a commit to Mingun/kaitai_struct_javascript_runtime that referenced this issue Apr 5, 2024
Mingun added a commit to Mingun/kaitai_struct_javascript_runtime that referenced this issue Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant