diff --git a/README.md b/README.md index df7096e..25a8a61 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,10 @@ cmd = readlineSync.prompt(); ``` ## Note -+ The your Node and OS may not support interactively reading from stdin. The stdin interfaces are different by platforms. + +### Platforms + +The your Node and OS may not support interactively reading from stdin. The stdin interfaces are different by platforms. If in those platforms, an error is thrown. ```js @@ -108,6 +111,19 @@ try { } ``` +### Reading by shell + +readlineSync tries reading from stdin by shell if it is needed. And, it use "piping via files" for synchronous running. +As everyone knows, "piping via files" is no good. It blocks event loop and a process. It may make your script be slow. + +Why did I choose it? : + ++ The best solution is [child_process.execSync](https://github.com/joyent/node/blob/master/doc/api/child_process.markdown#child_processexecsynccommand-options) in core modules of Node. But it is not supported by current version. ++ The good modules (native addon) for synchronous execution exist. But node-gyp can't compile those in some platforms or Node versions. ++ I think that the security is important more than the speed. Some modules have problem about security. (It don't protect data.) I think that the speed is not needed usually, because readlineSync is used while user types keys. + +Someday, I may rewrite readlineSync to use child_process.execSync, or safety module. + ## Release History * 2014-07-13 v0.4.3 fixed #6: Crypto input data. * 2014-07-12 v0.4.2 `setPrompt()` and `setEncoding()` return current value. diff --git a/lib/readline-sync.js b/lib/readline-sync.js index 524308d..8d1c259 100644 --- a/lib/readline-sync.js +++ b/lib/readline-sync.js @@ -78,6 +78,8 @@ function _readlineSync(display, options) { function _readlineShell(noEchoBack) { // piping via files instead of execSync (node v0.12+) + // https://github.com/joyent/node/blob/master/doc/api/child_process.markdown#child_processexecsynccommand-options + // see README > Note var shellPath, args, shellStdout, pathStdout = getTempfile('readline-sync.stdout'), pathStatus = getTempfile('readline-sync.status'), diff --git a/package.json b/package.json index 356ccde..2a4591b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "readline-sync", "description": "Synchronous Readline", - "version": "0.4.5", + "version": "0.4.6", "homepage": "https://github.com/anseki/readline-sync", "author": { "name": "anseki"