Additional info about Buffer
This commit is contained in:
parent
92dee428f1
commit
cbd6b25b2a
2 changed files with 7 additions and 4 deletions
|
@ -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.
|
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.
|
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))
|
||||||
|
|
||||||
### <a name="basic_options-print"></a>`print`
|
### <a name="basic_options-print"></a>`print`
|
||||||
|
|
||||||
|
|
|
@ -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 _execFileSync(options, execOptions) {
|
||||||
|
|
||||||
function getTempfile(name) {
|
function getTempfile(name) {
|
||||||
|
@ -315,7 +315,7 @@ function _readlineSync(options) {
|
||||||
ttyR = process.stdin._handle;
|
ttyR = process.stdin._handle;
|
||||||
} catch (e) { /* ignore */ }
|
} catch (e) { /* ignore */ }
|
||||||
} else {
|
} else {
|
||||||
// Node v0.12 read() fails.
|
// Node.js v0.12 read() fails.
|
||||||
try {
|
try {
|
||||||
fdR = fs.openSync('/dev/tty', 'r');
|
fdR = fs.openSync('/dev/tty', 'r');
|
||||||
ttyR = new TTY(fdR, false);
|
ttyR = new TTY(fdR, false);
|
||||||
|
@ -337,7 +337,7 @@ function _readlineSync(options) {
|
||||||
isCooked = !options.hideEchoBack && !options.keyIn,
|
isCooked = !options.hideEchoBack && !options.keyIn,
|
||||||
buffer, reqSize, readSize, chunk, line;
|
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) {
|
function setRawMode(mode) {
|
||||||
if (mode === isRawMode) { return true; }
|
if (mode === isRawMode) { return true; }
|
||||||
if (ttyR.setRawMode(mode) !== 0) { return false; }
|
if (ttyR.setRawMode(mode) !== 0) { return false; }
|
||||||
|
@ -361,6 +361,9 @@ function _readlineSync(options) {
|
||||||
input = tryExt();
|
input = tryExt();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/nodejs/node/issues/4660
|
||||||
|
// https://github.com/nodejs/node/pull/4682
|
||||||
if (Buffer.alloc) {
|
if (Buffer.alloc) {
|
||||||
buffer = Buffer.alloc((reqSize = options.keyIn ? 1 : options.bufferSize));
|
buffer = Buffer.alloc((reqSize = options.keyIn ? 1 : options.bufferSize));
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue