diff --git a/lib/readline-sync.js b/lib/readline-sync.js index fd85860..4b96b8c 100644 --- a/lib/readline-sync.js +++ b/lib/readline-sync.js @@ -364,13 +364,9 @@ function _readlineSync(options) { return; } - // https://github.com/nodejs/node/issues/4660 - // https://github.com/nodejs/node/pull/4682 - if (Buffer.alloc) { - buffer = Buffer.alloc((reqSize = options.keyIn ? 1 : options.bufferSize)); - } else { - buffer = new Buffer((reqSize = options.keyIn ? 1 : options.bufferSize)); - } + reqSize = options.keyIn ? 1 : options.bufferSize; + // Check `allocUnsafe` to make sure of the new API. + buffer = Buffer.allocUnsafe && Buffer.alloc ? Buffer.alloc(reqSize) : new Buffer(reqSize); if (options.keyIn && options.limit) { limit = new RegExp('[^' + options.limit + ']',