diff --git a/README.md b/README.md index b77c9af..0414a76 100644 --- a/README.md +++ b/README.md @@ -481,7 +481,7 @@ _For `question*` and `prompt*` methods only_ When readlineSync reads from a console directly (without external program), use a size `bufferSize` buffer. Even if the input by user exceeds it, it's usually no problem, because the buffer is used repeatedly. But some platforms's (e.g. Windows) console might not accept input that exceeds it. And set an enough size. -Note that this might be limited by [version of Node.js](https://nodejs.org/api/buffer.html#buffer_class_method_buffer_alloc_size_fill_encoding) and environment running your script (Big buffer size is usually not required). +Note that this might be limited by [version of Node.js](https://nodejs.org/api/buffer.html#buffer_class_method_buffer_alloc_size_fill_encoding) and environment running your script (Big buffer size is usually not required). (See also: [issue](https://github.com/nodejs/node/issues/4660), [PR](https://github.com/nodejs/node/pull/4682)) ### `print` diff --git a/lib/readline-sync.js b/lib/readline-sync.js index 722426f..cfed49a 100644 --- a/lib/readline-sync.js +++ b/lib/readline-sync.js @@ -80,7 +80,7 @@ function getHostArgs(options) { })); } -// piping via files (for Node v0.10-) +// piping via files (for Node.js v0.10-) function _execFileSync(options, execOptions) { function getTempfile(name) { @@ -315,7 +315,7 @@ function _readlineSync(options) { ttyR = process.stdin._handle; } catch (e) { /* ignore */ } } else { - // Node v0.12 read() fails. + // Node.js v0.12 read() fails. try { fdR = fs.openSync('/dev/tty', 'r'); ttyR = new TTY(fdR, false); @@ -337,7 +337,7 @@ function _readlineSync(options) { isCooked = !options.hideEchoBack && !options.keyIn, buffer, reqSize, readSize, chunk, line; - // Node v0.10- returns an error if same mode is set. + // Node.js v0.10- returns an error if same mode is set. function setRawMode(mode) { if (mode === isRawMode) { return true; } if (ttyR.setRawMode(mode) !== 0) { return false; } @@ -361,6 +361,9 @@ function _readlineSync(options) { input = tryExt(); 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 {