Add README.md > Note > Reading by shell

This commit is contained in:
anseki 2014-08-21 16:23:39 +09:00
parent 0e2b206e51
commit e3607ad0e1
3 changed files with 20 additions and 2 deletions

View file

@ -96,7 +96,10 @@ cmd = readlineSync.prompt();
``` ```
## Note ## 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. If in those platforms, an error is thrown.
```js ```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 ## Release History
* 2014-07-13 v0.4.3 fixed #6: Crypto input data. * 2014-07-13 v0.4.3 fixed #6: Crypto input data.
* 2014-07-12 v0.4.2 `setPrompt()` and `setEncoding()` return current value. * 2014-07-12 v0.4.2 `setPrompt()` and `setEncoding()` return current value.

View file

@ -78,6 +78,8 @@ function _readlineSync(display, options) {
function _readlineShell(noEchoBack) { function _readlineShell(noEchoBack) {
// piping via files instead of execSync (node v0.12+) // 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, var shellPath, args, shellStdout,
pathStdout = getTempfile('readline-sync.stdout'), pathStdout = getTempfile('readline-sync.stdout'),
pathStatus = getTempfile('readline-sync.status'), pathStatus = getTempfile('readline-sync.status'),

View file

@ -1,7 +1,7 @@
{ {
"name": "readline-sync", "name": "readline-sync",
"description": "Synchronous Readline", "description": "Synchronous Readline",
"version": "0.4.5", "version": "0.4.6",
"homepage": "https://github.com/anseki/readline-sync", "homepage": "https://github.com/anseki/readline-sync",
"author": { "author": {
"name": "anseki" "name": "anseki"