1 | # mute-stream
|
---|
2 |
|
---|
3 | Bytes go in, but they don't come out (when muted).
|
---|
4 |
|
---|
5 | This is a basic pass-through stream, but when muted, the bytes are
|
---|
6 | silently dropped, rather than being passed through.
|
---|
7 |
|
---|
8 | ## Usage
|
---|
9 |
|
---|
10 | ```javascript
|
---|
11 | var MuteStream = require('mute-stream')
|
---|
12 |
|
---|
13 | var ms = new MuteStream(options)
|
---|
14 |
|
---|
15 | ms.pipe(process.stdout)
|
---|
16 | ms.write('foo') // writes 'foo' to stdout
|
---|
17 | ms.mute()
|
---|
18 | ms.write('bar') // does not write 'bar'
|
---|
19 | ms.unmute()
|
---|
20 | ms.write('baz') // writes 'baz' to stdout
|
---|
21 |
|
---|
22 | // can also be used to mute incoming data
|
---|
23 | var ms = new MuteStream
|
---|
24 | input.pipe(ms)
|
---|
25 |
|
---|
26 | ms.on('data', function (c) {
|
---|
27 | console.log('data: ' + c)
|
---|
28 | })
|
---|
29 |
|
---|
30 | input.emit('data', 'foo') // logs 'foo'
|
---|
31 | ms.mute()
|
---|
32 | input.emit('data', 'bar') // does not log 'bar'
|
---|
33 | ms.unmute()
|
---|
34 | input.emit('data', 'baz') // logs 'baz'
|
---|
35 | ```
|
---|
36 |
|
---|
37 | ## Options
|
---|
38 |
|
---|
39 | All options are optional.
|
---|
40 |
|
---|
41 | * `replace` Set to a string to replace each character with the
|
---|
42 | specified string when muted. (So you can show `****` instead of the
|
---|
43 | password, for example.)
|
---|
44 |
|
---|
45 | * `prompt` If you are using a replacement char, and also using a
|
---|
46 | prompt with a readline stream (as for a `Password: *****` input),
|
---|
47 | then specify what the prompt is so that backspace will work
|
---|
48 | properly. Otherwise, pressing backspace will overwrite the prompt
|
---|
49 | with the replacement character, which is weird.
|
---|
50 |
|
---|
51 | ## ms.mute()
|
---|
52 |
|
---|
53 | Set `muted` to `true`. Turns `.write()` into a no-op.
|
---|
54 |
|
---|
55 | ## ms.unmute()
|
---|
56 |
|
---|
57 | Set `muted` to `false`
|
---|
58 |
|
---|
59 | ## ms.isTTY
|
---|
60 |
|
---|
61 | True if the pipe destination is a TTY, or if the incoming pipe source is
|
---|
62 | a TTY.
|
---|
63 |
|
---|
64 | ## Other stream methods...
|
---|
65 |
|
---|
66 | The other standard readable and writable stream methods are all
|
---|
67 | available. The MuteStream object acts as a facade to its pipe source
|
---|
68 | and destination.
|
---|