From 8c78b18e587ab2d87f459ec6f32b729df89f8ceb Mon Sep 17 00:00:00 2001 From: anseki Date: Wed, 27 Apr 2016 22:57:16 +0900 Subject: [PATCH] Use `Buffer.alloc` if it is available. --- lib/readline-sync.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/readline-sync.js b/lib/readline-sync.js index 35fcb3a..722426f 100644 --- a/lib/readline-sync.js +++ b/lib/readline-sync.js @@ -361,7 +361,11 @@ function _readlineSync(options) { input = tryExt(); return; } - buffer = new Buffer((reqSize = options.keyIn ? 1 : options.bufferSize)); + if (Buffer.alloc) { + buffer = Buffer.alloc((reqSize = options.keyIn ? 1 : options.bufferSize)); + } else { + buffer = new Buffer((reqSize = options.keyIn ? 1 : options.bufferSize)); + } if (options.keyIn && options.limit) { limit = new RegExp('[^' + options.limit + ']',