1
1
# stream-string
2
2
3
- [ ![ Build Status] ( https://img.shields.io/travis/jamescostian/stream-string.svg?style=flat )] ( https://travis-ci.org/jamescostian/stream-string )
4
- [ ![ Coverage Status] ( https://img.shields.io/coveralls/jamescostian/stream-string.svg?style=flat )] ( https://coveralls.io/r/jamescostian/stream-string?branch=master )
3
+ [ ![ GitHub Workflow Status] ( https://img.shields.io/github/actions/workflow/status/jamescostian/stream-string/check.yaml?branch=main )] ( https://github.com/jamescostian/stream-string/actions?query=workflow%3Acheck )
5
4
[ ![ License] ( https://img.shields.io/npm/l/stream-string.svg?style=flat )] ( https://github.com/jamescostian/stream-string/blob/master/LICENSE )
6
5
[ ![ NPM Version] ( https://img.shields.io/npm/v/stream-string.svg?style=flat )] ( https://www.npmjs.com/package/stream-string )
7
6
[ ![ Downloads/Month] ( https://img.shields.io/npm/dm/stream-string.svg?style=flat )] ( https://www.npmjs.com/package/stream-string )
@@ -21,40 +20,45 @@ npm install --save stream-string
21
20
### Promises
22
21
23
22
``` js
24
- const fs = require (' fs ' )
25
- const ss = require (' stream-string' )
23
+ const fs = require (" fs " );
24
+ const ss = require (" stream-string" );
26
25
27
26
// Make a gzip stream (just for this example)
28
- const myStream = fs .createReadStream (' ./file' ).pipe (require (' zlib' ).createGzip ())
29
-
30
- ss (myStream).then (data => {
31
- // myStream was converted to a string, and that string is stored in data
32
- console .log (data)
33
- }).catch (err => {
34
- // myStream emitted an error event (err), so the promise from stream-string was rejected
35
- throw err
36
- })
27
+ const myStream = fs
28
+ .createReadStream (" ./file" )
29
+ .pipe (require (" zlib" ).createGzip ());
30
+
31
+ ss (myStream)
32
+ .then ((data ) => {
33
+ // myStream was converted to a string, and that string is stored in data
34
+ console .log (data);
35
+ })
36
+ .catch ((err ) => {
37
+ // myStream emitted an error event (err), so the promise from stream-string was rejected
38
+ throw err;
39
+ });
37
40
```
38
41
39
42
### Callbacks
40
43
41
44
``` js
42
- const fs = require (' fs ' )
43
- const ss = require (' stream-string' )
45
+ const fs = require (" fs " );
46
+ const ss = require (" stream-string" );
44
47
45
48
// Make a gzip stream (just for this example)
46
- const myStream = fs .createReadStream (' ./file' ).pipe (require (' zlib' ).createGzip ())
49
+ const myStream = fs
50
+ .createReadStream (" ./file" )
51
+ .pipe (require (" zlib" ).createGzip ());
47
52
48
53
ss (myStream, (err , data ) => {
49
54
if (err) {
50
55
// myStream emitted an error event (err), which was passed to the callback
51
- throw err
52
- }
53
- else {
56
+ throw err;
57
+ } else {
54
58
// myStream was converted to a string, and that string is stored in data
55
- console .log (data)
59
+ console .log (data);
56
60
}
57
- })
61
+ });
58
62
```
59
63
60
64
## Contributing
0 commit comments