Debian Codegraph @

readme.markdown

raw
1 # read-only-stream
2
3 wrap a readable/writable stream to be read-only
4 to prevent mucking up the input side
5
6 [![build status](https://secure.travis-ci.org/substack/read-only-stream.png)](http://travis-ci.org/substack/read-only-stream)
7
8 # example
9
10 Suppose you have a module that uses a readable/writable stream internally but
11 want to expose just the readable part of that internal stream. This is common if
12 you use the writable side internally and expose the readable side as the
13 interface.
14
15 Now we can write some code like this with a `through` stream internally for
16 convenience:
17
18 ``` js
19 var through = require('through2');
20 var readonly = require('read-only-stream');
21
22 module.exports = function () {
23 var stream = through();
24 stream.end('wooooo\n');
25 return readonly(stream);
26 };
27 ```
28
29 but consumers won't be able to write to the input side and break the api:
30
31 ``` js
32 var wrap = require('./wrap.js');
33 var ro = wrap(); // can't write to `ro` and muck up internal state
34 ro.pipe(process.stdout);
35 ```
36
37 # methods
38
39 ``` js
40 var readonly = require('read-only-stream')
41 ```
42
43 ## var ro = readonly(stream)
44
45 Return a readable stream `ro` that wraps the readable/writable `stream` argument
46 given to only expose the readable side.
47
48 `stream` can be a streams1 or streams2 stream.
49
50 # install
51
52 With [npm](https://npmjs.org) do:
53
54 ```
55 npm install read-only-stream
56 ```
57
58 # license
59
60 MIT