b100904b3cd61466f164629ddb8957469bf2ca6d.svn-base
875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict'
const Base = require('./base.js')
const ownOr = require('own-or')
class Stdin extends Base {
constructor (options) {
options = options || {}
options.name = ownOr(options, 'name', '/dev/stdin')
super(options)
// This has to be here for node 0.10's wonky streams
this.stream = ownOr(options, 'tapStream', process.stdin)
this.stream.pause()
}
main (cb) {
this.stream.on('error', er => {
er.tapCaught = 'stdinError'
this.threw(er)
})
this.setTimeout(this.options.timeout)
this.stream.pipe(this.parser)
if (this.parent)
this.parent.emit('stdin', this)
this.stream.resume()
this.once('end', cb)
}
threw (er, extra, proxy) {
extra = super.threw(er, extra, proxy)
this.options = extra
this.parser.abort(er.message, extra)
this.parser.end()
}
}
module.exports = Stdin