Projekt

Obecné

Profil

Stáhnout (1.12 KB) Statistiky
| Větev: | Revize:
1
# flush-write-stream
2

    
3
A write stream constructor that supports a flush function that is called before `finish` is emitted
4

    
5
```
6
npm install flush-write-stream
7
```
8

    
9
[![build status](http://img.shields.io/travis/mafintosh/flush-write-stream.svg?style=flat)](http://travis-ci.org/mafintosh/flush-write-stream)
10

    
11
## Usage
12

    
13
``` js
14
var writer = require('flush-write-stream')
15

    
16
var ws = writer(write, flush)
17

    
18
ws.on('finish', function () {
19
  console.log('finished')
20
})
21

    
22
ws.write('hello')
23
ws.write('world')
24
ws.end()
25

    
26
function write (data, enc, cb) {
27
  // i am your normal ._write method
28
  console.log('writing', data.toString())
29
  cb()
30
}
31

    
32
function flush (cb) {
33
  // i am called before finish is emitted
34
  setTimeout(cb, 1000) // wait 1 sec
35
}
36
```
37

    
38
If you run the above it will produce the following output
39

    
40
```
41
writing hello
42
writing world
43
(nothing happens for 1 sec)
44
finished
45
```
46

    
47
## API
48

    
49
#### `var ws = writer([options], write, [flush])`
50

    
51
Create a new writable stream. Options are forwarded to the stream constructor.
52

    
53
#### `var ws = writer.obj([options], write, [flush])`
54

    
55
Same as the above except `objectMode` is set to `true` per default.
56

    
57
## License
58

    
59
MIT
(3-3/7)