-
Notifications
You must be signed in to change notification settings - Fork 296
Closed
Description
- Node.js Version: 15.0.0
- OS: macOS 10.15.7
- Scope (install, code, runtime, meta, other?): runtime
- Module (and version) (if relevant): buffer, crypto
In the new Node.js 15.0.0 the use of Buffer.allocUnsafe
gives a zero-filled Buffer, like with Buffer.alloc
.
This kind of Buffer can be filled will buf.fill
or manipulated by buf.writeUInt8
. But it cannot be filled with crypto.randomFillSync(buf)
. If this is tried, the Buffer keeps its previously content.
By using asynchronous randomFill
or still the Sync-one but with Buffer.alloc
this problem does not appear.
const crypto = require("crypto");
const buf = Buffer.allocUnsafe(4);
console.log(buf); //--> <Buffer 00 00 00 00>
buf.fill(255);
console.log(buf); //--> <Buffer ff ff ff ff>
crypto.randomFillSync(buf);
console.log(buf); //--> <Buffer ff ff ff ff>
Metadata
Metadata
Assignees
Labels
No labels