fsevents 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fsevents might be problematic. Click here for more details.

Files changed (216) hide show
  1. package/node_modules/are-we-there-yet/LICENSE +5 -0
  2. package/node_modules/are-we-there-yet/README.md +2 -1
  3. package/node_modules/are-we-there-yet/README.md~ +183 -0
  4. package/node_modules/are-we-there-yet/package.json +10 -9
  5. package/node_modules/async/README.md +14 -10
  6. package/node_modules/async/dist/async.js +22 -18
  7. package/node_modules/async/dist/async.min.js +1 -1
  8. package/node_modules/async/lib/async.js +22 -18
  9. package/node_modules/async/package.json +11 -10
  10. package/node_modules/core-util-is/package.json +2 -1
  11. package/node_modules/dashdash/README.md +6 -3
  12. package/node_modules/dashdash/lib/dashdash.js +10 -1
  13. package/node_modules/dashdash/package.json +9 -8
  14. package/node_modules/escape-string-regexp/index.js +1 -1
  15. package/node_modules/escape-string-regexp/package.json +17 -15
  16. package/node_modules/escape-string-regexp/readme.md +4 -4
  17. package/node_modules/fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/README.md +9 -0
  18. package/node_modules/fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/index.js +42 -30
  19. package/node_modules/fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/package.json +9 -9
  20. package/node_modules/fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/test/balanced.js +28 -0
  21. package/node_modules/fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/package.json +11 -11
  22. package/node_modules/graceful-fs/package.json +2 -3
  23. package/node_modules/isarray/package.json +2 -1
  24. package/node_modules/mime-db/HISTORY.md +32 -0
  25. package/node_modules/mime-db/README.md +1 -1
  26. package/node_modules/mime-db/db.json +78 -0
  27. package/node_modules/mime-db/package.json +15 -14
  28. package/node_modules/mime-types/HISTORY.md +12 -0
  29. package/node_modules/mime-types/package.json +11 -10
  30. package/node_modules/node-pre-gyp/CHANGELOG.md +8 -0
  31. package/node_modules/node-pre-gyp/lib/util/abi_crosswalk.json +32 -0
  32. package/node_modules/node-pre-gyp/package.json +8 -8
  33. package/node_modules/{bl/node_modules/readable-stream/node_modules/process-nextick-args → process-nextick-args}/.travis.yml +6 -1
  34. package/node_modules/{bl/node_modules/readable-stream/node_modules/process-nextick-args → process-nextick-args}/index.js +8 -1
  35. package/node_modules/{bl/node_modules/readable-stream/node_modules/process-nextick-args → process-nextick-args}/package.json +13 -12
  36. package/node_modules/rc/lib/utils.js +1 -1
  37. package/node_modules/rc/package.json +11 -10
  38. package/node_modules/readable-stream/README.md +27 -6
  39. package/node_modules/{bl/node_modules/readable-stream → readable-stream}/doc/stream.markdown +608 -574
  40. package/node_modules/readable-stream/lib/_stream_duplex.js +18 -25
  41. package/node_modules/readable-stream/lib/_stream_passthrough.js +2 -21
  42. package/node_modules/readable-stream/lib/_stream_readable.js +117 -93
  43. package/node_modules/readable-stream/lib/_stream_transform.js +15 -27
  44. package/node_modules/readable-stream/lib/_stream_writable.js +140 -88
  45. package/node_modules/readable-stream/package.json +33 -25
  46. package/node_modules/readable-stream/readable.js +6 -1
  47. package/node_modules/rimraf/README.md +58 -0
  48. package/node_modules/rimraf/node_modules/glob/README.md +27 -45
  49. package/node_modules/rimraf/node_modules/glob/common.js +7 -26
  50. package/node_modules/rimraf/node_modules/glob/node_modules/inherits/package.json +1 -1
  51. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/README.md +9 -0
  52. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/index.js +42 -30
  53. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/package.json +9 -9
  54. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/test/balanced.js +28 -0
  55. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/package.json +11 -11
  56. package/node_modules/rimraf/node_modules/glob/package.json +11 -10
  57. package/node_modules/rimraf/package.json +12 -11
  58. package/node_modules/rimraf/rimraf.js +7 -5
  59. package/node_modules/sshpk/bin/sshpk-conv +1 -1
  60. package/node_modules/sshpk/lib/dhe.js +1 -2
  61. package/node_modules/sshpk/lib/ssh-buffer.js +2 -1
  62. package/node_modules/sshpk/package.json +13 -11
  63. package/node_modules/string_decoder/package.json +2 -1
  64. package/node_modules/tar-pack/index.js +1 -2
  65. package/node_modules/tar-pack/node_modules/rimraf/LICENSE +12 -20
  66. package/node_modules/tar-pack/node_modules/rimraf/README.md +17 -4
  67. package/node_modules/tar-pack/node_modules/rimraf/bin.js +11 -4
  68. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/README.md +359 -0
  69. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/common.js +226 -0
  70. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/glob.js +752 -0
  71. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/inflight/.eslintrc +17 -0
  72. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/inflight/LICENSE +15 -0
  73. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/inflight/README.md +37 -0
  74. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/inflight/inflight.js +44 -0
  75. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/inflight/node_modules/wrappy/LICENSE +15 -0
  76. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/inflight/node_modules/wrappy/README.md +36 -0
  77. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/inflight/node_modules/wrappy/package.json +58 -0
  78. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/inflight/node_modules/wrappy/test/basic.js +51 -0
  79. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/inflight/node_modules/wrappy/wrappy.js +33 -0
  80. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/inflight/package.json +67 -0
  81. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/inflight/test.js +97 -0
  82. package/node_modules/{bl/node_modules/readable-stream → tar-pack/node_modules/rimraf/node_modules/glob}/node_modules/inherits/package.json +3 -3
  83. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/README.md +216 -0
  84. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/minimatch.js +912 -0
  85. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/.npmignore +3 -0
  86. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/README.md +122 -0
  87. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/example.js +8 -0
  88. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/index.js +191 -0
  89. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/.npmignore +2 -0
  90. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/.travis.yml +3 -0
  91. package/node_modules/tar-pack/node_modules/{readable-stream/node_modules/isarray/README.md → rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/LICENSE.md} +0 -33
  92. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/Makefile +6 -0
  93. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/README.md +89 -0
  94. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/example.js +5 -0
  95. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/index.js +50 -0
  96. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/package.json +79 -0
  97. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/test/balanced.js +84 -0
  98. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/.travis.yml +4 -0
  99. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/LICENSE +18 -0
  100. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/README.markdown +62 -0
  101. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/example/map.js +6 -0
  102. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/index.js +13 -0
  103. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/package.json +90 -0
  104. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/test/map.js +39 -0
  105. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/package.json +81 -0
  106. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/minimatch/package.json +66 -0
  107. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/once/README.md +51 -0
  108. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/once/node_modules/wrappy/LICENSE +15 -0
  109. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/once/node_modules/wrappy/README.md +36 -0
  110. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/once/node_modules/wrappy/package.json +58 -0
  111. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/once/node_modules/wrappy/test/basic.js +51 -0
  112. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/once/node_modules/wrappy/wrappy.js +33 -0
  113. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/once/once.js +21 -0
  114. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/once/package.json +70 -0
  115. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/path-is-absolute/index.js +20 -0
  116. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/path-is-absolute/package.json +78 -0
  117. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/node_modules/path-is-absolute/readme.md +51 -0
  118. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/package.json +79 -0
  119. package/node_modules/tar-pack/node_modules/rimraf/node_modules/glob/sync.js +460 -0
  120. package/node_modules/tar-pack/node_modules/rimraf/package.json +28 -40
  121. package/node_modules/tar-pack/node_modules/rimraf/rimraf.js +138 -53
  122. package/node_modules/tar-pack/package.json +21 -11
  123. package/node_modules/tunnel-agent/index.js +2 -0
  124. package/node_modules/tunnel-agent/package.json +10 -9
  125. package/node_modules/{bl/node_modules/readable-stream/node_modules/util-deprecate → util-deprecate}/package.json +3 -2
  126. package/node_modules/verror/package.json +3 -2
  127. package/package.json +2 -2
  128. package/CHANGELOG.md +0 -16
  129. package/node_modules/bl/node_modules/readable-stream/.npmignore +0 -5
  130. package/node_modules/bl/node_modules/readable-stream/LICENSE +0 -18
  131. package/node_modules/bl/node_modules/readable-stream/README.md +0 -36
  132. package/node_modules/bl/node_modules/readable-stream/duplex.js +0 -1
  133. package/node_modules/bl/node_modules/readable-stream/lib/_stream_duplex.js +0 -82
  134. package/node_modules/bl/node_modules/readable-stream/lib/_stream_passthrough.js +0 -27
  135. package/node_modules/bl/node_modules/readable-stream/lib/_stream_readable.js +0 -973
  136. package/node_modules/bl/node_modules/readable-stream/lib/_stream_transform.js +0 -197
  137. package/node_modules/bl/node_modules/readable-stream/lib/_stream_writable.js +0 -527
  138. package/node_modules/bl/node_modules/readable-stream/node_modules/core-util-is/LICENSE +0 -19
  139. package/node_modules/bl/node_modules/readable-stream/node_modules/core-util-is/README.md +0 -3
  140. package/node_modules/bl/node_modules/readable-stream/node_modules/core-util-is/float.patch +0 -604
  141. package/node_modules/bl/node_modules/readable-stream/node_modules/core-util-is/lib/util.js +0 -107
  142. package/node_modules/bl/node_modules/readable-stream/node_modules/core-util-is/package.json +0 -67
  143. package/node_modules/bl/node_modules/readable-stream/node_modules/core-util-is/test.js +0 -68
  144. package/node_modules/bl/node_modules/readable-stream/node_modules/isarray/README.md +0 -54
  145. package/node_modules/bl/node_modules/readable-stream/node_modules/isarray/build/build.js +0 -209
  146. package/node_modules/bl/node_modules/readable-stream/node_modules/isarray/component.json +0 -19
  147. package/node_modules/bl/node_modules/readable-stream/node_modules/isarray/index.js +0 -3
  148. package/node_modules/bl/node_modules/readable-stream/node_modules/isarray/package.json +0 -59
  149. package/node_modules/bl/node_modules/readable-stream/node_modules/string_decoder/.npmignore +0 -2
  150. package/node_modules/bl/node_modules/readable-stream/node_modules/string_decoder/LICENSE +0 -20
  151. package/node_modules/bl/node_modules/readable-stream/node_modules/string_decoder/README.md +0 -7
  152. package/node_modules/bl/node_modules/readable-stream/node_modules/string_decoder/index.js +0 -221
  153. package/node_modules/bl/node_modules/readable-stream/node_modules/string_decoder/package.json +0 -60
  154. package/node_modules/bl/node_modules/readable-stream/package.json +0 -82
  155. package/node_modules/bl/node_modules/readable-stream/passthrough.js +0 -1
  156. package/node_modules/bl/node_modules/readable-stream/readable.js +0 -12
  157. package/node_modules/bl/node_modules/readable-stream/transform.js +0 -1
  158. package/node_modules/bl/node_modules/readable-stream/writable.js +0 -1
  159. package/node_modules/node-pre-gyp/LICENSE +0 -27
  160. package/node_modules/readable-stream/float.patch +0 -923
  161. package/node_modules/tar-pack/node_modules/readable-stream/.npmignore +0 -5
  162. package/node_modules/tar-pack/node_modules/readable-stream/LICENSE +0 -18
  163. package/node_modules/tar-pack/node_modules/readable-stream/README.md +0 -15
  164. package/node_modules/tar-pack/node_modules/readable-stream/duplex.js +0 -1
  165. package/node_modules/tar-pack/node_modules/readable-stream/lib/_stream_duplex.js +0 -89
  166. package/node_modules/tar-pack/node_modules/readable-stream/lib/_stream_passthrough.js +0 -46
  167. package/node_modules/tar-pack/node_modules/readable-stream/lib/_stream_readable.js +0 -982
  168. package/node_modules/tar-pack/node_modules/readable-stream/lib/_stream_transform.js +0 -210
  169. package/node_modules/tar-pack/node_modules/readable-stream/lib/_stream_writable.js +0 -386
  170. package/node_modules/tar-pack/node_modules/readable-stream/node_modules/core-util-is/LICENSE +0 -19
  171. package/node_modules/tar-pack/node_modules/readable-stream/node_modules/core-util-is/README.md +0 -3
  172. package/node_modules/tar-pack/node_modules/readable-stream/node_modules/core-util-is/float.patch +0 -604
  173. package/node_modules/tar-pack/node_modules/readable-stream/node_modules/core-util-is/lib/util.js +0 -107
  174. package/node_modules/tar-pack/node_modules/readable-stream/node_modules/core-util-is/package.json +0 -67
  175. package/node_modules/tar-pack/node_modules/readable-stream/node_modules/core-util-is/test.js +0 -68
  176. package/node_modules/tar-pack/node_modules/readable-stream/node_modules/inherits/LICENSE +0 -16
  177. package/node_modules/tar-pack/node_modules/readable-stream/node_modules/inherits/README.md +0 -42
  178. package/node_modules/tar-pack/node_modules/readable-stream/node_modules/inherits/inherits.js +0 -1
  179. package/node_modules/tar-pack/node_modules/readable-stream/node_modules/inherits/inherits_browser.js +0 -23
  180. package/node_modules/tar-pack/node_modules/readable-stream/node_modules/inherits/package.json +0 -58
  181. package/node_modules/tar-pack/node_modules/readable-stream/node_modules/inherits/test.js +0 -25
  182. package/node_modules/tar-pack/node_modules/readable-stream/node_modules/isarray/build/build.js +0 -209
  183. package/node_modules/tar-pack/node_modules/readable-stream/node_modules/isarray/component.json +0 -19
  184. package/node_modules/tar-pack/node_modules/readable-stream/node_modules/isarray/index.js +0 -3
  185. package/node_modules/tar-pack/node_modules/readable-stream/node_modules/isarray/package.json +0 -59
  186. package/node_modules/tar-pack/node_modules/readable-stream/node_modules/string_decoder/.npmignore +0 -2
  187. package/node_modules/tar-pack/node_modules/readable-stream/node_modules/string_decoder/LICENSE +0 -20
  188. package/node_modules/tar-pack/node_modules/readable-stream/node_modules/string_decoder/README.md +0 -7
  189. package/node_modules/tar-pack/node_modules/readable-stream/node_modules/string_decoder/index.js +0 -221
  190. package/node_modules/tar-pack/node_modules/readable-stream/node_modules/string_decoder/package.json +0 -60
  191. package/node_modules/tar-pack/node_modules/readable-stream/package.json +0 -76
  192. package/node_modules/tar-pack/node_modules/readable-stream/passthrough.js +0 -1
  193. package/node_modules/tar-pack/node_modules/readable-stream/readable.js +0 -8
  194. package/node_modules/tar-pack/node_modules/readable-stream/transform.js +0 -1
  195. package/node_modules/tar-pack/node_modules/readable-stream/writable.js +0 -1
  196. package/node_modules/tar-pack/node_modules/rimraf/AUTHORS +0 -6
  197. package/node_modules/tar-pack/node_modules/rimraf/test/run.sh +0 -16
  198. package/node_modules/tar-pack/node_modules/rimraf/test/setup.sh +0 -47
  199. package/node_modules/tar-pack/node_modules/rimraf/test/test-async.js +0 -5
  200. package/node_modules/tar-pack/node_modules/rimraf/test/test-sync.js +0 -3
  201. /package/node_modules/{bl/node_modules/readable-stream/node_modules/process-nextick-args → process-nextick-args}/license.md +0 -0
  202. /package/node_modules/{bl/node_modules/readable-stream/node_modules/process-nextick-args → process-nextick-args}/readme.md +0 -0
  203. /package/node_modules/{bl/node_modules/readable-stream/node_modules/process-nextick-args → process-nextick-args}/test.js +0 -0
  204. /package/node_modules/{bl/node_modules/readable-stream → readable-stream}/.travis.yml +0 -0
  205. /package/node_modules/{bl/node_modules/readable-stream → readable-stream}/.zuul.yml +0 -0
  206. /package/node_modules/{bl/node_modules/readable-stream → readable-stream}/doc/wg-meetings/2015-01-30.md +0 -0
  207. /package/node_modules/{bl/node_modules/readable-stream → tar-pack/node_modules/rimraf/node_modules/glob}/node_modules/inherits/LICENSE +0 -0
  208. /package/node_modules/{bl/node_modules/readable-stream → tar-pack/node_modules/rimraf/node_modules/glob}/node_modules/inherits/README.md +0 -0
  209. /package/node_modules/{bl/node_modules/readable-stream → tar-pack/node_modules/rimraf/node_modules/glob}/node_modules/inherits/inherits.js +0 -0
  210. /package/node_modules/{bl/node_modules/readable-stream → tar-pack/node_modules/rimraf/node_modules/glob}/node_modules/inherits/inherits_browser.js +0 -0
  211. /package/node_modules/{bl/node_modules/readable-stream → tar-pack/node_modules/rimraf/node_modules/glob}/node_modules/inherits/test.js +0 -0
  212. /package/node_modules/{bl/node_modules/readable-stream/node_modules/util-deprecate → util-deprecate}/History.md +0 -0
  213. /package/node_modules/{bl/node_modules/readable-stream/node_modules/util-deprecate → util-deprecate}/LICENSE +0 -0
  214. /package/node_modules/{bl/node_modules/readable-stream/node_modules/util-deprecate → util-deprecate}/README.md +0 -0
  215. /package/node_modules/{bl/node_modules/readable-stream/node_modules/util-deprecate → util-deprecate}/browser.js +0 -0
  216. /package/node_modules/{bl/node_modules/readable-stream/node_modules/util-deprecate → util-deprecate}/node.js +0 -0
