You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # flush-write-stream
  2. A write stream constructor that supports a flush function that is called before `finish` is emitted
  3. ```
  4. npm install flush-write-stream
  5. ```
  6. [![build status](http://img.shields.io/travis/mafintosh/flush-write-stream.svg?style=flat)](http://travis-ci.org/mafintosh/flush-write-stream)
  7. ## Usage
  8. ``` js
  9. var writer = require('flush-write-stream')
  10. var ws = writer(write, flush)
  11. ws.on('finish', function () {
  12. console.log('finished')
  13. })
  14. ws.write('hello')
  15. ws.write('world')
  16. ws.end()
  17. function write (data, enc, cb) {
  18. // i am your normal ._write method
  19. console.log('writing', data.toString())
  20. cb()
  21. }
  22. function flush (cb) {
  23. // i am called before finish is emitted
  24. setTimeout(cb, 1000) // wait 1 sec
  25. }
  26. ```
  27. If you run the above it will produce the following output
  28. ```
  29. writing hello
  30. writing world
  31. (nothing happens for 1 sec)
  32. finished
  33. ```
  34. ## API
  35. #### `var ws = writer([options], write, [flush])`
  36. Create a new writable stream. Options are forwarded to the stream constructor.
  37. #### `var ws = writer.obj([options], write, [flush])`
  38. Same as the above except `objectMode` is set to `true` per default.
  39. ## License
  40. MIT