@@ -3,8 +3,7 @@
3
3
  Stability: 2 - Stable
4
4
 
5
5
  A stream is an abstract interface implemented by various objects in
6
- Node.js. For example a [request to an HTTP
7
- server](https://iojs.org/dist/v5.0.0/doc/api/http.html#http_http_incomingmessage) is a stream, as is
6
+ Node.js. For example a [request to an HTTP server][] is a stream, as is
8
7
  [stdout][]. Streams are readable, writable, or both. All streams are
9
8
  instances of [EventEmitter][]
10
9
 
@@ -93,6 +92,17 @@ server.listen(1337);
93
92
  // error: Unexpected token o
94
93
  ```
95
94
 
95
+ ### Class: stream.Duplex
96
+
97
+ Duplex streams are streams that implement both the [Readable][] and
98
+ [Writable][] interfaces. See above for usage.
99
+
100
+ Examples of Duplex streams include:
101
+
102
+ * [tcp sockets][]
103
+ * [zlib streams][]
104
+ * [crypto streams][]
105
+
96
106
  ### Class: stream.Readable
97
107
 
98
108
  <!--type=class-->
@@ -136,61 +146,22 @@ destinations drain and ask for more data.
136
146
 
137
147
  Examples of readable streams include:
138
148
 
139
- * [http responses, on the client](https://iojs.org/dist/v5.0.0/doc/api/http.html#http_http_incomingmessage)
140
- * [http requests, on the server](https://iojs.org/dist/v5.0.0/doc/api/http.html#http_http_incomingmessage)
141
- * [fs read streams](https://iojs.org/dist/v5.0.0/doc/api/fs.html#fs_class_fs_readstream)
149
+ * [http responses, on the client][]
150
+ * [http requests, on the server][]
151
+ * [fs read streams][]
142
152
  * [zlib streams][]
143
153
  * [crypto streams][]
144
154
  * [tcp sockets][]
145
155
  * [child process stdout and stderr][]
146
156
  * [process.stdin][]
147
157
 
148
- #### Event: 'readable'
149
-
150
- When a chunk of data can be read from the stream, it will emit a
151
- `'readable'` event.
152
-
153
- In some cases, listening for a `'readable'` event will cause some data
154
- to be read into the internal buffer from the underlying system, if it
155
- hadn't already.
156
-
157
- ```javascript
158
- var readable = getReadableStreamSomehow();
159
- readable.on('readable', function() {
160
- // there is some data to read now
161
- });
162
- ```
163
-
164
- Once the internal buffer is drained, a `readable` event will fire
165
- again when more data is available.
166
-
167
- The `readable` event is not emitted in the "flowing" mode with the
168
- sole exception of the last one, on end-of-stream.
169
-
170
- The 'readable' event indicates that the stream has new information:
171
- either new data is available or the end of the stream has been reached.
172
- In the former case, `.read()` will return that data. In the latter case,
173
- `.read()` will return null. For instance, in the following example, `foo.txt`
174
- is an empty file:
175
-
176
- ```javascript
177
- var fs = require('fs');
178
- var rr = fs.createReadStream('foo.txt');
179
- rr.on('readable', function() {
180
- console.log('readable:', rr.read());
181
- });
182
- rr.on('end', function() {
183
- console.log('end');
184
- });
185
- ```
158
+ #### Event: 'close'
186
159
 
187
- The output of running this script is:
160
+ Emitted when the stream and any of its underlying resources (a file
161
+ descriptor, for example) have been closed. The event indicates that
162
+ no more events will be emitted, and no further computation will occur.
188
163
 
189
- ```
190
- bash-3.2$ node test.js
191
- readable: null
192
- end
193
- ```
164
+ Not all streams will emit the 'close' event.
194
165
 
195
166
  #### Event: 'data'
196
167
 
@@ -228,101 +199,75 @@ readable.on('end', function() {
228
199
  });
229
200
  ```
230
201
 
231
- #### Event: 'close'
232
-
233
- Emitted when the stream and any of its underlying resources (a file
234
- descriptor, for example) have been closed. The event indicates that
235
- no more events will be emitted, and no further computation will occur.
236
-
237
- Not all streams will emit the 'close' event.
238
-
239
202
  #### Event: 'error'
240
203
 
241
204
  * {Error Object}
242
205
 
243
206
  Emitted if there was an error receiving data.
244
207
 
245
- #### readable.read([size])
246
-
247
- * `size` {Number} Optional argument to specify how much data to read.
248
- * Return {String | Buffer | null}
249
-
250
- The `read()` method pulls some data out of the internal buffer and
251
- returns it. If there is no data available, then it will return
252
- `null`.
253
-
254
- If you pass in a `size` argument, then it will return that many
255
- bytes. If `size` bytes are not available, then it will return `null`,
256
- unless we've ended, in which case it will return the data remaining
257
- in the buffer.
208
+ #### Event: 'readable'
258
209
 
259
- If you do not specify a `size` argument, then it will return all the
260
- data in the internal buffer.
210
+ When a chunk of data can be read from the stream, it will emit a
211
+ `'readable'` event.
261
212
 
262
- This method should only be called in paused mode. In flowing mode,
263
- this method is called automatically until the internal buffer is
264
- drained.
213
+ In some cases, listening for a `'readable'` event will cause some data
214
+ to be read into the internal buffer from the underlying system, if it
215
+ hadn't already.
265
216
 
266
217
  ```javascript
267
218
  var readable = getReadableStreamSomehow();
268
219
  readable.on('readable', function() {
269
- var chunk;
270
- while (null !== (chunk = readable.read())) {
271
- console.log('got %d bytes of data', chunk.length);
272
- }
220
+ // there is some data to read now
273
221
  });
274
222
  ```
275
223
 
276
- If this method returns a data chunk, then it will also trigger the
277
- emission of a [`'data'` event][].
278
-
279
- Note that calling `readable.read([size])` after the `end` event has been
280
- triggered will return `null`. No runtime error will be raised.
281
-
282
- #### readable.setEncoding(encoding)
283
-
284
- * `encoding` {String} The encoding to use.
285
- * Return: `this`
224
+ Once the internal buffer is drained, a `readable` event will fire
225
+ again when more data is available.
286
226
 
287
- Call this function to cause the stream to return strings of the
288
- specified encoding instead of Buffer objects. For example, if you do
289
- `readable.setEncoding('utf8')`, then the output data will be
290
- interpreted as UTF-8 data, and returned as strings. If you do
291
- `readable.setEncoding('hex')`, then the data will be encoded in
292
- hexadecimal string format.
227
+ The `readable` event is not emitted in the "flowing" mode with the
228
+ sole exception of the last one, on end-of-stream.
293
229
 
294
- This properly handles multi-byte characters that would otherwise be
295
- potentially mangled if you simply pulled the Buffers directly and
296
- called `buf.toString(encoding)` on them. If you want to read the data
297
- as strings, always use this method.
230
+ The 'readable' event indicates that the stream has new information:
231
+ either new data is available or the end of the stream has been reached.
232
+ In the former case, `.read()` will return that data. In the latter case,
233
+ `.read()` will return null. For instance, in the following example, `foo.txt`
234
+ is an empty file:
298
235
 
299
236
  ```javascript
300
- var readable = getReadableStreamSomehow();
301
- readable.setEncoding('utf8');
302
- readable.on('data', function(chunk) {
303
- assert.equal(typeof chunk, 'string');
304
- console.log('got %d characters of string data', chunk.length);
237
+ var fs = require('fs');
238
+ var rr = fs.createReadStream('foo.txt');
239
+ rr.on('readable', function() {
240
+ console.log('readable:', rr.read());
241
+ });
242
+ rr.on('end', function() {
243
+ console.log('end');
305
244
  });
306
245
  ```
307
246
 
308
- #### readable.resume()
247
+ The output of running this script is:
309
248
 
310
- * Return: `this`
249
+ ```
250
+ bash-3.2$ node test.js
251
+ readable: null
252
+ end
253
+ ```
311
254
 
312
- This method will cause the readable stream to resume emitting `data`
313
- events.
255
+ #### readable.isPaused()
314
256
 
315
- This method will switch the stream into flowing mode. If you do *not*
316
- want to consume the data from a stream, but you *do* want to get to
317
- its `end` event, you can call [`readable.resume()`][] to open the flow of
318
- data.
257
+ * Return: `Boolean`
258
+
259
+ This method returns whether or not the `readable` has been **explicitly**
260
+ paused by client code (using `readable.pause()` without a corresponding
261
+ `readable.resume()`).
319
262
 
320
263
  ```javascript
321
- var readable = getReadableStreamSomehow();
322
- readable.resume();
323
- readable.on('end', function() {
324
- console.log('got to the end, but did not read anything');
325
- });
264
+ var readable = new stream.Readable
265
+
266
+ readable.isPaused() // === false
267
+ readable.pause()
268
+ readable.isPaused() // === true
269
+ readable.resume()
270
+ readable.isPaused() // === false
326
271
  ```
327
272
 
328
273
  #### readable.pause()
@@ -346,24 +291,6 @@ readable.on('data', function(chunk) {
346
291
  });
347
292
  ```
348
293
 
349
- #### readable.isPaused()
350
-
351
- * Return: `Boolean`
352
-
353
- This method returns whether or not the `readable` has been **explicitly**
354
- paused by client code (using `readable.pause()` without a corresponding
355
- `readable.resume()`).
356
-
357
- ```javascript
358
- var readable = new stream.Readable
359
-
360
- readable.isPaused() // === false
361
- readable.pause()
362
- readable.isPaused() // === true
363
- readable.resume()
364
- readable.isPaused() // === false
365
- ```
366
-
367
294
  #### readable.pipe(destination[, options])
368
295
 
369
296
  * `destination` {[Writable][] Stream} The destination for writing data
@@ -416,54 +343,137 @@ reader.on('end', function() {
416
343
  Note that `process.stderr` and `process.stdout` are never closed until
417
344
  the process exits, regardless of the specified options.
418
345
 
419
- #### readable.unpipe([destination])
346
+ #### readable.read([size])
420
347
 
421
- * `destination` {[Writable][] Stream} Optional specific stream to unpipe
348
+ * `size` {Number} Optional argument to specify how much data to read.
349
+ * Return {String | Buffer | null}
422
350
 
423
- This method will remove the hooks set up for a previous `pipe()` call.
351
+ The `read()` method pulls some data out of the internal buffer and
352
+ returns it. If there is no data available, then it will return
353
+ `null`.
424
354
 
425
- If the destination is not specified, then all pipes are removed.
355
+ If you pass in a `size` argument, then it will return that many
356
+ bytes. If `size` bytes are not available, then it will return `null`,
357
+ unless we've ended, in which case it will return the data remaining
358
+ in the buffer.
426
359
 
427
- If the destination is specified, but no pipe is set up for it, then
428
- this is a no-op.
360
+ If you do not specify a `size` argument, then it will return all the
361
+ data in the internal buffer.
362
+
363
+ This method should only be called in paused mode. In flowing mode,
364
+ this method is called automatically until the internal buffer is
365
+ drained.
429
366
 
430
367
  ```javascript
431
368
  var readable = getReadableStreamSomehow();
432
- var writable = fs.createWriteStream('file.txt');
433
- // All the data from readable goes into 'file.txt',
434
- // but only for the first second
435
- readable.pipe(writable);
436
- setTimeout(function() {
437
- console.log('stop writing to file.txt');
438
- readable.unpipe(writable);
439
- console.log('manually close the file stream');
440
- writable.end();
441
- }, 1000);
369
+ readable.on('readable', function() {
370
+ var chunk;
371
+ while (null !== (chunk = readable.read())) {
372
+ console.log('got %d bytes of data', chunk.length);
373
+ }
374
+ });
442
375
  ```
443
376
 
444
- #### readable.unshift(chunk)
377
+ If this method returns a data chunk, then it will also trigger the
378
+ emission of a [`'data'` event][].
445
379
 
446
- * `chunk` {Buffer | String} Chunk of data to unshift onto the read queue
380
+ Note that calling `readable.read([size])` after the `end` event has been
381
+ triggered will return `null`. No runtime error will be raised.
447
382
 
448
- This is useful in certain cases where a stream is being consumed by a
449
- parser, which needs to "un-consume" some data that it has
450
- optimistically pulled out of the source, so that the stream can be
451
- passed on to some other party.
383
+ #### readable.resume()
452
384
 
453
- Note that `stream.unshift(chunk)` cannot be called after the `end` event
454
- has been triggered; a runtime error will be raised.
385
+ * Return: `this`
455
386
 
456
- If you find that you must often call `stream.unshift(chunk)` in your
457
- programs, consider implementing a [Transform][] stream instead. (See API
458
- for Stream Implementors, below.)
387
+ This method will cause the readable stream to resume emitting `data`
388
+ events.
389
+
390
+ This method will switch the stream into flowing mode. If you do *not*
391
+ want to consume the data from a stream, but you *do* want to get to
392
+ its `end` event, you can call [`readable.resume()`][] to open the flow of
393
+ data.
459
394
 
460
395
  ```javascript
461
- // Pull off a header delimited by \n\n
462
- // use unshift() if we get too much
463
- // Call the callback with (error, header, stream)
464
- var StringDecoder = require('string_decoder').StringDecoder;
465
- function parseHeader(stream, callback) {
466
- stream.on('error', callback);
396
+ var readable = getReadableStreamSomehow();
397
+ readable.resume();
398
+ readable.on('end', function() {
399
+ console.log('got to the end, but did not read anything');
400
+ });
401
+ ```
402
+
403
+ #### readable.setEncoding(encoding)
404
+
405
+ * `encoding` {String} The encoding to use.
406
+ * Return: `this`
407
+
408
+ Call this function to cause the stream to return strings of the
409
+ specified encoding instead of Buffer objects. For example, if you do
410
+ `readable.setEncoding('utf8')`, then the output data will be
411
+ interpreted as UTF-8 data, and returned as strings. If you do
412
+ `readable.setEncoding('hex')`, then the data will be encoded in
413
+ hexadecimal string format.
414
+
415
+ This properly handles multi-byte characters that would otherwise be
416
+ potentially mangled if you simply pulled the Buffers directly and
417
+ called `buf.toString(encoding)` on them. If you want to read the data
418
+ as strings, always use this method.
419
+
420
+ ```javascript
421
+ var readable = getReadableStreamSomehow();
422
+ readable.setEncoding('utf8');
423
+ readable.on('data', function(chunk) {
424
+ assert.equal(typeof chunk, 'string');
425
+ console.log('got %d characters of string data', chunk.length);
426
+ });
427
+ ```
428
+
429
+ #### readable.unpipe([destination])
430
+
431
+ * `destination` {[Writable][] Stream} Optional specific stream to unpipe
432
+
433
+ This method will remove the hooks set up for a previous `pipe()` call.
434
+
435
+ If the destination is not specified, then all pipes are removed.
436
+
437
+ If the destination is specified, but no pipe is set up for it, then
438
+ this is a no-op.
439
+
440
+ ```javascript
441
+ var readable = getReadableStreamSomehow();
442
+ var writable = fs.createWriteStream('file.txt');
443
+ // All the data from readable goes into 'file.txt',
444
+ // but only for the first second
445
+ readable.pipe(writable);
446
+ setTimeout(function() {
447
+ console.log('stop writing to file.txt');
448
+ readable.unpipe(writable);
449
+ console.log('manually close the file stream');
450
+ writable.end();
451
+ }, 1000);
452
+ ```
453
+
454
+ #### readable.unshift(chunk)
455
+
456
+ * `chunk` {Buffer | String} Chunk of data to unshift onto the read queue
457
+
458
+ This is useful in certain cases where a stream is being consumed by a
459
+ parser, which needs to "un-consume" some data that it has
460
+ optimistically pulled out of the source, so that the stream can be
461
+ passed on to some other party.
462
+
463
+ Note that `stream.unshift(chunk)` cannot be called after the `end` event
464
+ has been triggered; a runtime error will be raised.
465
+
466
+ If you find that you must often call `stream.unshift(chunk)` in your
467
+ programs, consider implementing a [Transform][] stream instead. (See API
468
+ for Stream Implementors, below.)
469
+
470
+ ```javascript
471
+ // Pull off a header delimited by \n\n
472
+ // use unshift() if we get too much
473
+ // Call the callback with (error, header, stream)
474
+ var StringDecoder = require('string_decoder').StringDecoder;
475
+ function parseHeader(stream, callback) {
476
+ stream.on('error', callback);
467
477
  stream.on('readable', onReadable);
468
478
  var decoder = new StringDecoder('utf8');
469
479
  var header = '';
@@ -528,6 +538,16 @@ myReader.on('readable', function() {
528
538
  });
529
539
  ```
530
540
 
541
+ ### Class: stream.Transform
542
+
543
+ Transform streams are [Duplex][] streams where the output is in some way
544
+ computed from the input. They implement both the [Readable][] and
545
+ [Writable][] interfaces. See above for usage.
546
+
547
+ Examples of Transform streams include:
548
+
549
+ * [zlib streams][]
550
+ * [crypto streams][]
531
551
 
532
552
  ### Class: stream.Writable
533
553
 
@@ -538,34 +558,15 @@ that you are writing data *to*.
538
558
 
539
559
  Examples of writable streams include:
540
560
 
541
- * [http requests, on the client](https://iojs.org/dist/v5.0.0/doc/api/http.html#http_class_http_clientrequest)
542
- * [http responses, on the server](https://iojs.org/dist/v5.0.0/doc/api/http.html#http_class_http_serverresponse)
543
- * [fs write streams](https://iojs.org/dist/v5.0.0/doc/api/fs.html#fs_class_fs_writestream)
561
+ * [http requests, on the client][]
562
+ * [http responses, on the server][]
563
+ * [fs write streams][]
544
564
  * [zlib streams][]
545
565
  * [crypto streams][]
546
566
  * [tcp sockets][]
547
- * [child process stdin](https://iojs.org/dist/v5.0.0/doc/api/child_process.html#child_process_child_stdin)
567
+ * [child process stdin][]
548
568
  * [process.stdout][], [process.stderr][]
549
569
 
550
- #### writable.write(chunk[, encoding][, callback])
551
-
552
- * `chunk` {String | Buffer} The data to write
553
- * `encoding` {String} The encoding, if `chunk` is a String
554
- * `callback` {Function} Callback for when this chunk of data is flushed
555
- * Returns: {Boolean} True if the data was handled completely.
556
-
557
- This method writes some data to the underlying system, and calls the
558
- supplied callback once the data has been fully handled.
559
-
560
- The return value indicates if you should continue writing right now.
561
- If the data had to be buffered internally, then it will return
562
- `false`. Otherwise, it will return `true`.
563
-
564
- This return value is strictly advisory. You MAY continue to write,
565
- even if it returns `false`. However, writes will be buffered in
566
- memory, so it is best not to do this excessively. Instead, wait for
567
- the `drain` event before writing more data.
568
-
569
570
  #### Event: 'drain'
570
571
 
571
572
  If a [`writable.write(chunk)`][] call returns false, then the `drain`
@@ -600,40 +601,11 @@ function writeOneMillionTimes(writer, data, encoding, callback) {
600
601
  }
601
602
  ```
602
603
 
603
- #### writable.cork()
604
-
605
- Forces buffering of all writes.
606
-
607
- Buffered data will be flushed either at `.uncork()` or at `.end()` call.
608
-
609
- #### writable.uncork()
610
-
611
- Flush all data, buffered since `.cork()` call.
612
-
613
- #### writable.setDefaultEncoding(encoding)
614
-
615
- * `encoding` {String} The new default encoding
616
-
617
- Sets the default encoding for a writable stream.
618
-
619
- #### writable.end([chunk][, encoding][, callback])
620
-
621
- * `chunk` {String | Buffer} Optional data to write
622
- * `encoding` {String} The encoding, if `chunk` is a String
623
- * `callback` {Function} Optional callback for when the stream is finished
624
-
625
- Call this method when no more data will be written to the stream. If
626
- supplied, the callback is attached as a listener on the `finish` event.
604
+ #### Event: 'error'
627
605
 
628
- Calling [`write()`][] after calling [`end()`][] will raise an error.
606
+ * {Error object}
629
607
 
630
- ```javascript
631
- // write 'hello, ' and then end with 'world!'
632
- var file = fs.createWriteStream('example.txt');
633
- file.write('hello, ');
634
- file.end('world!');
635
- // writing more now is not allowed!
636
- ```
608
+ Emitted if there was an error when writing or piping data.
637
609
 
638
610
  #### Event: 'finish'
639
611
 
@@ -686,34 +658,59 @@ reader.pipe(writer);
686
658
  reader.unpipe(writer);
687
659
  ```
688
660
 
689
- #### Event: 'error'
661
+ #### writable.cork()
690
662
 
691
- * {Error object}
663
+ Forces buffering of all writes.
692
664
 
693
- Emitted if there was an error when writing or piping data.
665
+ Buffered data will be flushed either at `.uncork()` or at `.end()` call.
694
666
 
695
- ### Class: stream.Duplex
667
+ #### writable.end([chunk][, encoding][, callback])
696
668
 
697
- Duplex streams are streams that implement both the [Readable][] and
698
- [Writable][] interfaces. See above for usage.
669
+ * `chunk` {String | Buffer} Optional data to write
670
+ * `encoding` {String} The encoding, if `chunk` is a String
671
+ * `callback` {Function} Optional callback for when the stream is finished
699
672
 
700
- Examples of Duplex streams include:
673
+ Call this method when no more data will be written to the stream. If
674
+ supplied, the callback is attached as a listener on the `finish` event.
701
675
 
702
- * [tcp sockets][]
703
- * [zlib streams][]
704
- * [crypto streams][]
676
+ Calling [`write()`][] after calling [`end()`][] will raise an error.
705
677
 
678
+ ```javascript
679
+ // write 'hello, ' and then end with 'world!'
680
+ var file = fs.createWriteStream('example.txt');
681
+ file.write('hello, ');
682
+ file.end('world!');
683
+ // writing more now is not allowed!
684
+ ```
706
685
 
707
- ### Class: stream.Transform
686
+ #### writable.setDefaultEncoding(encoding)
708
687
 
709
- Transform streams are [Duplex][] streams where the output is in some way
710
- computed from the input. They implement both the [Readable][] and
711
- [Writable][] interfaces. See above for usage.
688
+ * `encoding` {String} The new default encoding
712
689
 
713
- Examples of Transform streams include:
690
+ Sets the default encoding for a writable stream.
714
691
 
715
- * [zlib streams][]
716
- * [crypto streams][]
692
+ #### writable.uncork()
693
+
694
+ Flush all data, buffered since `.cork()` call.
695
+
696
+ #### writable.write(chunk[, encoding][, callback])
697
+
698
+ * `chunk` {String | Buffer} The data to write
699
+ * `encoding` {String} The encoding, if `chunk` is a String
700
+ * `callback` {Function} Callback for when this chunk of data is flushed
701
+ * Returns: {Boolean} True if the data was handled completely.
702
+
703
+ This method writes some data to the underlying system, and calls the
704
+ supplied callback once the data has been fully handled.
705
+
706
+ The return value indicates if you should continue writing right now.
707
+ If the data had to be buffered internally, then it will return
708
+ `false`. Otherwise, it will return `true`.
709
+
710
+ This return value is strictly advisory. You MAY continue to write,
711
+ even if it returns `false`. However, writes will be buffered in
712
+ memory, so it is best not to do this excessively. Instead, wait for
713
+ the `drain` event before writing more data.
717
714
 
718
715
 
719
716
  ## API for Stream Implementors
@@ -796,6 +793,49 @@ methods described in [API for Stream Consumers][] above. Otherwise, you
796
793
  can potentially cause adverse side effects in programs that consume
797
794
  your streaming interfaces.
798
795
 
796
+ ### Class: stream.Duplex
797
+
798
+ <!--type=class-->
799
+
800
+ A "duplex" stream is one that is both Readable and Writable, such as a
801
+ TCP socket connection.
802
+
803
+ Note that `stream.Duplex` is an abstract class designed to be extended
804
+ with an underlying implementation of the `_read(size)` and
805
+ [`_write(chunk, encoding, callback)`][] methods as you would with a
806
+ Readable or Writable stream class.
807
+
808
+ Since JavaScript doesn't have multiple prototypal inheritance, this
809
+ class prototypally inherits from Readable, and then parasitically from
810
+ Writable. It is thus up to the user to implement both the lowlevel
811
+ `_read(n)` method as well as the lowlevel
812
+ [`_write(chunk, encoding, callback)`][] method on extension duplex classes.
813
+
814
+ #### new stream.Duplex(options)
815
+
816
+ * `options` {Object} Passed to both Writable and Readable
817
+ constructors. Also has the following fields:
818
+ * `allowHalfOpen` {Boolean} Default=true. If set to `false`, then
819
+ the stream will automatically end the readable side when the
820
+ writable side ends and vice versa.
821
+ * `readableObjectMode` {Boolean} Default=false. Sets `objectMode`
822
+ for readable side of the stream. Has no effect if `objectMode`
823
+ is `true`.
824
+ * `writableObjectMode` {Boolean} Default=false. Sets `objectMode`
825
+ for writable side of the stream. Has no effect if `objectMode`
826
+ is `true`.
827
+
828
+ In classes that extend the Duplex class, make sure to call the
829
+ constructor so that the buffering settings can be properly
830
+ initialized.
831
+
832
+ ### Class: stream.PassThrough
833
+
834
+ This is a trivial implementation of a [Transform][] stream that simply
835
+ passes the input bytes across to the output. Its purpose is mainly
836
+ for examples and testing, but there are occasionally use cases where
837
+ it can come in handy as a building block for novel sorts of streams.
838
+
799
839
  ### Class: stream.Readable
800
840
 
801
841
  <!--type=class-->
@@ -807,15 +847,115 @@ Please see above under [API for Stream Consumers][] for how to consume
807
847
  streams in your programs. What follows is an explanation of how to
808
848
  implement Readable streams in your programs.
809
849
 
810
- #### Example: A Counting Stream
811
-
812
- <!--type=example-->
813
-
814
- This is a basic example of a Readable stream. It emits the numerals
815
- from 1 to 1,000,000 in ascending order, and then ends.
850
+ #### new stream.Readable([options])
816
851
 
817
- ```javascript
818
- var Readable = require('stream').Readable;
852
+ * `options` {Object}
853
+ * `highWaterMark` {Number} The maximum number of bytes to store in
854
+ the internal buffer before ceasing to read from the underlying
855
+ resource. Default=16kb, or 16 for `objectMode` streams
856
+ * `encoding` {String} If specified, then buffers will be decoded to
857
+ strings using the specified encoding. Default=null
858
+ * `objectMode` {Boolean} Whether this stream should behave
859
+ as a stream of objects. Meaning that stream.read(n) returns
860
+ a single value instead of a Buffer of size n. Default=false
861
+
862
+ In classes that extend the Readable class, make sure to call the
863
+ Readable constructor so that the buffering settings can be properly
864
+ initialized.
865
+
866
+ #### readable.\_read(size)
867
+
868
+ * `size` {Number} Number of bytes to read asynchronously
869
+
870
+ Note: **Implement this method, but do NOT call it directly.**
871
+
872
+ This method is prefixed with an underscore because it is internal to the
873
+ class that defines it and should only be called by the internal Readable
874
+ class methods. All Readable stream implementations must provide a _read
875
+ method to fetch data from the underlying resource.
876
+
877
+ When _read is called, if data is available from the resource, `_read` should
878
+ start pushing that data into the read queue by calling `this.push(dataChunk)`.
879
+ `_read` should continue reading from the resource and pushing data until push
880
+ returns false, at which point it should stop reading from the resource. Only
881
+ when _read is called again after it has stopped should it start reading
882
+ more data from the resource and pushing that data onto the queue.
883
+
884
+ Note: once the `_read()` method is called, it will not be called again until
885
+ the `push` method is called.
886
+
887
+ The `size` argument is advisory. Implementations where a "read" is a
888
+ single call that returns data can use this to know how much data to
889
+ fetch. Implementations where that is not relevant, such as TCP or
890
+ TLS, may ignore this argument, and simply provide data whenever it
891
+ becomes available. There is no need, for example to "wait" until
892
+ `size` bytes are available before calling [`stream.push(chunk)`][].
893
+
894
+ #### readable.push(chunk[, encoding])
895
+
896
+ * `chunk` {Buffer | null | String} Chunk of data to push into the read queue
897
+ * `encoding` {String} Encoding of String chunks. Must be a valid
898
+ Buffer encoding, such as `'utf8'` or `'ascii'`
899
+ * return {Boolean} Whether or not more pushes should be performed
900
+
901
+ Note: **This method should be called by Readable implementors, NOT
902
+ by consumers of Readable streams.**
903
+
904
+ If a value other than null is passed, The `push()` method adds a chunk of data
905
+ into the queue for subsequent stream processors to consume. If `null` is
906
+ passed, it signals the end of the stream (EOF), after which no more data
907
+ can be written.
908
+
909
+ The data added with `push` can be pulled out by calling the `read()` method
910
+ when the `'readable'`event fires.
911
+
912
+ This API is designed to be as flexible as possible. For example,
913
+ you may be wrapping a lower-level source which has some sort of
914
+ pause/resume mechanism, and a data callback. In those cases, you
915
+ could wrap the low-level source object by doing something like this:
916
+
917
+ ```javascript
918
+ // source is an object with readStop() and readStart() methods,
919
+ // and an `ondata` member that gets called when it has data, and
920
+ // an `onend` member that gets called when the data is over.
921
+
922
+ util.inherits(SourceWrapper, Readable);
923
+
924
+ function SourceWrapper(options) {
925
+ Readable.call(this, options);
926
+
927
+ this._source = getLowlevelSourceObject();
928
+ var self = this;
929
+
930
+ // Every time there's data, we push it into the internal buffer.
931
+ this._source.ondata = function(chunk) {
932
+ // if push() returns false, then we need to stop reading from source
933
+ if (!self.push(chunk))
934
+ self._source.readStop();
935
+ };
936
+
937
+ // When the source ends, we push the EOF-signaling `null` chunk
938
+ this._source.onend = function() {
939
+ self.push(null);
940
+ };
941
+ }
942
+
943
+ // _read will be called when the stream wants to pull more data in
944
+ // the advisory size argument is ignored in this case.
945
+ SourceWrapper.prototype._read = function(size) {
946
+ this._source.readStart();
947
+ };
948
+ ```
949
+
950
+ #### Example: A Counting Stream
951
+
952
+ <!--type=example-->
953
+
954
+ This is a basic example of a Readable stream. It emits the numerals
955
+ from 1 to 1,000,000 in ascending order, and then ends.
956
+
957
+ ```javascript
958
+ var Readable = require('stream').Readable;
819
959
  var util = require('util');
820
960
  util.inherits(Counter, Readable);
821
961
 
@@ -951,220 +1091,6 @@ SimpleProtocol.prototype._read = function(n) {
951
1091
  // with the parsed header data.
952
1092
  ```
953
1093
 
954
-
955
- #### new stream.Readable([options])
956
-
957
- * `options` {Object}
958
- * `highWaterMark` {Number} The maximum number of bytes to store in
959
- the internal buffer before ceasing to read from the underlying
960
- resource. Default=16kb, or 16 for `objectMode` streams
961
- * `encoding` {String} If specified, then buffers will be decoded to
962
- strings using the specified encoding. Default=null
963
- * `objectMode` {Boolean} Whether this stream should behave
964
- as a stream of objects. Meaning that stream.read(n) returns
965
- a single value instead of a Buffer of size n. Default=false
966
-
967
- In classes that extend the Readable class, make sure to call the
968
- Readable constructor so that the buffering settings can be properly
969
- initialized.
970
-
971
- #### readable.\_read(size)
972
-
973
- * `size` {Number} Number of bytes to read asynchronously
974
-
975
- Note: **Implement this method, but do NOT call it directly.**
976
-
977
- This method is prefixed with an underscore because it is internal to the
978
- class that defines it and should only be called by the internal Readable
979
- class methods. All Readable stream implementations must provide a _read
980
- method to fetch data from the underlying resource.
981
-
982
- When _read is called, if data is available from the resource, `_read` should
983
- start pushing that data into the read queue by calling `this.push(dataChunk)`.
984
- `_read` should continue reading from the resource and pushing data until push
985
- returns false, at which point it should stop reading from the resource. Only
986
- when _read is called again after it has stopped should it start reading
987
- more data from the resource and pushing that data onto the queue.
988
-
989
- Note: once the `_read()` method is called, it will not be called again until
990
- the `push` method is called.
991
-
992
- The `size` argument is advisory. Implementations where a "read" is a
993
- single call that returns data can use this to know how much data to
994
- fetch. Implementations where that is not relevant, such as TCP or
995
- TLS, may ignore this argument, and simply provide data whenever it
996
- becomes available. There is no need, for example to "wait" until
997
- `size` bytes are available before calling [`stream.push(chunk)`][].
998
-
999
- #### readable.push(chunk[, encoding])
1000
-
1001
- * `chunk` {Buffer | null | String} Chunk of data to push into the read queue
1002
- * `encoding` {String} Encoding of String chunks. Must be a valid
1003
- Buffer encoding, such as `'utf8'` or `'ascii'`
1004
- * return {Boolean} Whether or not more pushes should be performed
1005
-
1006
- Note: **This method should be called by Readable implementors, NOT
1007
- by consumers of Readable streams.**
1008
-
1009
- If a value other than null is passed, The `push()` method adds a chunk of data
1010
- into the queue for subsequent stream processors to consume. If `null` is
1011
- passed, it signals the end of the stream (EOF), after which no more data
1012
- can be written.
1013
-
1014
- The data added with `push` can be pulled out by calling the `read()` method
1015
- when the `'readable'`event fires.
1016
-
1017
- This API is designed to be as flexible as possible. For example,
1018
- you may be wrapping a lower-level source which has some sort of
1019
- pause/resume mechanism, and a data callback. In those cases, you
1020
- could wrap the low-level source object by doing something like this:
1021
-
1022
- ```javascript
1023
- // source is an object with readStop() and readStart() methods,
1024
- // and an `ondata` member that gets called when it has data, and
1025
- // an `onend` member that gets called when the data is over.
1026
-
1027
- util.inherits(SourceWrapper, Readable);
1028
-
1029
- function SourceWrapper(options) {
1030
- Readable.call(this, options);
1031
-
1032
- this._source = getLowlevelSourceObject();
1033
- var self = this;
1034
-
1035
- // Every time there's data, we push it into the internal buffer.
1036
- this._source.ondata = function(chunk) {
1037
- // if push() returns false, then we need to stop reading from source
1038
- if (!self.push(chunk))
1039
- self._source.readStop();
1040
- };
1041
-
1042
- // When the source ends, we push the EOF-signaling `null` chunk
1043
- this._source.onend = function() {
1044
- self.push(null);
1045
- };
1046
- }
1047
-
1048
- // _read will be called when the stream wants to pull more data in
1049
- // the advisory size argument is ignored in this case.
1050
- SourceWrapper.prototype._read = function(size) {
1051
- this._source.readStart();
1052
- };
1053
- ```
1054
-
1055
-
1056
- ### Class: stream.Writable
1057
-
1058
- <!--type=class-->
1059
-
1060
- `stream.Writable` is an abstract class designed to be extended with an
1061
- underlying implementation of the [`_write(chunk, encoding, callback)`][] method.
1062
-
1063
- Please see above under [API for Stream Consumers][] for how to consume
1064
- writable streams in your programs. What follows is an explanation of
1065
- how to implement Writable streams in your programs.
1066
-
1067
- #### new stream.Writable([options])
1068
-
1069
- * `options` {Object}
1070
- * `highWaterMark` {Number} Buffer level when [`write()`][] starts
1071
- returning false. Default=16kb, or 16 for `objectMode` streams
1072
- * `decodeStrings` {Boolean} Whether or not to decode strings into
1073
- Buffers before passing them to [`_write()`][]. Default=true
1074
- * `objectMode` {Boolean} Whether or not the `write(anyObj)` is
1075
- a valid operation. If set you can write arbitrary data instead
1076
- of only `Buffer` / `String` data. Default=false
1077
-
1078
- In classes that extend the Writable class, make sure to call the
1079
- constructor so that the buffering settings can be properly
1080
- initialized.
1081
-
1082
- #### writable.\_write(chunk, encoding, callback)
1083
-
1084
- * `chunk` {Buffer | String} The chunk to be written. Will **always**
1085
- be a buffer unless the `decodeStrings` option was set to `false`.
1086
- * `encoding` {String} If the chunk is a string, then this is the
1087
- encoding type. If chunk is a buffer, then this is the special
1088
- value - 'buffer', ignore it in this case.
1089
- * `callback` {Function} Call this function (optionally with an error
1090
- argument) when you are done processing the supplied chunk.
1091
-
1092
- All Writable stream implementations must provide a [`_write()`][]
1093
- method to send data to the underlying resource.
1094
-
1095
- Note: **This function MUST NOT be called directly.** It should be
1096
- implemented by child classes, and called by the internal Writable
1097
- class methods only.
1098
-
1099
- Call the callback using the standard `callback(error)` pattern to
1100
- signal that the write completed successfully or with an error.
1101
-
1102
- If the `decodeStrings` flag is set in the constructor options, then
1103
- `chunk` may be a string rather than a Buffer, and `encoding` will
1104
- indicate the sort of string that it is. This is to support
1105
- implementations that have an optimized handling for certain string
1106
- data encodings. If you do not explicitly set the `decodeStrings`
1107
- option to `false`, then you can safely ignore the `encoding` argument,
1108
- and assume that `chunk` will always be a Buffer.
1109
-
1110
- This method is prefixed with an underscore because it is internal to
1111
- the class that defines it, and should not be called directly by user
1112
- programs. However, you **are** expected to override this method in
1113
- your own extension classes.
1114
-
1115
- #### writable.\_writev(chunks, callback)
1116
-
1117
- * `chunks` {Array} The chunks to be written. Each chunk has following
1118
- format: `{ chunk: ..., encoding: ... }`.
1119
- * `callback` {Function} Call this function (optionally with an error
1120
- argument) when you are done processing the supplied chunks.
1121
-
1122
- Note: **This function MUST NOT be called directly.** It may be
1123
- implemented by child classes, and called by the internal Writable
1124
- class methods only.
1125
-
1126
- This function is completely optional to implement. In most cases it is
1127
- unnecessary. If implemented, it will be called with all the chunks
1128
- that are buffered in the write queue.
1129
-
1130
-
1131
- ### Class: stream.Duplex
1132
-
1133
- <!--type=class-->
1134
-
1135
- A "duplex" stream is one that is both Readable and Writable, such as a
1136
- TCP socket connection.
1137
-
1138
- Note that `stream.Duplex` is an abstract class designed to be extended
1139
- with an underlying implementation of the `_read(size)` and
1140
- [`_write(chunk, encoding, callback)`][] methods as you would with a
1141
- Readable or Writable stream class.
1142
-
1143
- Since JavaScript doesn't have multiple prototypal inheritance, this
1144
- class prototypally inherits from Readable, and then parasitically from
1145
- Writable. It is thus up to the user to implement both the lowlevel
1146
- `_read(n)` method as well as the lowlevel
1147
- [`_write(chunk, encoding, callback)`][] method on extension duplex classes.
1148
-
1149
- #### new stream.Duplex(options)
1150
-
1151
- * `options` {Object} Passed to both Writable and Readable
1152
- constructors. Also has the following fields:
1153
- * `allowHalfOpen` {Boolean} Default=true. If set to `false`, then
1154
- the stream will automatically end the readable side when the
1155
- writable side ends and vice versa.
1156
- * `readableObjectMode` {Boolean} Default=false. Sets `objectMode`
1157
- for readable side of the stream. Has no effect if `objectMode`
1158
- is `true`.
1159
- * `writableObjectMode` {Boolean} Default=false. Sets `objectMode`
1160
- for writable side of the stream. Has no effect if `objectMode`
1161
- is `true`.
1162
-
1163
- In classes that extend the Duplex class, make sure to call the
1164
- constructor so that the buffering settings can be properly
1165
- initialized.
1166
-
1167
-
1168
1094
  ### Class: stream.Transform
1169
1095
 
1170
1096
  A "transform" stream is a duplex stream where the output is causally
@@ -1183,12 +1109,47 @@ also implement the `_flush()` method. (See below.)
1183
1109
 
1184
1110
  #### new stream.Transform([options])
1185
1111
 
1186
- * `options` {Object} Passed to both Writable and Readable
1187
- constructors.
1112
+ * `options` {Object} Passed to both Writable and Readable
1113
+ constructors.
1114
+
1115
+ In classes that extend the Transform class, make sure to call the
1116
+ constructor so that the buffering settings can be properly
1117
+ initialized.
1118
+
1119
+ #### Events: 'finish' and 'end'
1120
+
1121
+ The [`finish`][] and [`end`][] events are from the parent Writable
1122
+ and Readable classes respectively. The `finish` event is fired after
1123
+ `.end()` is called and all chunks have been processed by `_transform`,
1124
+ `end` is fired after all data has been output which is after the callback
1125
+ in `_flush` has been called.
1126
+
1127
+ #### transform.\_flush(callback)
1128
+
1129
+ * `callback` {Function} Call this function (optionally with an error
1130
+ argument) when you are done flushing any remaining data.
1131
+
1132
+ Note: **This function MUST NOT be called directly.** It MAY be implemented
1133
+ by child classes, and if so, will be called by the internal Transform
1134
+ class methods only.
1135
+
1136
+ In some cases, your transform operation may need to emit a bit more
1137
+ data at the end of the stream. For example, a `Zlib` compression
1138
+ stream will store up some internal state so that it can optimally
1139
+ compress the output. At the end, however, it needs to do the best it
1140
+ can with what is left, so that the data will be complete.
1141
+
1142
+ In those cases, you can implement a `_flush` method, which will be
1143
+ called at the very end, after all the written data is consumed, but
1144
+ before emitting `end` to signal the end of the readable side. Just
1145
+ like with `_transform`, call `transform.push(chunk)` zero or more
1146
+ times, as appropriate, and call `callback` when the flush operation is
1147
+ complete.
1188
1148
 
1189
- In classes that extend the Transform class, make sure to call the
1190
- constructor so that the buffering settings can be properly
1191
- initialized.
1149
+ This method is prefixed with an underscore because it is internal to
1150
+ the class that defines it, and should not be called directly by user
1151
+ programs. However, you **are** expected to override this method in
1152
+ your own extension classes.
1192
1153
 
1193
1154
  #### transform.\_transform(chunk, encoding, callback)
1194
1155
 
@@ -1238,41 +1199,6 @@ the class that defines it, and should not be called directly by user
1238
1199
  programs. However, you **are** expected to override this method in
1239
1200
  your own extension classes.
1240
1201
 
1241
- #### transform.\_flush(callback)
1242
-
1243
- * `callback` {Function} Call this function (optionally with an error
1244
- argument) when you are done flushing any remaining data.
1245
-
1246
- Note: **This function MUST NOT be called directly.** It MAY be implemented
1247
- by child classes, and if so, will be called by the internal Transform
1248
- class methods only.
1249
-
1250
- In some cases, your transform operation may need to emit a bit more
1251
- data at the end of the stream. For example, a `Zlib` compression
1252
- stream will store up some internal state so that it can optimally
1253
- compress the output. At the end, however, it needs to do the best it
1254
- can with what is left, so that the data will be complete.
1255
-
1256
- In those cases, you can implement a `_flush` method, which will be
1257
- called at the very end, after all the written data is consumed, but
1258
- before emitting `end` to signal the end of the readable side. Just
1259
- like with `_transform`, call `transform.push(chunk)` zero or more
1260
- times, as appropriate, and call `callback` when the flush operation is
1261
- complete.
1262
-
1263
- This method is prefixed with an underscore because it is internal to
1264
- the class that defines it, and should not be called directly by user
1265
- programs. However, you **are** expected to override this method in
1266
- your own extension classes.
1267
-
1268
- #### Events: 'finish' and 'end'
1269
-
1270
- The [`finish`][] and [`end`][] events are from the parent Writable
1271
- and Readable classes respectively. The `finish` event is fired after
1272
- `.end()` is called and all chunks have been processed by `_transform`,
1273
- `end` is fired after all data has been output which is after the callback
1274
- in `_flush` has been called.
1275
-
1276
1202
  #### Example: `SimpleProtocol` parser v2
1277
1203
 
1278
1204
  The example above of a simple protocol parser can be implemented
@@ -1351,13 +1277,79 @@ SimpleProtocol.prototype._transform = function(chunk, encoding, done) {
1351
1277
  // with the parsed header data.
1352
1278
  ```
1353
1279
 
1280
+ ### Class: stream.Writable
1354
1281
 
1355
- ### Class: stream.PassThrough
1282
+ <!--type=class-->
1356
1283
 
1357
- This is a trivial implementation of a [Transform][] stream that simply
1358
- passes the input bytes across to the output. Its purpose is mainly
1359
- for examples and testing, but there are occasionally use cases where
1360
- it can come in handy as a building block for novel sorts of streams.
1284
+ `stream.Writable` is an abstract class designed to be extended with an
1285
+ underlying implementation of the [`_write(chunk, encoding, callback)`][] method.
1286
+
1287
+ Please see above under [API for Stream Consumers][] for how to consume
1288
+ writable streams in your programs. What follows is an explanation of
1289
+ how to implement Writable streams in your programs.
1290
+
1291
+ #### new stream.Writable([options])
1292
+
1293
+ * `options` {Object}
1294
+ * `highWaterMark` {Number} Buffer level when [`write()`][] starts
1295
+ returning false. Default=16kb, or 16 for `objectMode` streams
1296
+ * `decodeStrings` {Boolean} Whether or not to decode strings into
1297
+ Buffers before passing them to [`_write()`][]. Default=true
1298
+ * `objectMode` {Boolean} Whether or not the `write(anyObj)` is
1299
+ a valid operation. If set you can write arbitrary data instead
1300
+ of only `Buffer` / `String` data. Default=false
1301
+
1302
+ In classes that extend the Writable class, make sure to call the
1303
+ constructor so that the buffering settings can be properly
1304
+ initialized.
1305
+
1306
+ #### writable.\_write(chunk, encoding, callback)
1307
+
1308
+ * `chunk` {Buffer | String} The chunk to be written. Will **always**
1309
+ be a buffer unless the `decodeStrings` option was set to `false`.
1310
+ * `encoding` {String} If the chunk is a string, then this is the
1311
+ encoding type. If chunk is a buffer, then this is the special
1312
+ value - 'buffer', ignore it in this case.
1313
+ * `callback` {Function} Call this function (optionally with an error
1314
+ argument) when you are done processing the supplied chunk.
1315
+
1316
+ All Writable stream implementations must provide a [`_write()`][]
1317
+ method to send data to the underlying resource.
1318
+
1319
+ Note: **This function MUST NOT be called directly.** It should be
1320
+ implemented by child classes, and called by the internal Writable
1321
+ class methods only.
1322
+
1323
+ Call the callback using the standard `callback(error)` pattern to
1324
+ signal that the write completed successfully or with an error.
1325
+
1326
+ If the `decodeStrings` flag is set in the constructor options, then
1327
+ `chunk` may be a string rather than a Buffer, and `encoding` will
1328
+ indicate the sort of string that it is. This is to support
1329
+ implementations that have an optimized handling for certain string
1330
+ data encodings. If you do not explicitly set the `decodeStrings`
1331
+ option to `false`, then you can safely ignore the `encoding` argument,
1332
+ and assume that `chunk` will always be a Buffer.
1333
+
1334
+ This method is prefixed with an underscore because it is internal to
1335
+ the class that defines it, and should not be called directly by user
1336
+ programs. However, you **are** expected to override this method in
1337
+ your own extension classes.
1338
+
1339
+ #### writable.\_writev(chunks, callback)
1340
+
1341
+ * `chunks` {Array} The chunks to be written. Each chunk has following
1342
+ format: `{ chunk: ..., encoding: ... }`.
1343
+ * `callback` {Function} Call this function (optionally with an error
1344
+ argument) when you are done processing the supplied chunks.
1345
+
1346
+ Note: **This function MUST NOT be called directly.** It may be
1347
+ implemented by child classes, and called by the internal Writable
1348
+ class methods only.
1349
+
1350
+ This function is completely optional to implement. In most cases it is
1351
+ unnecessary. If implemented, it will be called with all the chunks
1352
+ that are buffered in the write queue.
1361
1353
 
1362
1354
 
1363
1355
  ## Simplified Constructor API
@@ -1370,51 +1362,52 @@ This can be done by passing the appropriate methods as constructor options:
1370
1362
 
1371
1363
  Examples:
1372
1364
 
1373
- ### Readable
1365
+ ### Duplex
1374
1366
  ```javascript
1375
- var readable = new stream.Readable({
1367
+ var duplex = new stream.Duplex({
1376
1368
  read: function(n) {
1377
1369
  // sets this._read under the hood
1378
- }
1379
- });
1380
- ```
1381
1370
 
1382
- ### Writable
1383
- ```javascript
1384
- var writable = new stream.Writable({
1371
+ // push data onto the read queue, passing null
1372
+ // will signal the end of the stream (EOF)
1373
+ this.push(chunk);
1374
+ },
1385
1375
  write: function(chunk, encoding, next) {
1386
1376
  // sets this._write under the hood
1377
+
1378
+ // An optional error can be passed as the first argument
1379
+ next()
1387
1380
  }
1388
1381
  });
1389
1382
 
1390
1383
  // or
1391
1384
 
1392
- var writable = new stream.Writable({
1385
+ var duplex = new stream.Duplex({
1386
+ read: function(n) {
1387
+ // sets this._read under the hood
1388
+
1389
+ // push data onto the read queue, passing null
1390
+ // will signal the end of the stream (EOF)
1391
+ this.push(chunk);
1392
+ },
1393
1393
  writev: function(chunks, next) {
1394
1394
  // sets this._writev under the hood
1395
+
1396
+ // An optional error can be passed as the first argument
1397
+ next()
1395
1398
  }
1396
1399
  });
1397
1400
  ```
1398
1401
 
1399
- ### Duplex
1402
+ ### Readable
1400
1403
  ```javascript
1401
- var duplex = new stream.Duplex({
1404
+ var readable = new stream.Readable({
1402
1405
  read: function(n) {
1403
1406
  // sets this._read under the hood
1404
- },
1405
- write: function(chunk, encoding, next) {
1406
- // sets this._write under the hood
1407
- }
1408
- });
1409
-
1410
- // or
1411
1407
 
1412
- var duplex = new stream.Duplex({
1413
- read: function(n) {
1414
- // sets this._read under the hood
1415
- },
1416
- writev: function(chunks, next) {
1417
- // sets this._writev under the hood
1408
+ // push data onto the read queue, passing null
1409
+ // will signal the end of the stream (EOF)
1410
+ this.push(chunk);
1418
1411
  }
1419
1412
  });
1420
1413
  ```
@@ -1424,9 +1417,43 @@ var duplex = new stream.Duplex({
1424
1417
  var transform = new stream.Transform({
1425
1418
  transform: function(chunk, encoding, next) {
1426
1419
  // sets this._transform under the hood
1420
+
1421
+ // generate output as many times as needed
1422
+ // this.push(chunk);
1423
+
1424
+ // call when the current chunk is consumed
1425
+ next();
1427
1426
  },
1428
1427
  flush: function(done) {
1429
1428
  // sets this._flush under the hood
1429
+
1430
+ // generate output as many times as needed
1431
+ // this.push(chunk);
1432
+
1433
+ done();
1434
+ }
1435
+ });
1436
+ ```
1437
+
1438
+ ### Writable
1439
+ ```javascript
1440
+ var writable = new stream.Writable({
1441
+ write: function(chunk, encoding, next) {
1442
+ // sets this._write under the hood
1443
+
1444
+ // An optional error can be passed as the first argument
1445
+ next()
1446
+ }
1447
+ });
1448
+
1449
+ // or
1450
+
1451
+ var writable = new stream.Writable({
1452
+ writev: function(chunks, next) {
1453
+ // sets this._writev under the hood
1454
+
1455
+ // An optional error can be passed as the first argument
1456
+ next()
1430
1457
  }
1431
1458
  });
1432
1459
  ```
@@ -1458,40 +1485,6 @@ The purpose of streams, especially with the `pipe()` method, is to
1458
1485
  limit the buffering of data to acceptable levels, so that sources and
1459
1486
  destinations of varying speed will not overwhelm the available memory.
1460
1487
 
1461
- ### `stream.read(0)`
1462
-
1463
- There are some cases where you want to trigger a refresh of the
1464
- underlying readable stream mechanisms, without actually consuming any
1465
- data. In that case, you can call `stream.read(0)`, which will always
1466
- return null.
1467
-
1468
- If the internal read buffer is below the `highWaterMark`, and the
1469
- stream is not currently reading, then calling `read(0)` will trigger
1470
- a low-level `_read` call.
1471
-
1472
- There is almost never a need to do this. However, you will see some
1473
- cases in Node.js's internals where this is done, particularly in the
1474
- Readable stream class internals.
1475
-
1476
- ### `stream.push('')`
1477
-
1478
- Pushing a zero-byte string or Buffer (when not in [Object mode][]) has an
1479
- interesting side effect. Because it *is* a call to
1480
- [`stream.push()`][], it will end the `reading` process. However, it
1481
- does *not* add any data to the readable buffer, so there's nothing for
1482
- a user to consume.
1483
-
1484
- Very rarely, there are cases where you have no data to provide now,
1485
- but the consumer of your stream (or, perhaps, another bit of your own
1486
- code) will know when to check again, by calling `stream.read(0)`. In
1487
- those cases, you *may* call `stream.push('')`.
1488
-
1489
- So far, the only use case for this functionality is in the
1490
- [tls.CryptoStream][] class, which is deprecated in Node.js/io.js v1.0. If you
1491
- find that you have to use `stream.push('')`, please consider another
1492
- approach, because it almost certainly indicates that something is
1493
- horribly wrong.
1494
-
1495
1488
  ### Compatibility with Older Node.js Versions
1496
1489
 
1497
1490
  <!--type=misc-->
@@ -1649,25 +1642,66 @@ JSONParseStream.prototype._flush = function(cb) {
1649
1642
  };
1650
1643
  ```
1651
1644
 
1645
+ ### `stream.read(0)`
1646
+
1647
+ There are some cases where you want to trigger a refresh of the
1648
+ underlying readable stream mechanisms, without actually consuming any
1649
+ data. In that case, you can call `stream.read(0)`, which will always
1650
+ return null.
1651
+
1652
+ If the internal read buffer is below the `highWaterMark`, and the
1653
+ stream is not currently reading, then calling `read(0)` will trigger
1654
+ a low-level `_read` call.
1655
+
1656
+ There is almost never a need to do this. However, you will see some
1657
+ cases in Node.js's internals where this is done, particularly in the
1658
+ Readable stream class internals.
1659
+
1660
+ ### `stream.push('')`
1661
+
1662
+ Pushing a zero-byte string or Buffer (when not in [Object mode][]) has an
1663
+ interesting side effect. Because it *is* a call to
1664
+ [`stream.push()`][], it will end the `reading` process. However, it
1665
+ does *not* add any data to the readable buffer, so there's nothing for
1666
+ a user to consume.
1667
+
1668
+ Very rarely, there are cases where you have no data to provide now,
1669
+ but the consumer of your stream (or, perhaps, another bit of your own
1670
+ code) will know when to check again, by calling `stream.read(0)`. In
1671
+ those cases, you *may* call `stream.push('')`.
1672
+
1673
+ So far, the only use case for this functionality is in the
1674
+ [tls.CryptoStream][] class, which is deprecated in Node.js/io.js v1.0. If you
1675
+ find that you have to use `stream.push('')`, please consider another
1676
+ approach, because it almost certainly indicates that something is
1677
+ horribly wrong.
1652
1678
 
1653
- [EventEmitter]: https://iojs.org/dist/v5.0.0/doc/api/events.html#events_class_events_eventemitter
1679
+ [request to an HTTP server]: https://nodejs.org/docs/v5.1.0/api/http.html#http_http_incomingmessage
1680
+ [EventEmitter]: https://nodejs.org/docs/v5.1.0/api/events.html#events_class_events_eventemitter
1654
1681
  [Object mode]: #stream_object_mode
1655
1682
  [`stream.push(chunk)`]: #stream_readable_push_chunk_encoding
1656
1683
  [`stream.push(null)`]: #stream_readable_push_chunk_encoding
1657
1684
  [`stream.push()`]: #stream_readable_push_chunk_encoding
1658
1685
  [`unpipe()`]: #stream_readable_unpipe_destination
1659
1686
  [unpiped]: #stream_readable_unpipe_destination
1660
- [tcp sockets]: https://iojs.org/dist/v5.0.0/doc/api/net.html#net_class_net_socket
1687
+ [tcp sockets]: https://nodejs.org/docs/v5.1.0/api/net.html#net_class_net_socket
1688
+ [http responses, on the client]: https://nodejs.org/docs/v5.1.0/api/http.html#http_http_incomingmessage
1689
+ [http requests, on the server]: https://nodejs.org/docs/v5.1.0/api/http.html#http_http_incomingmessage
1690
+ [http requests, on the client]: https://nodejs.org/docs/v5.1.0/api/http.html#http_class_http_clientrequest
1691
+ [http responses, on the server]: https://nodejs.org/docs/v5.1.0/api/http.html#http_class_http_serverresponse
1692
+ [fs read streams]: https://nodejs.org/docs/v5.1.0/api/fs.html#fs_class_fs_readstream
1693
+ [fs write streams]: https://nodejs.org/docs/v5.1.0/api/fs.html#fs_class_fs_writestream
1661
1694
  [zlib streams]: zlib.html
1662
1695
  [zlib]: zlib.html
1663
1696
  [crypto streams]: crypto.html
1664
1697
  [crypto]: crypto.html
1665
- [tls.CryptoStream]: https://iojs.org/dist/v5.0.0/doc/api/tls.html#tls_class_cryptostream
1666
- [process.stdin]: https://iojs.org/dist/v5.0.0/doc/api/process.html#process_process_stdin
1667
- [stdout]: https://iojs.org/dist/v5.0.0/doc/api/process.html#process_process_stdout
1668
- [process.stdout]: https://iojs.org/dist/v5.0.0/doc/api/process.html#process_process_stdout
1669
- [process.stderr]: https://iojs.org/dist/v5.0.0/doc/api/process.html#process_process_stderr
1670
- [child process stdout and stderr]: https://iojs.org/dist/v5.0.0/doc/api/child_process.html#child_process_child_stdout
1698
+ [tls.CryptoStream]: https://nodejs.org/docs/v5.1.0/api/tls.html#tls_class_cryptostream
1699
+ [process.stdin]: https://nodejs.org/docs/v5.1.0/api/process.html#process_process_stdin
1700
+ [stdout]: https://nodejs.org/docs/v5.1.0/api/process.html#process_process_stdout
1701
+ [process.stdout]: https://nodejs.org/docs/v5.1.0/api/process.html#process_process_stdout
1702
+ [process.stderr]: https://nodejs.org/docs/v5.1.0/api/process.html#process_process_stderr
1703
+ [child process stdout and stderr]: https://nodejs.org/docs/v5.1.0/api/child_process.html#child_process_child_stdout
1704
+ [child process stdin]: https://nodejs.org/docs/v5.1.0/api/child_process.html#child_process_child_stdin
1671
1705
  [API for Stream Consumers]: #stream_api_for_stream_consumers
1672
1706
  [API for Stream Implementors]: #stream_api_for_stream_implementors
1673
1707
  [Readable]: #stream_class_stream_readable
@@ -1686,7 +1720,7 @@ JSONParseStream.prototype._flush = function(cb) {
1686
1720
  [`_write(chunk, encoding, callback)`]: #stream_writable_write_chunk_encoding_callback_1
1687
1721
  [`_write()`]: #stream_writable_write_chunk_encoding_callback_1
1688
1722
  [_write]: #stream_writable_write_chunk_encoding_callback_1
1689
- [`util.inherits`]: https://iojs.org/dist/v5.0.0/doc/api/util.html#util_util_inherits_constructor_superconstructor
1723
+ [`util.inherits`]: https://nodejs.org/docs/v5.1.0/api/util.html#util_util_inherits_constructor_superconstructor
1690
1724
  [`end()`]: #stream_writable_end_chunk_encoding_callback
1691
1725
  [`'data'` event]: #stream_event_data
1692
1726
  [`resume()`]: #stream_readable_resume