fsevents 1.0.12 → 1.0.14

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

Files changed (514) hide show
  1. package/.npmignore +1 -3
  2. package/.travis.yml +6 -5
  3. package/build/.target.mk +49 -0
  4. package/build/Makefile +352 -0
  5. package/build/action_after_build.target.mk +32 -0
  6. package/build/binding.Makefile +6 -0
  7. package/build/fse.target.mk +169 -0
  8. package/build/gyp-mac-tool +612 -0
  9. package/lib/binding/Release/node-v11-darwin-x64/fse.node +0 -0
  10. package/lib/binding/Release/node-v46-darwin-x64/fse.node +0 -0
  11. package/lib/binding/Release/node-v47-darwin-x64/fse.node +0 -0
  12. package/node_modules/abbrev/package.json +82 -0
  13. package/node_modules/{lodash.repeat/LICENSE → ansi-regex/license} +5 -7
  14. package/node_modules/ansi-regex/package.json +20 -2
  15. package/node_modules/{lodash.padstart/LICENSE → ansi-styles/license} +5 -7
  16. package/node_modules/ansi-styles/package.json +21 -4
  17. package/node_modules/aproba/LICENSE +14 -0
  18. package/node_modules/aproba/README.md +59 -0
  19. package/node_modules/aproba/index.js +62 -0
  20. package/node_modules/aproba/package.json +88 -0
  21. package/node_modules/are-we-there-yet/package.json +21 -4
  22. package/node_modules/asn1/package.json +19 -1
  23. package/node_modules/assert-plus/package.json +21 -4
  24. package/node_modules/async/CHANGELOG.md +125 -0
  25. package/node_modules/async/LICENSE +19 -0
  26. package/node_modules/async/package.json +20 -2
  27. package/node_modules/aws-sign2/package.json +20 -2
  28. package/node_modules/aws4/aws4.js +1 -1
  29. package/node_modules/aws4/lru.js +96 -0
  30. package/node_modules/aws4/package.json +31 -16
  31. package/node_modules/{rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion → balanced-match}/.npmignore +2 -0
  32. package/node_modules/{rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match → balanced-match}/README.md +5 -3
  33. package/node_modules/{fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match → balanced-match}/index.js +9 -1
  34. package/node_modules/{rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match → balanced-match}/package.json +35 -13
  35. package/node_modules/bl/README.md +3 -3
  36. package/node_modules/bl/bl.js +54 -38
  37. package/node_modules/bl/node_modules/readable-stream/.npmignore +5 -0
  38. package/node_modules/bl/node_modules/readable-stream/.travis.yml +52 -0
  39. package/node_modules/bl/node_modules/readable-stream/LICENSE +18 -0
  40. package/node_modules/bl/node_modules/readable-stream/README.md +36 -0
  41. package/node_modules/bl/node_modules/readable-stream/doc/wg-meetings/2015-01-30.md +60 -0
  42. package/node_modules/bl/node_modules/readable-stream/duplex.js +1 -0
  43. package/node_modules/bl/node_modules/readable-stream/lib/_stream_duplex.js +75 -0
  44. package/node_modules/bl/node_modules/readable-stream/lib/_stream_passthrough.js +26 -0
  45. package/node_modules/bl/node_modules/readable-stream/lib/_stream_readable.js +880 -0
  46. package/node_modules/bl/node_modules/readable-stream/lib/_stream_transform.js +180 -0
  47. package/node_modules/bl/node_modules/readable-stream/lib/_stream_writable.js +516 -0
  48. package/node_modules/bl/node_modules/readable-stream/package.json +105 -0
  49. package/node_modules/bl/node_modules/readable-stream/passthrough.js +1 -0
  50. package/node_modules/bl/node_modules/readable-stream/readable.js +12 -0
  51. package/node_modules/bl/node_modules/readable-stream/transform.js +1 -0
  52. package/node_modules/bl/node_modules/readable-stream/writable.js +1 -0
  53. package/node_modules/bl/package.json +39 -15
  54. package/node_modules/bl/test/test.js +71 -2
  55. package/node_modules/block-stream/package.json +37 -12
  56. package/node_modules/boom/package.json +20 -2
  57. package/node_modules/{rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion → brace-expansion}/package.json +34 -16
  58. package/node_modules/buffer-shims/index.js +108 -0
  59. package/node_modules/buffer-shims/license.md +19 -0
  60. package/node_modules/buffer-shims/package.json +77 -0
  61. package/node_modules/buffer-shims/readme.md +21 -0
  62. package/node_modules/caseless/package.json +20 -2
  63. package/node_modules/{lodash.pad/LICENSE → chalk/license} +5 -7
  64. package/node_modules/chalk/package.json +21 -4
  65. package/node_modules/code-point-at/index.js +33 -0
  66. package/node_modules/{lodash.padend/LICENSE → code-point-at/license} +5 -7
  67. package/node_modules/code-point-at/package.json +96 -0
  68. package/node_modules/code-point-at/readme.md +34 -0
  69. package/node_modules/combined-stream/package.json +20 -2
  70. package/node_modules/commander/History.md +261 -0
  71. package/node_modules/commander/LICENSE +22 -0
  72. package/node_modules/commander/package.json +20 -2
  73. package/node_modules/{rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → concat-map}/package.json +21 -3
  74. package/node_modules/console-control-strings/LICENSE +13 -0
  75. package/node_modules/console-control-strings/README.md +145 -0
  76. package/node_modules/console-control-strings/README.md~ +140 -0
  77. package/node_modules/console-control-strings/index.js +125 -0
  78. package/node_modules/console-control-strings/package.json +88 -0
  79. package/node_modules/core-util-is/package.json +21 -2
  80. package/node_modules/cryptiles/package.json +20 -2
  81. package/node_modules/dashdash/lib/dashdash.js +34 -1
  82. package/node_modules/dashdash/node_modules/assert-plus/package.json +21 -4
  83. package/node_modules/dashdash/package.json +29 -12
  84. package/node_modules/debug/package.json +20 -2
  85. package/node_modules/deep-extend/CHANGELOG.md +21 -0
  86. package/node_modules/{rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → deep-extend}/LICENSE +3 -1
  87. package/node_modules/deep-extend/package.json +21 -4
  88. package/node_modules/delayed-stream/package.json +20 -2
  89. package/node_modules/delegates/package.json +21 -4
  90. package/node_modules/ecc-jsbn/package.json +20 -2
  91. package/node_modules/escape-string-regexp/license +21 -0
  92. package/node_modules/escape-string-regexp/package.json +21 -4
  93. package/node_modules/extend/package.json +20 -2
  94. package/node_modules/extsprintf/package.json +20 -3
  95. package/node_modules/forever-agent/package.json +20 -2
  96. package/node_modules/form-data/package.json +21 -4
  97. package/node_modules/fs.realpath/LICENSE +43 -0
  98. package/node_modules/fs.realpath/README.md +33 -0
  99. package/node_modules/fs.realpath/index.js +66 -0
  100. package/node_modules/fs.realpath/old.js +303 -0
  101. package/node_modules/fs.realpath/package.json +86 -0
  102. package/node_modules/fstream/.travis.yml +4 -4
  103. package/node_modules/fstream/lib/collect.js +2 -0
  104. package/node_modules/fstream/package.json +37 -15
  105. package/node_modules/fstream-ignore/package.json +45 -17
  106. package/node_modules/gauge/CHANGELOG.md +131 -0
  107. package/node_modules/gauge/CHANGELOG.md~ +123 -0
  108. package/node_modules/gauge/README.md +317 -88
  109. package/node_modules/gauge/README.md~ +393 -0
  110. package/node_modules/gauge/base-theme.js +14 -0
  111. package/node_modules/gauge/error.js +24 -0
  112. package/node_modules/gauge/has-color.js +12 -0
  113. package/node_modules/gauge/index.js +226 -0
  114. package/node_modules/gauge/package.json +67 -21
  115. package/node_modules/gauge/plumbing.js +47 -0
  116. package/node_modules/gauge/process.js +3 -0
  117. package/node_modules/gauge/progress-bar.js +29 -219
  118. package/node_modules/gauge/render-template.js +181 -0
  119. package/node_modules/gauge/set-immediate.js +7 -0
  120. package/node_modules/gauge/set-interval.js +3 -0
  121. package/node_modules/gauge/spin.js +5 -0
  122. package/node_modules/gauge/template-item.js +73 -0
  123. package/node_modules/gauge/theme-set.js +115 -0
  124. package/node_modules/gauge/themes.js +54 -0
  125. package/node_modules/gauge/wide-truncate.js +25 -0
  126. package/node_modules/generate-function/package.json +20 -2
  127. package/node_modules/generate-object-property/package.json +20 -2
  128. package/node_modules/getpass/.npmignore +8 -0
  129. package/node_modules/getpass/.travis.yml +9 -0
  130. package/node_modules/getpass/LICENSE +18 -0
  131. package/node_modules/getpass/README.md +32 -0
  132. package/node_modules/getpass/lib/index.js +123 -0
  133. package/node_modules/getpass/node_modules/assert-plus/AUTHORS +6 -0
  134. package/node_modules/getpass/node_modules/assert-plus/CHANGES.md +14 -0
  135. package/node_modules/getpass/node_modules/assert-plus/README.md +162 -0
  136. package/node_modules/getpass/node_modules/assert-plus/assert.js +211 -0
  137. package/node_modules/getpass/node_modules/assert-plus/package.json +107 -0
  138. package/node_modules/getpass/package.json +82 -0
  139. package/node_modules/glob/changelog.md +67 -0
  140. package/node_modules/{rimraf/node_modules/glob → glob}/glob.js +2 -1
  141. package/node_modules/glob/package.json +103 -0
  142. package/node_modules/{rimraf/node_modules/glob → glob}/sync.js +2 -1
  143. package/node_modules/graceful-fs/LICENSE +15 -0
  144. package/node_modules/graceful-fs/README.md +82 -2
  145. package/node_modules/graceful-fs/package.json +30 -12
  146. package/node_modules/graceful-readlink/package.json +20 -2
  147. package/node_modules/har-validator/LICENSE +13 -0
  148. package/node_modules/har-validator/package.json +20 -2
  149. package/node_modules/has-ansi/license +21 -0
  150. package/node_modules/has-ansi/package.json +20 -2
  151. package/node_modules/has-color/index.js +32 -0
  152. package/node_modules/has-color/package.json +97 -0
  153. package/node_modules/has-color/readme.md +30 -0
  154. package/node_modules/has-unicode/index.js +3 -8
  155. package/node_modules/has-unicode/package.json +36 -12
  156. package/node_modules/hawk/package.json +20 -2
  157. package/node_modules/hoek/package.json +20 -2
  158. package/node_modules/http-signature/package.json +20 -2
  159. package/node_modules/inflight/package.json +97 -0
  160. package/node_modules/inherits/package.json +16 -9
  161. package/node_modules/ini/package.json +21 -4
  162. package/node_modules/is-fullwidth-code-point/index.js +46 -0
  163. package/node_modules/is-fullwidth-code-point/license +21 -0
  164. package/node_modules/is-fullwidth-code-point/package.json +100 -0
  165. package/node_modules/is-fullwidth-code-point/readme.md +39 -0
  166. package/node_modules/is-my-json-valid/package.json +21 -4
  167. package/node_modules/is-property/package.json +20 -2
  168. package/node_modules/is-typedarray/package.json +20 -2
  169. package/node_modules/isarray/package.json +21 -2
  170. package/node_modules/isstream/package.json +20 -2
  171. package/node_modules/jodid25519/package.json +19 -1
  172. package/node_modules/jsbn/package.json +19 -1
  173. package/node_modules/json-schema/package.json +20 -2
  174. package/node_modules/json-stringify-safe/package.json +20 -2
  175. package/node_modules/jsonpointer/package.json +19 -1
  176. package/node_modules/jsprim/CHANGES.md +5 -0
  177. package/node_modules/jsprim/README.md +13 -4
  178. package/node_modules/jsprim/lib/jsprim.js +12 -2
  179. package/node_modules/jsprim/package.json +33 -11
  180. package/node_modules/mime-db/HISTORY.md +21 -0
  181. package/node_modules/mime-db/db.json +53 -1
  182. package/node_modules/mime-db/package.json +36 -19
  183. package/node_modules/mime-types/HISTORY.md +6 -0
  184. package/node_modules/mime-types/package.json +33 -16
  185. package/node_modules/{fstream-ignore/node_modules/minimatch → minimatch}/README.md +2 -9
  186. package/node_modules/{fstream-ignore/node_modules/minimatch → minimatch}/minimatch.js +15 -3
  187. package/node_modules/{rimraf/node_modules/glob/node_modules/minimatch → minimatch}/package.json +37 -14
  188. package/node_modules/mkdirp/package.json +10 -8
  189. package/node_modules/ms/History.md +66 -0
  190. package/node_modules/ms/package.json +19 -1
  191. package/node_modules/node-pre-gyp/CHANGELOG.md +21 -0
  192. package/node_modules/node-pre-gyp/appveyor.yml +2 -2
  193. package/node_modules/node-pre-gyp/lib/install.js +12 -2
  194. package/node_modules/node-pre-gyp/lib/testbinary.js +9 -9
  195. package/node_modules/node-pre-gyp/lib/util/abi_crosswalk.json +84 -0
  196. package/node_modules/node-pre-gyp/package.json +21 -31
  197. package/node_modules/node-uuid/package.json +20 -2
  198. package/node_modules/{node-pre-gyp/node_modules/nopt → nopt}/package.json +21 -3
  199. package/node_modules/npmlog/CHANGELOG.md +36 -0
  200. package/node_modules/npmlog/CHANGELOG.md~ +31 -0
  201. package/node_modules/npmlog/README.md +16 -1
  202. package/node_modules/npmlog/log.js +97 -50
  203. package/node_modules/npmlog/package.json +43 -17
  204. package/node_modules/number-is-nan/index.js +4 -0
  205. package/node_modules/number-is-nan/license +21 -0
  206. package/node_modules/number-is-nan/package.json +94 -0
  207. package/node_modules/number-is-nan/readme.md +30 -0
  208. package/node_modules/oauth-sign/package.json +36 -12
  209. package/node_modules/object-assign/index.js +83 -0
  210. package/node_modules/object-assign/license +21 -0
  211. package/node_modules/object-assign/package.json +106 -0
  212. package/node_modules/object-assign/readme.md +56 -0
  213. package/node_modules/once/package.json +22 -2
  214. package/node_modules/path-is-absolute/license +21 -0
  215. package/node_modules/{rimraf/node_modules/glob/node_modules/path-is-absolute → path-is-absolute}/package.json +22 -4
  216. package/node_modules/pinkie/license +21 -0
  217. package/node_modules/pinkie/package.json +21 -4
  218. package/node_modules/pinkie-promise/index.js +1 -1
  219. package/node_modules/pinkie-promise/license +21 -0
  220. package/node_modules/pinkie-promise/package.json +32 -10
  221. package/node_modules/process-nextick-args/index.js +31 -8
  222. package/node_modules/process-nextick-args/package.json +33 -10
  223. package/node_modules/qs/.eslintrc +5 -3
  224. package/node_modules/qs/.jscs.json +176 -0
  225. package/node_modules/qs/CHANGELOG.md +10 -0
  226. package/node_modules/qs/dist/qs.js +75 -63
  227. package/node_modules/qs/lib/parse.js +32 -29
  228. package/node_modules/qs/lib/stringify.js +37 -30
  229. package/node_modules/qs/lib/utils.js +6 -4
  230. package/node_modules/qs/package.json +41 -18
  231. package/node_modules/qs/test/parse.js +30 -0
  232. package/node_modules/qs/test/stringify.js +70 -0
  233. package/node_modules/rc/node_modules/minimist/package.json +20 -2
  234. package/node_modules/rc/package.json +21 -4
  235. package/node_modules/readable-stream/.npmignore +4 -1
  236. package/node_modules/readable-stream/.travis.yml +2 -0
  237. package/node_modules/readable-stream/README.md +2 -2
  238. package/node_modules/readable-stream/doc/stream.md +1772 -0
  239. package/node_modules/readable-stream/lib/_stream_readable.js +33 -20
  240. package/node_modules/readable-stream/lib/_stream_transform.js +3 -3
  241. package/node_modules/readable-stream/lib/_stream_writable.js +25 -15
  242. package/node_modules/readable-stream/package.json +44 -15
  243. package/node_modules/readable-stream/readable.js +4 -0
  244. package/node_modules/request/.eslintrc +1 -1
  245. package/node_modules/request/.travis.yml +9 -3
  246. package/node_modules/request/CHANGELOG.md +46 -8
  247. package/node_modules/request/CONTRIBUTING.md +41 -4
  248. package/node_modules/request/README.md +9 -6
  249. package/node_modules/request/codecov.yml +2 -0
  250. package/node_modules/request/index.js +6 -5
  251. package/node_modules/request/lib/helpers.js +3 -3
  252. package/node_modules/request/package.json +52 -30
  253. package/node_modules/request/request.js +58 -43
  254. package/node_modules/rimraf/package.json +33 -16
  255. package/node_modules/rimraf/rimraf.js +10 -2
  256. package/node_modules/semver/README.md +27 -8
  257. package/node_modules/semver/package.json +38 -12
  258. package/node_modules/semver/range.bnf +1 -1
  259. package/node_modules/semver/semver.js +7 -1
  260. package/node_modules/set-blocking/CHANGELOG.md +26 -0
  261. package/node_modules/set-blocking/LICENSE.txt +14 -0
  262. package/node_modules/set-blocking/README.md +31 -0
  263. package/node_modules/set-blocking/index.js +7 -0
  264. package/node_modules/set-blocking/package.json +98 -0
  265. package/node_modules/signal-exit/CHANGELOG.md +17 -0
  266. package/node_modules/signal-exit/LICENSE.txt +14 -0
  267. package/node_modules/signal-exit/README.md +40 -0
  268. package/node_modules/signal-exit/index.js +148 -0
  269. package/node_modules/signal-exit/package.json +98 -0
  270. package/node_modules/signal-exit/signals.js +52 -0
  271. package/node_modules/sntp/package.json +20 -2
  272. package/node_modules/sshpk/.travis.yml +3 -3
  273. package/node_modules/sshpk/README.md +26 -7
  274. package/node_modules/sshpk/bin/sshpk-conv +14 -2
  275. package/node_modules/sshpk/bin/sshpk-sign +16 -1
  276. package/node_modules/sshpk/lib/errors.js +14 -1
  277. package/node_modules/sshpk/lib/formats/auto.js +8 -8
  278. package/node_modules/sshpk/lib/formats/pem.js +39 -5
  279. package/node_modules/sshpk/lib/formats/pkcs1.js +4 -4
  280. package/node_modules/sshpk/lib/formats/pkcs8.js +4 -4
  281. package/node_modules/sshpk/lib/formats/rfc4253.js +2 -2
  282. package/node_modules/sshpk/lib/formats/ssh-private.js +3 -3
  283. package/node_modules/sshpk/lib/formats/ssh.js +2 -2
  284. package/node_modules/sshpk/lib/index.js +2 -1
  285. package/node_modules/sshpk/lib/key.js +20 -17
  286. package/node_modules/sshpk/lib/private-key.js +19 -12
  287. package/node_modules/sshpk/lib/utils.js +40 -1
  288. package/node_modules/sshpk/node_modules/assert-plus/AUTHORS +6 -0
  289. package/node_modules/sshpk/node_modules/assert-plus/CHANGES.md +14 -0
  290. package/node_modules/sshpk/node_modules/assert-plus/README.md +162 -0
  291. package/node_modules/sshpk/node_modules/assert-plus/assert.js +211 -0
  292. package/node_modules/sshpk/node_modules/assert-plus/package.json +107 -0
  293. package/node_modules/sshpk/package.json +48 -30
  294. package/node_modules/string-width/index.js +32 -0
  295. package/node_modules/string-width/license +21 -0
  296. package/node_modules/string-width/package.json +111 -0
  297. package/node_modules/string-width/readme.md +41 -0
  298. package/node_modules/string_decoder/package.json +21 -2
  299. package/node_modules/stringstream/package.json +20 -2
  300. package/node_modules/strip-ansi/license +21 -0
  301. package/node_modules/strip-ansi/package.json +24 -5
  302. package/node_modules/strip-json-comments/license +21 -0
  303. package/node_modules/strip-json-comments/package.json +20 -2
  304. package/node_modules/supports-color/license +21 -0
  305. package/node_modules/supports-color/package.json +20 -2
  306. package/node_modules/tar/package.json +20 -2
  307. package/node_modules/tar-pack/package.json +34 -17
  308. package/node_modules/tough-cookie/LICENSE +27 -0
  309. package/node_modules/tough-cookie/package.json +21 -4
  310. package/node_modules/tunnel-agent/package.json +35 -10
  311. package/node_modules/tweetnacl/CHANGELOG.md +0 -53
  312. package/node_modules/tweetnacl/README.md +42 -24
  313. package/node_modules/tweetnacl/nacl-fast.js +52 -22
  314. package/node_modules/tweetnacl/nacl-fast.min.js +2 -2
  315. package/node_modules/tweetnacl/nacl.js +51 -21
  316. package/node_modules/tweetnacl/nacl.min.js +1 -1
  317. package/node_modules/tweetnacl/package.json +56 -30
  318. package/node_modules/uid-number/package.json +21 -4
  319. package/node_modules/util-deprecate/package.json +21 -2
  320. package/node_modules/verror/package.json +20 -3
  321. package/node_modules/wide-align/.npmignore +5 -0
  322. package/node_modules/wide-align/LICENSE +14 -0
  323. package/node_modules/wide-align/README.md +47 -0
  324. package/node_modules/wide-align/align.js +65 -0
  325. package/node_modules/wide-align/package.json +85 -0
  326. package/node_modules/wide-align/test/align.js +37 -0
  327. package/node_modules/wrappy/package.json +44 -14
  328. package/node_modules/xtend/package.json +20 -2
  329. package/package.json +2 -2
  330. package/node_modules/ansi/.jshintrc +0 -4
  331. package/node_modules/ansi/History.md +0 -23
  332. package/node_modules/ansi/LICENSE +0 -24
  333. package/node_modules/ansi/README.md +0 -98
  334. package/node_modules/ansi/examples/beep/index.js +0 -16
  335. package/node_modules/ansi/examples/clear/index.js +0 -15
  336. package/node_modules/ansi/examples/cursorPosition.js +0 -32
  337. package/node_modules/ansi/examples/progress/index.js +0 -87
  338. package/node_modules/ansi/lib/ansi.js +0 -405
  339. package/node_modules/ansi/lib/newlines.js +0 -71
  340. package/node_modules/ansi/package.json +0 -69
  341. package/node_modules/aws4/node_modules/lru-cache/README.md +0 -142
  342. package/node_modules/aws4/node_modules/lru-cache/lib/lru-cache.js +0 -469
  343. package/node_modules/aws4/node_modules/lru-cache/node_modules/pseudomap/README.md +0 -60
  344. package/node_modules/aws4/node_modules/lru-cache/node_modules/pseudomap/map.js +0 -9
  345. package/node_modules/aws4/node_modules/lru-cache/node_modules/pseudomap/package.json +0 -60
  346. package/node_modules/aws4/node_modules/lru-cache/node_modules/pseudomap/pseudomap.js +0 -113
  347. package/node_modules/aws4/node_modules/lru-cache/node_modules/pseudomap/test/basic.js +0 -86
  348. package/node_modules/aws4/node_modules/lru-cache/node_modules/yallist/.npmignore +0 -4
  349. package/node_modules/aws4/node_modules/lru-cache/node_modules/yallist/.travis.yml +0 -7
  350. package/node_modules/aws4/node_modules/lru-cache/node_modules/yallist/CONTRIBUTING.md +0 -4
  351. package/node_modules/aws4/node_modules/lru-cache/node_modules/yallist/README.md +0 -204
  352. package/node_modules/aws4/node_modules/lru-cache/node_modules/yallist/package.json +0 -60
  353. package/node_modules/aws4/node_modules/lru-cache/node_modules/yallist/test/basic.js +0 -188
  354. package/node_modules/aws4/node_modules/lru-cache/node_modules/yallist/yallist.js +0 -360
  355. package/node_modules/aws4/node_modules/lru-cache/package.json +0 -78
  356. package/node_modules/block-stream/bench/block-stream-pause.js +0 -70
  357. package/node_modules/block-stream/bench/block-stream.js +0 -68
  358. package/node_modules/block-stream/bench/dropper-pause.js +0 -70
  359. package/node_modules/block-stream/bench/dropper.js +0 -68
  360. package/node_modules/block-stream/test/basic.js +0 -27
  361. package/node_modules/block-stream/test/nopad-thorough.js +0 -68
  362. package/node_modules/block-stream/test/nopad.js +0 -57
  363. package/node_modules/block-stream/test/pause-resume.js +0 -73
  364. package/node_modules/block-stream/test/thorough.js +0 -68
  365. package/node_modules/block-stream/test/two-stream.js +0 -59
  366. package/node_modules/fstream-ignore/.npmignore +0 -1
  367. package/node_modules/fstream-ignore/example/basic.js +0 -13
  368. package/node_modules/fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/.npmignore +0 -3
  369. package/node_modules/fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/example.js +0 -8
  370. package/node_modules/fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/.npmignore +0 -2
  371. package/node_modules/fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/.travis.yml +0 -3
  372. package/node_modules/fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/Makefile +0 -6
  373. package/node_modules/fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/README.md +0 -89
  374. package/node_modules/fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/example.js +0 -5
  375. package/node_modules/fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/package.json +0 -80
  376. package/node_modules/fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/test/balanced.js +0 -84
  377. package/node_modules/fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/package.json +0 -91
  378. package/node_modules/fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/package.json +0 -86
  379. package/node_modules/fstream-ignore/node_modules/minimatch/package.json +0 -67
  380. package/node_modules/fstream-ignore/test/.ignore +0 -2
  381. package/node_modules/fstream-ignore/test/.npmignore +0 -1
  382. package/node_modules/fstream-ignore/test/00-setup.js +0 -71
  383. package/node_modules/fstream-ignore/test/basic.js +0 -28
  384. package/node_modules/fstream-ignore/test/common.js +0 -40
  385. package/node_modules/fstream-ignore/test/ignore-most.js +0 -41
  386. package/node_modules/fstream-ignore/test/nested-ignores.js +0 -51
  387. package/node_modules/fstream-ignore/test/read-file-order.js +0 -81
  388. package/node_modules/fstream-ignore/test/unignore-child.js +0 -38
  389. package/node_modules/fstream-ignore/test/zz-cleanup.js +0 -10
  390. package/node_modules/gauge/.npmignore +0 -32
  391. package/node_modules/gauge/example.png +0 -0
  392. package/node_modules/gauge/test/progress-bar.js +0 -176
  393. package/node_modules/has-unicode/.npmignore +0 -32
  394. package/node_modules/has-unicode/test/index.js +0 -26
  395. package/node_modules/lodash.pad/README.md +0 -18
  396. package/node_modules/lodash.pad/index.js +0 -296
  397. package/node_modules/lodash.pad/package.json +0 -91
  398. package/node_modules/lodash.padend/README.md +0 -18
  399. package/node_modules/lodash.padend/index.js +0 -285
  400. package/node_modules/lodash.padend/package.json +0 -91
  401. package/node_modules/lodash.padstart/README.md +0 -18
  402. package/node_modules/lodash.padstart/index.js +0 -285
  403. package/node_modules/lodash.padstart/package.json +0 -91
  404. package/node_modules/lodash.repeat/README.md +0 -18
  405. package/node_modules/lodash.repeat/index.js +0 -215
  406. package/node_modules/lodash.repeat/package.json +0 -92
  407. package/node_modules/lodash.tostring/LICENSE +0 -23
  408. package/node_modules/lodash.tostring/README.md +0 -18
  409. package/node_modules/lodash.tostring/index.js +0 -164
  410. package/node_modules/lodash.tostring/package.json +0 -91
  411. package/node_modules/node-pre-gyp/README.md +0 -570
  412. package/node_modules/node-pre-gyp/node_modules/nopt/.npmignore +0 -1
  413. package/node_modules/node-pre-gyp/node_modules/nopt/node_modules/abbrev/.npmignore +0 -4
  414. package/node_modules/node-pre-gyp/node_modules/nopt/node_modules/abbrev/.travis.yml +0 -5
  415. package/node_modules/node-pre-gyp/node_modules/nopt/node_modules/abbrev/CONTRIBUTING.md +0 -3
  416. package/node_modules/node-pre-gyp/node_modules/nopt/node_modules/abbrev/package.json +0 -56
  417. package/node_modules/node-pre-gyp/node_modules/nopt/node_modules/abbrev/test.js +0 -47
  418. package/node_modules/npmlog/.nyc_output/64996.json +0 -1
  419. package/node_modules/npmlog/.nyc_output/64998.json +0 -1
  420. package/node_modules/npmlog/.nyc_output/65000.json +0 -1
  421. package/node_modules/npmlog/.travis.yml +0 -14
  422. package/node_modules/npmlog/example.js +0 -39
  423. package/node_modules/npmlog/test/basic.js +0 -235
  424. package/node_modules/npmlog/test/progress.js +0 -131
  425. package/node_modules/oauth-sign/test.js +0 -89
  426. package/node_modules/qs/.npmignore +0 -18
  427. package/node_modules/qs/.travis.yml +0 -69
  428. package/node_modules/qs/README.md +0 -335
  429. package/node_modules/qs/bower.json +0 -22
  430. package/node_modules/qs/component.json +0 -15
  431. package/node_modules/rimraf/node_modules/glob/node_modules/inflight/.eslintrc +0 -17
  432. package/node_modules/rimraf/node_modules/glob/node_modules/inflight/node_modules/wrappy/README.md +0 -36
  433. package/node_modules/rimraf/node_modules/glob/node_modules/inflight/node_modules/wrappy/package.json +0 -59
  434. package/node_modules/rimraf/node_modules/glob/node_modules/inflight/node_modules/wrappy/test/basic.js +0 -51
  435. package/node_modules/rimraf/node_modules/glob/node_modules/inflight/node_modules/wrappy/wrappy.js +0 -33
  436. package/node_modules/rimraf/node_modules/glob/node_modules/inflight/package.json +0 -68
  437. package/node_modules/rimraf/node_modules/glob/node_modules/inflight/test.js +0 -97
  438. package/node_modules/rimraf/node_modules/glob/node_modules/inherits/LICENSE +0 -16
  439. package/node_modules/rimraf/node_modules/glob/node_modules/inherits/README.md +0 -42
  440. package/node_modules/rimraf/node_modules/glob/node_modules/inherits/inherits.js +0 -1
  441. package/node_modules/rimraf/node_modules/glob/node_modules/inherits/inherits_browser.js +0 -23
  442. package/node_modules/rimraf/node_modules/glob/node_modules/inherits/package.json +0 -59
  443. package/node_modules/rimraf/node_modules/glob/node_modules/inherits/test.js +0 -25
  444. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/README.md +0 -216
  445. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/minimatch.js +0 -912
  446. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/README.md +0 -122
  447. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/example.js +0 -8
  448. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/index.js +0 -191
  449. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/.npmignore +0 -2
  450. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/.travis.yml +0 -3
  451. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/LICENSE.md +0 -21
  452. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/Makefile +0 -6
  453. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/example.js +0 -5
  454. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/index.js +0 -50
  455. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/test/balanced.js +0 -84
  456. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/.travis.yml +0 -4
  457. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/README.markdown +0 -62
  458. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/example/map.js +0 -6
  459. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/index.js +0 -13
  460. package/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/test/map.js +0 -39
  461. package/node_modules/rimraf/node_modules/glob/node_modules/once/README.md +0 -51
  462. package/node_modules/rimraf/node_modules/glob/node_modules/once/node_modules/wrappy/README.md +0 -36
  463. package/node_modules/rimraf/node_modules/glob/node_modules/once/node_modules/wrappy/package.json +0 -59
  464. package/node_modules/rimraf/node_modules/glob/node_modules/once/node_modules/wrappy/test/basic.js +0 -51
  465. package/node_modules/rimraf/node_modules/glob/node_modules/once/node_modules/wrappy/wrappy.js +0 -33
  466. package/node_modules/rimraf/node_modules/glob/node_modules/once/once.js +0 -21
  467. package/node_modules/rimraf/node_modules/glob/node_modules/once/package.json +0 -71
  468. package/node_modules/rimraf/node_modules/glob/package.json +0 -85
  469. package/node_modules/semver/.npmignore +0 -4
  470. package/node_modules/semver/.travis.yml +0 -5
  471. package/node_modules/semver/test/big-numbers.js +0 -31
  472. package/node_modules/semver/test/clean.js +0 -29
  473. package/node_modules/semver/test/gtr.js +0 -173
  474. package/node_modules/semver/test/index.js +0 -698
  475. package/node_modules/semver/test/ltr.js +0 -181
  476. package/node_modules/semver/test/major-minor-patch.js +0 -72
  477. package/node_modules/tunnel-agent/.jshintrc +0 -5
  478. package/node_modules/tweetnacl/COPYING.txt +0 -9
  479. package/node_modules/wrappy/test/basic.js +0 -51
  480. package/test/fsevents.js +0 -27
  481. package/test/function.js +0 -93
  482. /package/node_modules/{aws4/node_modules/lru-cache/node_modules/pseudomap → abbrev}/LICENSE +0 -0
  483. /package/node_modules/{node-pre-gyp/node_modules/nopt/node_modules/abbrev → abbrev}/README.md +0 -0
  484. /package/node_modules/{node-pre-gyp/node_modules/nopt/node_modules/abbrev → abbrev}/abbrev.js +0 -0
  485. /package/node_modules/{fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match → balanced-match}/LICENSE.md +0 -0
  486. /package/node_modules/{readable-stream → bl/node_modules/readable-stream}/.zuul.yml +0 -0
  487. /package/node_modules/{readable-stream → bl/node_modules/readable-stream}/doc/stream.markdown +0 -0
  488. /package/node_modules/{fstream-ignore/node_modules/minimatch/node_modules/brace-expansion → brace-expansion}/README.md +0 -0
  489. /package/node_modules/{fstream-ignore/node_modules/minimatch/node_modules/brace-expansion → brace-expansion}/index.js +0 -0
  490. /package/node_modules/{fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → concat-map}/.travis.yml +0 -0
  491. /package/node_modules/{fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → concat-map}/LICENSE +0 -0
  492. /package/node_modules/{fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → concat-map}/README.markdown +0 -0
  493. /package/node_modules/{fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → concat-map}/example/map.js +0 -0
  494. /package/node_modules/{fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → concat-map}/index.js +0 -0
  495. /package/node_modules/{fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → concat-map}/test/map.js +0 -0
  496. /package/node_modules/{aws4/node_modules/lru-cache/node_modules/yallist → glob}/LICENSE +0 -0
  497. /package/node_modules/{rimraf/node_modules/glob → glob}/README.md +0 -0
  498. /package/node_modules/{rimraf/node_modules/glob → glob}/common.js +0 -0
  499. /package/node_modules/{rimraf/node_modules/glob/node_modules/inflight → inflight}/LICENSE +0 -0
  500. /package/node_modules/{rimraf/node_modules/glob/node_modules/inflight → inflight}/README.md +0 -0
  501. /package/node_modules/{rimraf/node_modules/glob/node_modules/inflight → inflight}/inflight.js +0 -0
  502. /package/node_modules/{node-pre-gyp/node_modules/nopt → ini}/LICENSE +0 -0
  503. /package/node_modules/{node-pre-gyp/node_modules/nopt/node_modules/abbrev → minimatch}/LICENSE +0 -0
  504. /package/node_modules/{ansi → nopt}/.npmignore +0 -0
  505. /package/node_modules/{node-pre-gyp/node_modules/nopt → nopt}/.travis.yml +0 -0
  506. /package/node_modules/{rimraf/node_modules/glob/node_modules/inflight/node_modules/wrappy → nopt}/LICENSE +0 -0
  507. /package/node_modules/{node-pre-gyp/node_modules/nopt → nopt}/README.md +0 -0
  508. /package/node_modules/{node-pre-gyp/node_modules/nopt → nopt}/bin/nopt.js +0 -0
  509. /package/node_modules/{node-pre-gyp/node_modules/nopt → nopt}/examples/my-program.js +0 -0
  510. /package/node_modules/{node-pre-gyp/node_modules/nopt → nopt}/lib/nopt.js +0 -0
  511. /package/node_modules/{node-pre-gyp/node_modules/nopt → nopt}/test/basic.js +0 -0
  512. /package/node_modules/{rimraf/node_modules/glob/node_modules/once/node_modules/wrappy → once}/LICENSE +0 -0
  513. /package/node_modules/{rimraf/node_modules/glob/node_modules/path-is-absolute → path-is-absolute}/index.js +0 -0
  514. /package/node_modules/{rimraf/node_modules/glob/node_modules/path-is-absolute → path-is-absolute}/readme.md +0 -0
@@ -0,0 +1,1772 @@
1
+ # Stream
2
+
3
+ Stability: 2 - Stable
4
+
5
+ A stream is an abstract interface implemented by various objects in
6
+ Node.js. For example a [request to an HTTP server][http-incoming-message] is a
7
+ stream, as is [`process.stdout`][]. Streams are readable, writable, or both. All
8
+ streams are instances of [`EventEmitter`][].
9
+
10
+ You can load the Stream base classes by doing `require('stream')`.
11
+ There are base classes provided for [Readable][] streams, [Writable][]
12
+ streams, [Duplex][] streams, and [Transform][] streams.
13
+
14
+ This document is split up into 3 sections:
15
+
16
+ 1. The first section explains the parts of the API that you need to be
17
+ aware of to use streams in your programs.
18
+ 2. The second section explains the parts of the API that you need to
19
+ use if you implement your own custom streams yourself. The API is designed to
20
+ make this easy for you to do.
21
+ 3. The third section goes into more depth about how streams work,
22
+ including some of the internal mechanisms and functions that you
23
+ should probably not modify unless you definitely know what you are
24
+ doing.
25
+
26
+
27
+ ## API for Stream Consumers
28
+
29
+ <!--type=misc-->
30
+
31
+ Streams can be either [Readable][], [Writable][], or both ([Duplex][]).
32
+
33
+ All streams are EventEmitters, but they also have other custom methods
34
+ and properties depending on whether they are Readable, Writable, or
35
+ Duplex.
36
+
37
+ If a stream is both Readable and Writable, then it implements all of
38
+ the methods and events. So, a [Duplex][] or [Transform][] stream is
39
+ fully described by this API, though their implementation may be
40
+ somewhat different.
41
+
42
+ It is not necessary to implement Stream interfaces in order to consume
43
+ streams in your programs. If you **are** implementing streaming
44
+ interfaces in your own program, please also refer to
45
+ [API for Stream Implementors][].
46
+
47
+ Almost all Node.js programs, no matter how simple, use Streams in some
48
+ way. Here is an example of using Streams in an Node.js program:
49
+
50
+ ```js
51
+ const http = require('http');
52
+
53
+ var server = http.createServer( (req, res) => {
54
+ // req is an http.IncomingMessage, which is a Readable Stream
55
+ // res is an http.ServerResponse, which is a Writable Stream
56
+
57
+ var body = '';
58
+ // we want to get the data as utf8 strings
59
+ // If you don't set an encoding, then you'll get Buffer objects
60
+ req.setEncoding('utf8');
61
+
62
+ // Readable streams emit 'data' events once a listener is added
63
+ req.on('data', (chunk) => {
64
+ body += chunk;
65
+ });
66
+
67
+ // the end event tells you that you have entire body
68
+ req.on('end', () => {
69
+ try {
70
+ var data = JSON.parse(body);
71
+ } catch (er) {
72
+ // uh oh! bad json!
73
+ res.statusCode = 400;
74
+ return res.end(`error: ${er.message}`);
75
+ }
76
+
77
+ // write back something interesting to the user:
78
+ res.write(typeof data);
79
+ res.end();
80
+ });
81
+ });
82
+
83
+ server.listen(1337);
84
+
85
+ // $ curl localhost:1337 -d '{}'
86
+ // object
87
+ // $ curl localhost:1337 -d '"foo"'
88
+ // string
89
+ // $ curl localhost:1337 -d 'not json'
90
+ // error: Unexpected token o
91
+ ```
92
+
93
+ ### Class: stream.Duplex
94
+
95
+ Duplex streams are streams that implement both the [Readable][] and
96
+ [Writable][] interfaces.
97
+
98
+ Examples of Duplex streams include:
99
+
100
+ * [TCP sockets][]
101
+ * [zlib streams][zlib]
102
+ * [crypto streams][crypto]
103
+
104
+ ### Class: stream.Readable
105
+
106
+ <!--type=class-->
107
+
108
+ The Readable stream interface is the abstraction for a *source* of
109
+ data that you are reading from. In other words, data comes *out* of a
110
+ Readable stream.
111
+
112
+ A Readable stream will not start emitting data until you indicate that
113
+ you are ready to receive it.
114
+
115
+ Readable streams have two "modes": a **flowing mode** and a **paused
116
+ mode**. When in flowing mode, data is read from the underlying system
117
+ and provided to your program as fast as possible. In paused mode, you
118
+ must explicitly call [`stream.read()`][stream-read] to get chunks of data out.
119
+ Streams start out in paused mode.
120
+
121
+ **Note**: If no data event handlers are attached, and there are no
122
+ [`stream.pipe()`][] destinations, and the stream is switched into flowing
123
+ mode, then data will be lost.
124
+
125
+ You can switch to flowing mode by doing any of the following:
126
+
127
+ * Adding a [`'data'`][] event handler to listen for data.
128
+ * Calling the [`stream.resume()`][stream-resume] method to explicitly open the
129
+ flow.
130
+ * Calling the [`stream.pipe()`][] method to send the data to a [Writable][].
131
+
132
+ You can switch back to paused mode by doing either of the following:
133
+
134
+ * If there are no pipe destinations, by calling the
135
+ [`stream.pause()`][stream-pause] method.
136
+ * If there are pipe destinations, by removing any [`'data'`][] event
137
+ handlers, and removing all pipe destinations by calling the
138
+ [`stream.unpipe()`][] method.
139
+
140
+ Note that, for backwards compatibility reasons, removing [`'data'`][]
141
+ event handlers will **not** automatically pause the stream. Also, if
142
+ there are piped destinations, then calling [`stream.pause()`][stream-pause] will
143
+ not guarantee that the stream will *remain* paused once those
144
+ destinations drain and ask for more data.
145
+
146
+ Examples of readable streams include:
147
+
148
+ * [HTTP responses, on the client][http-incoming-message]
149
+ * [HTTP requests, on the server][http-incoming-message]
150
+ * [fs read streams][]
151
+ * [zlib streams][zlib]
152
+ * [crypto streams][crypto]
153
+ * [TCP sockets][]
154
+ * [child process stdout and stderr][]
155
+ * [`process.stdin`][]
156
+
157
+ #### Event: 'close'
158
+
159
+ Emitted when the stream and any of its underlying resources (a file
160
+ descriptor, for example) have been closed. The event indicates that
161
+ no more events will be emitted, and no further computation will occur.
162
+
163
+ Not all streams will emit the `'close'` event as the `'close'` event is
164
+ optional.
165
+
166
+ #### Event: 'data'
167
+
168
+ * `chunk` {Buffer|String} The chunk of data.
169
+
170
+ Attaching a `'data'` event listener to a stream that has not been
171
+ explicitly paused will switch the stream into flowing mode. Data will
172
+ then be passed as soon as it is available.
173
+
174
+ If you just want to get all the data out of the stream as fast as
175
+ possible, this is the best way to do so.
176
+
177
+ ```js
178
+ var readable = getReadableStreamSomehow();
179
+ readable.on('data', (chunk) => {
180
+ console.log('got %d bytes of data', chunk.length);
181
+ });
182
+ ```
183
+
184
+ #### Event: 'end'
185
+
186
+ This event fires when there will be no more data to read.
187
+
188
+ Note that the `'end'` event **will not fire** unless the data is
189
+ completely consumed. This can be done by switching into flowing mode,
190
+ or by calling [`stream.read()`][stream-read] repeatedly until you get to the
191
+ end.
192
+
193
+ ```js
194
+ var readable = getReadableStreamSomehow();
195
+ readable.on('data', (chunk) => {
196
+ console.log('got %d bytes of data', chunk.length);
197
+ });
198
+ readable.on('end', () => {
199
+ console.log('there will be no more data.');
200
+ });
201
+ ```
202
+
203
+ #### Event: 'error'
204
+
205
+ * {Error}
206
+
207
+ Emitted if there was an error receiving data.
208
+
209
+ #### Event: 'readable'
210
+
211
+ When a chunk of data can be read from the stream, it will emit a
212
+ `'readable'` event.
213
+
214
+ In some cases, listening for a `'readable'` event will cause some data
215
+ to be read into the internal buffer from the underlying system, if it
216
+ hadn't already.
217
+
218
+ ```javascript
219
+ var readable = getReadableStreamSomehow();
220
+ readable.on('readable', () => {
221
+ // there is some data to read now
222
+ });
223
+ ```
224
+
225
+ Once the internal buffer is drained, a `'readable'` event will fire
226
+ again when more data is available.
227
+
228
+ The `'readable'` event is not emitted in the "flowing" mode with the
229
+ sole exception of the last one, on end-of-stream.
230
+
231
+ The `'readable'` event indicates that the stream has new information:
232
+ either new data is available or the end of the stream has been reached.
233
+ In the former case, [`stream.read()`][stream-read] will return that data. In the
234
+ latter case, [`stream.read()`][stream-read] will return null. For instance, in
235
+ the following example, `foo.txt` is an empty file:
236
+
237
+ ```js
238
+ const fs = require('fs');
239
+ var rr = fs.createReadStream('foo.txt');
240
+ rr.on('readable', () => {
241
+ console.log('readable:', rr.read());
242
+ });
243
+ rr.on('end', () => {
244
+ console.log('end');
245
+ });
246
+ ```
247
+
248
+ The output of running this script is:
249
+
250
+ ```
251
+ $ node test.js
252
+ readable: null
253
+ end
254
+ ```
255
+
256
+ #### readable.isPaused()
257
+
258
+ * Return: {Boolean}
259
+
260
+ This method returns whether or not the `readable` has been **explicitly**
261
+ paused by client code (using [`stream.pause()`][stream-pause] without a
262
+ corresponding [`stream.resume()`][stream-resume]).
263
+
264
+ ```js
265
+ var readable = new stream.Readable
266
+
267
+ readable.isPaused() // === false
268
+ readable.pause()
269
+ readable.isPaused() // === true
270
+ readable.resume()
271
+ readable.isPaused() // === false
272
+ ```
273
+
274
+ #### readable.pause()
275
+
276
+ * Return: `this`
277
+
278
+ This method will cause a stream in flowing mode to stop emitting
279
+ [`'data'`][] events, switching out of flowing mode. Any data that becomes
280
+ available will remain in the internal buffer.
281
+
282
+ ```js
283
+ var readable = getReadableStreamSomehow();
284
+ readable.on('data', (chunk) => {
285
+ console.log('got %d bytes of data', chunk.length);
286
+ readable.pause();
287
+ console.log('there will be no more data for 1 second');
288
+ setTimeout(() => {
289
+ console.log('now data will start flowing again');
290
+ readable.resume();
291
+ }, 1000);
292
+ });
293
+ ```
294
+
295
+ #### readable.pipe(destination[, options])
296
+
297
+ * `destination` {stream.Writable} The destination for writing data
298
+ * `options` {Object} Pipe options
299
+ * `end` {Boolean} End the writer when the reader ends. Default = `true`
300
+
301
+ This method pulls all the data out of a readable stream, and writes it
302
+ to the supplied destination, automatically managing the flow so that
303
+ the destination is not overwhelmed by a fast readable stream.
304
+
305
+ Multiple destinations can be piped to safely.
306
+
307
+ ```js
308
+ var readable = getReadableStreamSomehow();
309
+ var writable = fs.createWriteStream('file.txt');
310
+ // All the data from readable goes into 'file.txt'
311
+ readable.pipe(writable);
312
+ ```
313
+
314
+ This function returns the destination stream, so you can set up pipe
315
+ chains like so:
316
+
317
+ ```js
318
+ var r = fs.createReadStream('file.txt');
319
+ var z = zlib.createGzip();
320
+ var w = fs.createWriteStream('file.txt.gz');
321
+ r.pipe(z).pipe(w);
322
+ ```
323
+
324
+ For example, emulating the Unix `cat` command:
325
+
326
+ ```js
327
+ process.stdin.pipe(process.stdout);
328
+ ```
329
+
330
+ By default [`stream.end()`][stream-end] is called on the destination when the
331
+ source stream emits [`'end'`][], so that `destination` is no longer writable.
332
+ Pass `{ end: false }` as `options` to keep the destination stream open.
333
+
334
+ This keeps `writer` open so that "Goodbye" can be written at the
335
+ end.
336
+
337
+ ```js
338
+ reader.pipe(writer, { end: false });
339
+ reader.on('end', () => {
340
+ writer.end('Goodbye\n');
341
+ });
342
+ ```
343
+
344
+ Note that [`process.stderr`][] and [`process.stdout`][] are never closed until
345
+ the process exits, regardless of the specified options.
346
+
347
+ #### readable.read([size])
348
+
349
+ * `size` {Number} Optional argument to specify how much data to read.
350
+ * Return {String|Buffer|Null}
351
+
352
+ The `read()` method pulls some data out of the internal buffer and
353
+ returns it. If there is no data available, then it will return
354
+ `null`.
355
+
356
+ If you pass in a `size` argument, then it will return that many
357
+ bytes. If `size` bytes are not available, then it will return `null`,
358
+ unless we've ended, in which case it will return the data remaining
359
+ in the buffer.
360
+
361
+ If you do not specify a `size` argument, then it will return all the
362
+ data in the internal buffer.
363
+
364
+ This method should only be called in paused mode. In flowing mode,
365
+ this method is called automatically until the internal buffer is
366
+ drained.
367
+
368
+ ```js
369
+ var readable = getReadableStreamSomehow();
370
+ readable.on('readable', () => {
371
+ var chunk;
372
+ while (null !== (chunk = readable.read())) {
373
+ console.log('got %d bytes of data', chunk.length);
374
+ }
375
+ });
376
+ ```
377
+
378
+ If this method returns a data chunk, then it will also trigger the
379
+ emission of a [`'data'`][] event.
380
+
381
+ Note that calling [`stream.read([size])`][stream-read] after the [`'end'`][]
382
+ event has been triggered will return `null`. No runtime error will be raised.
383
+
384
+ #### readable.resume()
385
+
386
+ * Return: `this`
387
+
388
+ This method will cause the readable stream to resume emitting [`'data'`][]
389
+ events.
390
+
391
+ This method will switch the stream into flowing mode. If you do *not*
392
+ want to consume the data from a stream, but you *do* want to get to
393
+ its [`'end'`][] event, you can call [`stream.resume()`][stream-resume] to open
394
+ the flow of data.
395
+
396
+ ```js
397
+ var readable = getReadableStreamSomehow();
398
+ readable.resume();
399
+ readable.on('end', () => {
400
+ console.log('got to the end, but did not read anything');
401
+ });
402
+ ```
403
+
404
+ #### readable.setEncoding(encoding)
405
+
406
+ * `encoding` {String} The encoding to use.
407
+ * Return: `this`
408
+
409
+ Call this function to cause the stream to return strings of the specified
410
+ encoding instead of Buffer objects. For example, if you do
411
+ `readable.setEncoding('utf8')`, then the output data will be interpreted as
412
+ UTF-8 data, and returned as strings. If you do `readable.setEncoding('hex')`,
413
+ then the data will be encoded in 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
+ Also you can disable any encoding at all with `readable.setEncoding(null)`.
421
+ This approach is very useful if you deal with binary data or with large
422
+ multi-byte strings spread out over multiple chunks.
423
+
424
+ ```js
425
+ var readable = getReadableStreamSomehow();
426
+ readable.setEncoding('utf8');
427
+ readable.on('data', (chunk) => {
428
+ assert.equal(typeof chunk, 'string');
429
+ console.log('got %d characters of string data', chunk.length);
430
+ });
431
+ ```
432
+
433
+ #### readable.unpipe([destination])
434
+
435
+ * `destination` {stream.Writable} Optional specific stream to unpipe
436
+
437
+ This method will remove the hooks set up for a previous [`stream.pipe()`][]
438
+ call.
439
+
440
+ If the destination is not specified, then all pipes are removed.
441
+
442
+ If the destination is specified, but no pipe is set up for it, then
443
+ this is a no-op.
444
+
445
+ ```js
446
+ var readable = getReadableStreamSomehow();
447
+ var writable = fs.createWriteStream('file.txt');
448
+ // All the data from readable goes into 'file.txt',
449
+ // but only for the first second
450
+ readable.pipe(writable);
451
+ setTimeout(() => {
452
+ console.log('stop writing to file.txt');
453
+ readable.unpipe(writable);
454
+ console.log('manually close the file stream');
455
+ writable.end();
456
+ }, 1000);
457
+ ```
458
+
459
+ #### readable.unshift(chunk)
460
+
461
+ * `chunk` {Buffer|String} Chunk of data to unshift onto the read queue
462
+
463
+ This is useful in certain cases where a stream is being consumed by a
464
+ parser, which needs to "un-consume" some data that it has
465
+ optimistically pulled out of the source, so that the stream can be
466
+ passed on to some other party.
467
+
468
+ Note that `stream.unshift(chunk)` cannot be called after the [`'end'`][] event
469
+ has been triggered; a runtime error will be raised.
470
+
471
+ If you find that you must often call `stream.unshift(chunk)` in your
472
+ programs, consider implementing a [Transform][] stream instead. (See [API
473
+ for Stream Implementors][].)
474
+
475
+ ```js
476
+ // Pull off a header delimited by \n\n
477
+ // use unshift() if we get too much
478
+ // Call the callback with (error, header, stream)
479
+ const StringDecoder = require('string_decoder').StringDecoder;
480
+ function parseHeader(stream, callback) {
481
+ stream.on('error', callback);
482
+ stream.on('readable', onReadable);
483
+ var decoder = new StringDecoder('utf8');
484
+ var header = '';
485
+ function onReadable() {
486
+ var chunk;
487
+ while (null !== (chunk = stream.read())) {
488
+ var str = decoder.write(chunk);
489
+ if (str.match(/\n\n/)) {
490
+ // found the header boundary
491
+ var split = str.split(/\n\n/);
492
+ header += split.shift();
493
+ var remaining = split.join('\n\n');
494
+ var buf = Buffer.from(remaining, 'utf8');
495
+ if (buf.length)
496
+ stream.unshift(buf);
497
+ stream.removeListener('error', callback);
498
+ stream.removeListener('readable', onReadable);
499
+ // now the body of the message can be read from the stream.
500
+ callback(null, header, stream);
501
+ } else {
502
+ // still reading the header.
503
+ header += str;
504
+ }
505
+ }
506
+ }
507
+ }
508
+ ```
509
+
510
+ Note that, unlike [`stream.push(chunk)`][stream-push], `stream.unshift(chunk)`
511
+ will not end the reading process by resetting the internal reading state of the
512
+ stream. This can cause unexpected results if `unshift()` is called during a
513
+ read (i.e. from within a [`stream._read()`][stream-_read] implementation on a
514
+ custom stream). Following the call to `unshift()` with an immediate
515
+ [`stream.push('')`][stream-push] will reset the reading state appropriately,
516
+ however it is best to simply avoid calling `unshift()` while in the process of
517
+ performing a read.
518
+
519
+ #### readable.wrap(stream)
520
+
521
+ * `stream` {Stream} An "old style" readable stream
522
+
523
+ Versions of Node.js prior to v0.10 had streams that did not implement the
524
+ entire Streams API as it is today. (See [Compatibility][] for
525
+ more information.)
526
+
527
+ If you are using an older Node.js library that emits [`'data'`][] events and
528
+ has a [`stream.pause()`][stream-pause] method that is advisory only, then you
529
+ can use the `wrap()` method to create a [Readable][] stream that uses the old
530
+ stream as its data source.
531
+
532
+ You will very rarely ever need to call this function, but it exists
533
+ as a convenience for interacting with old Node.js programs and libraries.
534
+
535
+ For example:
536
+
537
+ ```js
538
+ const OldReader = require('./old-api-module.js').OldReader;
539
+ const Readable = require('stream').Readable;
540
+ const oreader = new OldReader;
541
+ const myReader = new Readable().wrap(oreader);
542
+
543
+ myReader.on('readable', () => {
544
+ myReader.read(); // etc.
545
+ });
546
+ ```
547
+
548
+ ### Class: stream.Transform
549
+
550
+ Transform streams are [Duplex][] streams where the output is in some way
551
+ computed from the input. They implement both the [Readable][] and
552
+ [Writable][] interfaces.
553
+
554
+ Examples of Transform streams include:
555
+
556
+ * [zlib streams][zlib]
557
+ * [crypto streams][crypto]
558
+
559
+ ### Class: stream.Writable
560
+
561
+ <!--type=class-->
562
+
563
+ The Writable stream interface is an abstraction for a *destination*
564
+ that you are writing data *to*.
565
+
566
+ Examples of writable streams include:
567
+
568
+ * [HTTP requests, on the client][]
569
+ * [HTTP responses, on the server][]
570
+ * [fs write streams][]
571
+ * [zlib streams][zlib]
572
+ * [crypto streams][crypto]
573
+ * [TCP sockets][]
574
+ * [child process stdin][]
575
+ * [`process.stdout`][], [`process.stderr`][]
576
+
577
+ #### Event: 'close'
578
+
579
+ Emitted when the stream and any of its underlying resources (a file descriptor,
580
+ for example) have been closed. The event indicates that no more events will be
581
+ emitted, and no further computation will occur.
582
+
583
+ Not all streams will emit the `'close'` event as the `'close'` event is
584
+ optional.
585
+
586
+ #### Event: 'drain'
587
+
588
+ If a [`stream.write(chunk)`][stream-write] call returns `false`, then the
589
+ `'drain'` event will indicate when it is appropriate to begin writing more data
590
+ to the stream.
591
+
592
+ ```js
593
+ // Write the data to the supplied writable stream one million times.
594
+ // Be attentive to back-pressure.
595
+ function writeOneMillionTimes(writer, data, encoding, callback) {
596
+ var i = 1000000;
597
+ write();
598
+ function write() {
599
+ var ok = true;
600
+ do {
601
+ i -= 1;
602
+ if (i === 0) {
603
+ // last time!
604
+ writer.write(data, encoding, callback);
605
+ } else {
606
+ // see if we should continue, or wait
607
+ // don't pass the callback, because we're not done yet.
608
+ ok = writer.write(data, encoding);
609
+ }
610
+ } while (i > 0 && ok);
611
+ if (i > 0) {
612
+ // had to stop early!
613
+ // write some more once it drains
614
+ writer.once('drain', write);
615
+ }
616
+ }
617
+ }
618
+ ```
619
+
620
+ #### Event: 'error'
621
+
622
+ * {Error}
623
+
624
+ Emitted if there was an error when writing or piping data.
625
+
626
+ #### Event: 'finish'
627
+
628
+ When the [`stream.end()`][stream-end] method has been called, and all data has
629
+ been flushed to the underlying system, this event is emitted.
630
+
631
+ ```javascript
632
+ var writer = getWritableStreamSomehow();
633
+ for (var i = 0; i < 100; i ++) {
634
+ writer.write('hello, #${i}!\n');
635
+ }
636
+ writer.end('this is the end\n');
637
+ writer.on('finish', () => {
638
+ console.error('all writes are now complete.');
639
+ });
640
+ ```
641
+
642
+ #### Event: 'pipe'
643
+
644
+ * `src` {stream.Readable} source stream that is piping to this writable
645
+
646
+ This is emitted whenever the [`stream.pipe()`][] method is called on a readable
647
+ stream, adding this writable to its set of destinations.
648
+
649
+ ```js
650
+ var writer = getWritableStreamSomehow();
651
+ var reader = getReadableStreamSomehow();
652
+ writer.on('pipe', (src) => {
653
+ console.error('something is piping into the writer');
654
+ assert.equal(src, reader);
655
+ });
656
+ reader.pipe(writer);
657
+ ```
658
+
659
+ #### Event: 'unpipe'
660
+
661
+ * `src` {[Readable][] Stream} The source stream that
662
+ [unpiped][`stream.unpipe()`] this writable
663
+
664
+ This is emitted whenever the [`stream.unpipe()`][] method is called on a
665
+ readable stream, removing this writable from its set of destinations.
666
+
667
+ ```js
668
+ var writer = getWritableStreamSomehow();
669
+ var reader = getReadableStreamSomehow();
670
+ writer.on('unpipe', (src) => {
671
+ console.error('something has stopped piping into the writer');
672
+ assert.equal(src, reader);
673
+ });
674
+ reader.pipe(writer);
675
+ reader.unpipe(writer);
676
+ ```
677
+
678
+ #### writable.cork()
679
+
680
+ Forces buffering of all writes.
681
+
682
+ Buffered data will be flushed either at [`stream.uncork()`][] or at
683
+ [`stream.end()`][stream-end] call.
684
+
685
+ #### writable.end([chunk][, encoding][, callback])
686
+
687
+ * `chunk` {String|Buffer} Optional data to write
688
+ * `encoding` {String} The encoding, if `chunk` is a String
689
+ * `callback` {Function} Optional callback for when the stream is finished
690
+
691
+ Call this method when no more data will be written to the stream. If supplied,
692
+ the callback is attached as a listener on the [`'finish'`][] event.
693
+
694
+ Calling [`stream.write()`][stream-write] after calling
695
+ [`stream.end()`][stream-end] will raise an error.
696
+
697
+ ```js
698
+ // write 'hello, ' and then end with 'world!'
699
+ var file = fs.createWriteStream('example.txt');
700
+ file.write('hello, ');
701
+ file.end('world!');
702
+ // writing more now is not allowed!
703
+ ```
704
+
705
+ #### writable.setDefaultEncoding(encoding)
706
+
707
+ * `encoding` {String} The new default encoding
708
+ * Return: `this`
709
+
710
+ Sets the default encoding for a writable stream.
711
+
712
+ #### writable.uncork()
713
+
714
+ Flush all data, buffered since [`stream.cork()`][] call.
715
+
716
+ #### writable.write(chunk[, encoding][, callback])
717
+
718
+ * `chunk` {String|Buffer} The data to write
719
+ * `encoding` {String} The encoding, if `chunk` is a String
720
+ * `callback` {Function} Callback for when this chunk of data is flushed
721
+ * Returns: {Boolean} `true` if the data was handled completely.
722
+
723
+ This method writes some data to the underlying system, and calls the
724
+ supplied callback once the data has been fully handled. If an error
725
+ occurs, the callback may or may not be called with the error as its
726
+ first argument. To detect write errors, listen for the `'error'` event.
727
+
728
+ The return value indicates if you should continue writing right now.
729
+ If the data had to be buffered internally, then it will return
730
+ `false`. Otherwise, it will return `true`.
731
+
732
+ This return value is strictly advisory. You MAY continue to write,
733
+ even if it returns `false`. However, writes will be buffered in
734
+ memory, so it is best not to do this excessively. Instead, wait for
735
+ the [`'drain'`][] event before writing more data.
736
+
737
+
738
+ ## API for Stream Implementors
739
+
740
+ <!--type=misc-->
741
+
742
+ To implement any sort of stream, the pattern is the same:
743
+
744
+ 1. Extend the appropriate parent class in your own subclass. (The
745
+ [`util.inherits()`][] method is particularly helpful for this.)
746
+ 2. Call the appropriate parent class constructor in your constructor,
747
+ to be sure that the internal mechanisms are set up properly.
748
+ 3. Implement one or more specific methods, as detailed below.
749
+
750
+ The class to extend and the method(s) to implement depend on the sort
751
+ of stream class you are writing:
752
+
753
+ <table>
754
+ <thead>
755
+ <tr>
756
+ <th>
757
+ <p>Use-case</p>
758
+ </th>
759
+ <th>
760
+ <p>Class</p>
761
+ </th>
762
+ <th>
763
+ <p>Method(s) to implement</p>
764
+ </th>
765
+ </tr>
766
+ </thead>
767
+ <tr>
768
+ <td>
769
+ <p>Reading only</p>
770
+ </td>
771
+ <td>
772
+ <p>[Readable](#stream_class_stream_readable_1)</p>
773
+ </td>
774
+ <td>
775
+ <p><code>[_read][stream-_read]</code></p>
776
+ </td>
777
+ </tr>
778
+ <tr>
779
+ <td>
780
+ <p>Writing only</p>
781
+ </td>
782
+ <td>
783
+ <p>[Writable](#stream_class_stream_writable_1)</p>
784
+ </td>
785
+ <td>
786
+ <p><code>[_write][stream-_write]</code>, <code>[_writev][stream-_writev]</code></p>
787
+ </td>
788
+ </tr>
789
+ <tr>
790
+ <td>
791
+ <p>Reading and writing</p>
792
+ </td>
793
+ <td>
794
+ <p>[Duplex](#stream_class_stream_duplex_1)</p>
795
+ </td>
796
+ <td>
797
+ <p><code>[_read][stream-_read]</code>, <code>[_write][stream-_write]</code>, <code>[_writev][stream-_writev]</code></p>
798
+ </td>
799
+ </tr>
800
+ <tr>
801
+ <td>
802
+ <p>Operate on written data, then read the result</p>
803
+ </td>
804
+ <td>
805
+ <p>[Transform](#stream_class_stream_transform_1)</p>
806
+ </td>
807
+ <td>
808
+ <p><code>[_transform][stream-_transform]</code>, <code>[_flush][stream-_flush]</code></p>
809
+ </td>
810
+ </tr>
811
+ </table>
812
+
813
+ In your implementation code, it is very important to never call the methods
814
+ described in [API for Stream Consumers][]. Otherwise, you can potentially cause
815
+ adverse side effects in programs that consume your streaming interfaces.
816
+
817
+ ### Class: stream.Duplex
818
+
819
+ <!--type=class-->
820
+
821
+ A "duplex" stream is one that is both Readable and Writable, such as a TCP
822
+ socket connection.
823
+
824
+ Note that `stream.Duplex` is an abstract class designed to be extended
825
+ with an underlying implementation of the [`stream._read(size)`][stream-_read]
826
+ and [`stream._write(chunk, encoding, callback)`][stream-_write] methods as you
827
+ would with a Readable or Writable stream class.
828
+
829
+ Since JavaScript doesn't have multiple prototypal inheritance, this class
830
+ prototypally inherits from Readable, and then parasitically from Writable. It is
831
+ thus up to the user to implement both the low-level
832
+ [`stream._read(n)`][stream-_read] method as well as the low-level
833
+ [`stream._write(chunk, encoding, callback)`][stream-_write] method on extension
834
+ duplex classes.
835
+
836
+ #### new stream.Duplex(options)
837
+
838
+ * `options` {Object} Passed to both Writable and Readable
839
+ constructors. Also has the following fields:
840
+ * `allowHalfOpen` {Boolean} Default = `true`. If set to `false`, then
841
+ the stream will automatically end the readable side when the
842
+ writable side ends and vice versa.
843
+ * `readableObjectMode` {Boolean} Default = `false`. Sets `objectMode`
844
+ for readable side of the stream. Has no effect if `objectMode`
845
+ is `true`.
846
+ * `writableObjectMode` {Boolean} Default = `false`. Sets `objectMode`
847
+ for writable side of the stream. Has no effect if `objectMode`
848
+ is `true`.
849
+
850
+ In classes that extend the Duplex class, make sure to call the
851
+ constructor so that the buffering settings can be properly
852
+ initialized.
853
+
854
+ ### Class: stream.PassThrough
855
+
856
+ This is a trivial implementation of a [Transform][] stream that simply
857
+ passes the input bytes across to the output. Its purpose is mainly
858
+ for examples and testing, but there are occasionally use cases where
859
+ it can come in handy as a building block for novel sorts of streams.
860
+
861
+ ### Class: stream.Readable
862
+
863
+ <!--type=class-->
864
+
865
+ `stream.Readable` is an abstract class designed to be extended with an
866
+ underlying implementation of the [`stream._read(size)`][stream-_read] method.
867
+
868
+ Please see [API for Stream Consumers][] for how to consume
869
+ streams in your programs. What follows is an explanation of how to
870
+ implement Readable streams in your programs.
871
+
872
+ #### new stream.Readable([options])
873
+
874
+ * `options` {Object}
875
+ * `highWaterMark` {Number} The maximum number of bytes to store in
876
+ the internal buffer before ceasing to read from the underlying
877
+ resource. Default = `16384` (16kb), or `16` for `objectMode` streams
878
+ * `encoding` {String} If specified, then buffers will be decoded to
879
+ strings using the specified encoding. Default = `null`
880
+ * `objectMode` {Boolean} Whether this stream should behave
881
+ as a stream of objects. Meaning that [`stream.read(n)`][stream-read] returns
882
+ a single value instead of a Buffer of size n. Default = `false`
883
+ * `read` {Function} Implementation for the [`stream._read()`][stream-_read]
884
+ method.
885
+
886
+ In classes that extend the Readable class, make sure to call the
887
+ Readable constructor so that the buffering settings can be properly
888
+ initialized.
889
+
890
+ #### readable.\_read(size)
891
+
892
+ * `size` {Number} Number of bytes to read asynchronously
893
+
894
+ Note: **Implement this method, but do NOT call it directly.**
895
+
896
+ This method is prefixed with an underscore because it is internal to the
897
+ class that defines it and should only be called by the internal Readable
898
+ class methods. All Readable stream implementations must provide a \_read
899
+ method to fetch data from the underlying resource.
900
+
901
+ When `_read()` is called, if data is available from the resource, the `_read()`
902
+ implementation should start pushing that data into the read queue by calling
903
+ [`this.push(dataChunk)`][stream-push]. `_read()` should continue reading from
904
+ the resource and pushing data until push returns `false`, at which point it
905
+ should stop reading from the resource. Only when `_read()` is called again after
906
+ it has stopped should it start reading more data from the resource and pushing
907
+ that data onto the queue.
908
+
909
+ Note: once the `_read()` method is called, it will not be called again until
910
+ the [`stream.push()`][stream-push] method is called.
911
+
912
+ The `size` argument is advisory. Implementations where a "read" is a
913
+ single call that returns data can use this to know how much data to
914
+ fetch. Implementations where that is not relevant, such as TCP or
915
+ TLS, may ignore this argument, and simply provide data whenever it
916
+ becomes available. There is no need, for example to "wait" until
917
+ `size` bytes are available before calling [`stream.push(chunk)`][stream-push].
918
+
919
+ #### readable.push(chunk[, encoding])
920
+
921
+
922
+ * `chunk` {Buffer|Null|String} Chunk of data to push into the read queue
923
+ * `encoding` {String} Encoding of String chunks. Must be a valid
924
+ Buffer encoding, such as `'utf8'` or `'ascii'`
925
+ * return {Boolean} Whether or not more pushes should be performed
926
+
927
+ Note: **This method should be called by Readable implementors, NOT
928
+ by consumers of Readable streams.**
929
+
930
+ If a value other than null is passed, The `push()` method adds a chunk of data
931
+ into the queue for subsequent stream processors to consume. If `null` is
932
+ passed, it signals the end of the stream (EOF), after which no more data
933
+ can be written.
934
+
935
+ The data added with `push()` can be pulled out by calling the
936
+ [`stream.read()`][stream-read] method when the [`'readable'`][] event fires.
937
+
938
+ This API is designed to be as flexible as possible. For example,
939
+ you may be wrapping a lower-level source which has some sort of
940
+ pause/resume mechanism, and a data callback. In those cases, you
941
+ could wrap the low-level source object by doing something like this:
942
+
943
+ ```js
944
+ // source is an object with readStop() and readStart() methods,
945
+ // and an `ondata` member that gets called when it has data, and
946
+ // an `onend` member that gets called when the data is over.
947
+
948
+ util.inherits(SourceWrapper, Readable);
949
+
950
+ function SourceWrapper(options) {
951
+ Readable.call(this, options);
952
+
953
+ this._source = getLowlevelSourceObject();
954
+
955
+ // Every time there's data, we push it into the internal buffer.
956
+ this._source.ondata = (chunk) => {
957
+ // if push() returns false, then we need to stop reading from source
958
+ if (!this.push(chunk))
959
+ this._source.readStop();
960
+ };
961
+
962
+ // When the source ends, we push the EOF-signaling `null` chunk
963
+ this._source.onend = () => {
964
+ this.push(null);
965
+ };
966
+ }
967
+
968
+ // _read will be called when the stream wants to pull more data in
969
+ // the advisory size argument is ignored in this case.
970
+ SourceWrapper.prototype._read = function(size) {
971
+ this._source.readStart();
972
+ };
973
+ ```
974
+
975
+ #### Example: A Counting Stream
976
+
977
+ <!--type=example-->
978
+
979
+ This is a basic example of a Readable stream. It emits the numerals
980
+ from 1 to 1,000,000 in ascending order, and then ends.
981
+
982
+ ```js
983
+ const Readable = require('stream').Readable;
984
+ const util = require('util');
985
+ util.inherits(Counter, Readable);
986
+
987
+ function Counter(opt) {
988
+ Readable.call(this, opt);
989
+ this._max = 1000000;
990
+ this._index = 1;
991
+ }
992
+
993
+ Counter.prototype._read = function() {
994
+ var i = this._index++;
995
+ if (i > this._max)
996
+ this.push(null);
997
+ else {
998
+ var str = '' + i;
999
+ var buf = Buffer.from(str, 'ascii');
1000
+ this.push(buf);
1001
+ }
1002
+ };
1003
+ ```
1004
+
1005
+ #### Example: SimpleProtocol v1 (Sub-optimal)
1006
+
1007
+ This is similar to the `parseHeader` function described
1008
+ [here](#stream_readable_unshift_chunk), but implemented as a custom stream.
1009
+ Also, note that this implementation does not convert the incoming data to a
1010
+ string.
1011
+
1012
+ However, this would be better implemented as a [Transform][] stream. See
1013
+ [SimpleProtocol v2][] for a better implementation.
1014
+
1015
+ ```js
1016
+ // A parser for a simple data protocol.
1017
+ // The "header" is a JSON object, followed by 2 \n characters, and
1018
+ // then a message body.
1019
+ //
1020
+ // NOTE: This can be done more simply as a Transform stream!
1021
+ // Using Readable directly for this is sub-optimal. See the
1022
+ // alternative example below under the Transform section.
1023
+
1024
+ const Readable = require('stream').Readable;
1025
+ const util = require('util');
1026
+
1027
+ util.inherits(SimpleProtocol, Readable);
1028
+
1029
+ function SimpleProtocol(source, options) {
1030
+ if (!(this instanceof SimpleProtocol))
1031
+ return new SimpleProtocol(source, options);
1032
+
1033
+ Readable.call(this, options);
1034
+ this._inBody = false;
1035
+ this._sawFirstCr = false;
1036
+
1037
+ // source is a readable stream, such as a socket or file
1038
+ this._source = source;
1039
+
1040
+ source.on('end', () => {
1041
+ this.push(null);
1042
+ });
1043
+
1044
+ // give it a kick whenever the source is readable
1045
+ // read(0) will not consume any bytes
1046
+ source.on('readable', () => {
1047
+ this.read(0);
1048
+ });
1049
+
1050
+ this._rawHeader = [];
1051
+ this.header = null;
1052
+ }
1053
+
1054
+ SimpleProtocol.prototype._read = function(n) {
1055
+ if (!this._inBody) {
1056
+ var chunk = this._source.read();
1057
+
1058
+ // if the source doesn't have data, we don't have data yet.
1059
+ if (chunk === null)
1060
+ return this.push('');
1061
+
1062
+ // check if the chunk has a \n\n
1063
+ var split = -1;
1064
+ for (var i = 0; i < chunk.length; i++) {
1065
+ if (chunk[i] === 10) { // '\n'
1066
+ if (this._sawFirstCr) {
1067
+ split = i;
1068
+ break;
1069
+ } else {
1070
+ this._sawFirstCr = true;
1071
+ }
1072
+ } else {
1073
+ this._sawFirstCr = false;
1074
+ }
1075
+ }
1076
+
1077
+ if (split === -1) {
1078
+ // still waiting for the \n\n
1079
+ // stash the chunk, and try again.
1080
+ this._rawHeader.push(chunk);
1081
+ this.push('');
1082
+ } else {
1083
+ this._inBody = true;
1084
+ var h = chunk.slice(0, split);
1085
+ this._rawHeader.push(h);
1086
+ var header = Buffer.concat(this._rawHeader).toString();
1087
+ try {
1088
+ this.header = JSON.parse(header);
1089
+ } catch (er) {
1090
+ this.emit('error', new Error('invalid simple protocol data'));
1091
+ return;
1092
+ }
1093
+ // now, because we got some extra data, unshift the rest
1094
+ // back into the read queue so that our consumer will see it.
1095
+ var b = chunk.slice(split);
1096
+ this.unshift(b);
1097
+ // calling unshift by itself does not reset the reading state
1098
+ // of the stream; since we're inside _read, doing an additional
1099
+ // push('') will reset the state appropriately.
1100
+ this.push('');
1101
+
1102
+ // and let them know that we are done parsing the header.
1103
+ this.emit('header', this.header);
1104
+ }
1105
+ } else {
1106
+ // from there on, just provide the data to our consumer.
1107
+ // careful not to push(null), since that would indicate EOF.
1108
+ var chunk = this._source.read();
1109
+ if (chunk) this.push(chunk);
1110
+ }
1111
+ };
1112
+
1113
+ // Usage:
1114
+ // var parser = new SimpleProtocol(source);
1115
+ // Now parser is a readable stream that will emit 'header'
1116
+ // with the parsed header data.
1117
+ ```
1118
+
1119
+ ### Class: stream.Transform
1120
+
1121
+ A "transform" stream is a duplex stream where the output is causally
1122
+ connected in some way to the input, such as a [zlib][] stream or a
1123
+ [crypto][] stream.
1124
+
1125
+ There is no requirement that the output be the same size as the input,
1126
+ the same number of chunks, or arrive at the same time. For example, a
1127
+ Hash stream will only ever have a single chunk of output which is
1128
+ provided when the input is ended. A zlib stream will produce output
1129
+ that is either much smaller or much larger than its input.
1130
+
1131
+ Rather than implement the [`stream._read()`][stream-_read] and
1132
+ [`stream._write()`][stream-_write] methods, Transform classes must implement the
1133
+ [`stream._transform()`][stream-_transform] method, and may optionally
1134
+ also implement the [`stream._flush()`][stream-_flush] method. (See below.)
1135
+
1136
+ #### new stream.Transform([options])
1137
+
1138
+ * `options` {Object} Passed to both Writable and Readable
1139
+ constructors. Also has the following fields:
1140
+ * `transform` {Function} Implementation for the
1141
+ [`stream._transform()`][stream-_transform] method.
1142
+ * `flush` {Function} Implementation for the [`stream._flush()`][stream-_flush]
1143
+ method.
1144
+
1145
+ In classes that extend the Transform class, make sure to call the
1146
+ constructor so that the buffering settings can be properly
1147
+ initialized.
1148
+
1149
+ #### Events: 'finish' and 'end'
1150
+
1151
+ The [`'finish'`][] and [`'end'`][] events are from the parent Writable
1152
+ and Readable classes respectively. The `'finish'` event is fired after
1153
+ [`stream.end()`][stream-end] is called and all chunks have been processed by
1154
+ [`stream._transform()`][stream-_transform], `'end'` is fired after all data has
1155
+ been output which is after the callback in [`stream._flush()`][stream-_flush]
1156
+ has been called.
1157
+
1158
+ #### transform.\_flush(callback)
1159
+
1160
+ * `callback` {Function} Call this function (optionally with an error
1161
+ argument) when you are done flushing any remaining data.
1162
+
1163
+ Note: **This function MUST NOT be called directly.** It MAY be implemented
1164
+ by child classes, and if so, will be called by the internal Transform
1165
+ class methods only.
1166
+
1167
+ In some cases, your transform operation may need to emit a bit more
1168
+ data at the end of the stream. For example, a `Zlib` compression
1169
+ stream will store up some internal state so that it can optimally
1170
+ compress the output. At the end, however, it needs to do the best it
1171
+ can with what is left, so that the data will be complete.
1172
+
1173
+ In those cases, you can implement a `_flush()` method, which will be
1174
+ called at the very end, after all the written data is consumed, but
1175
+ before emitting [`'end'`][] to signal the end of the readable side. Just
1176
+ like with [`stream._transform()`][stream-_transform], call
1177
+ `transform.push(chunk)` zero or more times, as appropriate, and call `callback`
1178
+ when the flush operation is complete.
1179
+
1180
+ This method is prefixed with an underscore because it is internal to
1181
+ the class that defines it, and should not be called directly by user
1182
+ programs. However, you **are** expected to override this method in
1183
+ your own extension classes.
1184
+
1185
+ #### transform.\_transform(chunk, encoding, callback)
1186
+
1187
+ * `chunk` {Buffer|String} The chunk to be transformed. Will **always**
1188
+ be a buffer unless the `decodeStrings` option was set to `false`.
1189
+ * `encoding` {String} If the chunk is a string, then this is the
1190
+ encoding type. If chunk is a buffer, then this is the special
1191
+ value - 'buffer', ignore it in this case.
1192
+ * `callback` {Function} Call this function (optionally with an error
1193
+ argument and data) when you are done processing the supplied chunk.
1194
+
1195
+ Note: **This function MUST NOT be called directly.** It should be
1196
+ implemented by child classes, and called by the internal Transform
1197
+ class methods only.
1198
+
1199
+ All Transform stream implementations must provide a `_transform()`
1200
+ method to accept input and produce output.
1201
+
1202
+ `_transform()` should do whatever has to be done in this specific
1203
+ Transform class, to handle the bytes being written, and pass them off
1204
+ to the readable portion of the interface. Do asynchronous I/O,
1205
+ process things, and so on.
1206
+
1207
+ Call `transform.push(outputChunk)` 0 or more times to generate output
1208
+ from this input chunk, depending on how much data you want to output
1209
+ as a result of this chunk.
1210
+
1211
+ Call the callback function only when the current chunk is completely
1212
+ consumed. Note that there may or may not be output as a result of any
1213
+ particular input chunk. If you supply a second argument to the callback
1214
+ it will be passed to the push method. In other words the following are
1215
+ equivalent:
1216
+
1217
+ ```js
1218
+ transform.prototype._transform = function (data, encoding, callback) {
1219
+ this.push(data);
1220
+ callback();
1221
+ };
1222
+
1223
+ transform.prototype._transform = function (data, encoding, callback) {
1224
+ callback(null, data);
1225
+ };
1226
+ ```
1227
+
1228
+ This method is prefixed with an underscore because it is internal to
1229
+ the class that defines it, and should not be called directly by user
1230
+ programs. However, you **are** expected to override this method in
1231
+ your own extension classes.
1232
+
1233
+ #### Example: `SimpleProtocol` parser v2
1234
+
1235
+ The example [here](#stream_example_simpleprotocol_v1_sub_optimal) of a simple
1236
+ protocol parser can be implemented simply by using the higher level
1237
+ [Transform][] stream class, similar to the `parseHeader` and `SimpleProtocol
1238
+ v1` examples.
1239
+
1240
+ In this example, rather than providing the input as an argument, it
1241
+ would be piped into the parser, which is a more idiomatic Node.js stream
1242
+ approach.
1243
+
1244
+ ```javascript
1245
+ const util = require('util');
1246
+ const Transform = require('stream').Transform;
1247
+ util.inherits(SimpleProtocol, Transform);
1248
+
1249
+ function SimpleProtocol(options) {
1250
+ if (!(this instanceof SimpleProtocol))
1251
+ return new SimpleProtocol(options);
1252
+
1253
+ Transform.call(this, options);
1254
+ this._inBody = false;
1255
+ this._sawFirstCr = false;
1256
+ this._rawHeader = [];
1257
+ this.header = null;
1258
+ }
1259
+
1260
+ SimpleProtocol.prototype._transform = function(chunk, encoding, done) {
1261
+ if (!this._inBody) {
1262
+ // check if the chunk has a \n\n
1263
+ var split = -1;
1264
+ for (var i = 0; i < chunk.length; i++) {
1265
+ if (chunk[i] === 10) { // '\n'
1266
+ if (this._sawFirstCr) {
1267
+ split = i;
1268
+ break;
1269
+ } else {
1270
+ this._sawFirstCr = true;
1271
+ }
1272
+ } else {
1273
+ this._sawFirstCr = false;
1274
+ }
1275
+ }
1276
+
1277
+ if (split === -1) {
1278
+ // still waiting for the \n\n
1279
+ // stash the chunk, and try again.
1280
+ this._rawHeader.push(chunk);
1281
+ } else {
1282
+ this._inBody = true;
1283
+ var h = chunk.slice(0, split);
1284
+ this._rawHeader.push(h);
1285
+ var header = Buffer.concat(this._rawHeader).toString();
1286
+ try {
1287
+ this.header = JSON.parse(header);
1288
+ } catch (er) {
1289
+ this.emit('error', new Error('invalid simple protocol data'));
1290
+ return;
1291
+ }
1292
+ // and let them know that we are done parsing the header.
1293
+ this.emit('header', this.header);
1294
+
1295
+ // now, because we got some extra data, emit this first.
1296
+ this.push(chunk.slice(split));
1297
+ }
1298
+ } else {
1299
+ // from there on, just provide the data to our consumer as-is.
1300
+ this.push(chunk);
1301
+ }
1302
+ done();
1303
+ };
1304
+
1305
+ // Usage:
1306
+ // var parser = new SimpleProtocol();
1307
+ // source.pipe(parser)
1308
+ // Now parser is a readable stream that will emit 'header'
1309
+ // with the parsed header data.
1310
+ ```
1311
+
1312
+ ### Class: stream.Writable
1313
+
1314
+ <!--type=class-->
1315
+
1316
+ `stream.Writable` is an abstract class designed to be extended with an
1317
+ underlying implementation of the
1318
+ [`stream._write(chunk, encoding, callback)`][stream-_write] method.
1319
+
1320
+ Please see [API for Stream Consumers][] for how to consume
1321
+ writable streams in your programs. What follows is an explanation of
1322
+ how to implement Writable streams in your programs.
1323
+
1324
+ #### new stream.Writable([options])
1325
+
1326
+ * `options` {Object}
1327
+ * `highWaterMark` {Number} Buffer level when
1328
+ [`stream.write()`][stream-write] starts returning `false`. Default = `16384`
1329
+ (16kb), or `16` for `objectMode` streams.
1330
+ * `decodeStrings` {Boolean} Whether or not to decode strings into
1331
+ Buffers before passing them to [`stream._write()`][stream-_write].
1332
+ Default = `true`
1333
+ * `objectMode` {Boolean} Whether or not the
1334
+ [`stream.write(anyObj)`][stream-write] is a valid operation. If set you can
1335
+ write arbitrary data instead of only `Buffer` / `String` data.
1336
+ Default = `false`
1337
+ * `write` {Function} Implementation for the
1338
+ [`stream._write()`][stream-_write] method.
1339
+ * `writev` {Function} Implementation for the
1340
+ [`stream._writev()`][stream-_writev] method.
1341
+
1342
+ In classes that extend the Writable class, make sure to call the
1343
+ constructor so that the buffering settings can be properly
1344
+ initialized.
1345
+
1346
+ #### writable.\_write(chunk, encoding, callback)
1347
+
1348
+ * `chunk` {Buffer|String} The chunk to be written. Will **always**
1349
+ be a buffer unless the `decodeStrings` option was set to `false`.
1350
+ * `encoding` {String} If the chunk is a string, then this is the
1351
+ encoding type. If chunk is a buffer, then this is the special
1352
+ value - 'buffer', ignore it in this case.
1353
+ * `callback` {Function} Call this function (optionally with an error
1354
+ argument) when you are done processing the supplied chunk.
1355
+
1356
+ All Writable stream implementations must provide a
1357
+ [`stream._write()`][stream-_write] method to send data to the underlying
1358
+ resource.
1359
+
1360
+ Note: **This function MUST NOT be called directly.** It should be
1361
+ implemented by child classes, and called by the internal Writable
1362
+ class methods only.
1363
+
1364
+ Call the callback using the standard `callback(error)` pattern to
1365
+ signal that the write completed successfully or with an error.
1366
+
1367
+ If the `decodeStrings` flag is set in the constructor options, then
1368
+ `chunk` may be a string rather than a Buffer, and `encoding` will
1369
+ indicate the sort of string that it is. This is to support
1370
+ implementations that have an optimized handling for certain string
1371
+ data encodings. If you do not explicitly set the `decodeStrings`
1372
+ option to `false`, then you can safely ignore the `encoding` argument,
1373
+ and assume that `chunk` will always be a Buffer.
1374
+
1375
+ This method is prefixed with an underscore because it is internal to
1376
+ the class that defines it, and should not be called directly by user
1377
+ programs. However, you **are** expected to override this method in
1378
+ your own extension classes.
1379
+
1380
+ #### writable.\_writev(chunks, callback)
1381
+
1382
+ * `chunks` {Array} The chunks to be written. Each chunk has following
1383
+ format: `{ chunk: ..., encoding: ... }`.
1384
+ * `callback` {Function} Call this function (optionally with an error
1385
+ argument) when you are done processing the supplied chunks.
1386
+
1387
+ Note: **This function MUST NOT be called directly.** It may be
1388
+ implemented by child classes, and called by the internal Writable
1389
+ class methods only.
1390
+
1391
+ This function is completely optional to implement. In most cases it is
1392
+ unnecessary. If implemented, it will be called with all the chunks
1393
+ that are buffered in the write queue.
1394
+
1395
+
1396
+ ## Simplified Constructor API
1397
+
1398
+ <!--type=misc-->
1399
+
1400
+ In simple cases there is now the added benefit of being able to construct a
1401
+ stream without inheritance.
1402
+
1403
+ This can be done by passing the appropriate methods as constructor options:
1404
+
1405
+ Examples:
1406
+
1407
+ ### Duplex
1408
+
1409
+ ```js
1410
+ var duplex = new stream.Duplex({
1411
+ read: function(n) {
1412
+ // sets this._read under the hood
1413
+
1414
+ // push data onto the read queue, passing null
1415
+ // will signal the end of the stream (EOF)
1416
+ this.push(chunk);
1417
+ },
1418
+ write: function(chunk, encoding, next) {
1419
+ // sets this._write under the hood
1420
+
1421
+ // An optional error can be passed as the first argument
1422
+ next()
1423
+ }
1424
+ });
1425
+
1426
+ // or
1427
+
1428
+ var duplex = new stream.Duplex({
1429
+ read: function(n) {
1430
+ // sets this._read under the hood
1431
+
1432
+ // push data onto the read queue, passing null
1433
+ // will signal the end of the stream (EOF)
1434
+ this.push(chunk);
1435
+ },
1436
+ writev: function(chunks, next) {
1437
+ // sets this._writev under the hood
1438
+
1439
+ // An optional error can be passed as the first argument
1440
+ next()
1441
+ }
1442
+ });
1443
+ ```
1444
+
1445
+ ### Readable
1446
+
1447
+ ```js
1448
+ var readable = new stream.Readable({
1449
+ read: function(n) {
1450
+ // sets this._read under the hood
1451
+
1452
+ // push data onto the read queue, passing null
1453
+ // will signal the end of the stream (EOF)
1454
+ this.push(chunk);
1455
+ }
1456
+ });
1457
+ ```
1458
+
1459
+ ### Transform
1460
+
1461
+ ```js
1462
+ var transform = new stream.Transform({
1463
+ transform: function(chunk, encoding, next) {
1464
+ // sets this._transform under the hood
1465
+
1466
+ // generate output as many times as needed
1467
+ // this.push(chunk);
1468
+
1469
+ // call when the current chunk is consumed
1470
+ next();
1471
+ },
1472
+ flush: function(done) {
1473
+ // sets this._flush under the hood
1474
+
1475
+ // generate output as many times as needed
1476
+ // this.push(chunk);
1477
+
1478
+ done();
1479
+ }
1480
+ });
1481
+ ```
1482
+
1483
+ ### Writable
1484
+
1485
+ ```js
1486
+ var writable = new stream.Writable({
1487
+ write: function(chunk, encoding, next) {
1488
+ // sets this._write under the hood
1489
+
1490
+ // An optional error can be passed as the first argument
1491
+ next()
1492
+ }
1493
+ });
1494
+
1495
+ // or
1496
+
1497
+ var writable = new stream.Writable({
1498
+ writev: function(chunks, next) {
1499
+ // sets this._writev under the hood
1500
+
1501
+ // An optional error can be passed as the first argument
1502
+ next()
1503
+ }
1504
+ });
1505
+ ```
1506
+
1507
+ ## Streams: Under the Hood
1508
+
1509
+ <!--type=misc-->
1510
+
1511
+ ### Buffering
1512
+
1513
+ <!--type=misc-->
1514
+
1515
+ Both Writable and Readable streams will buffer data on an internal
1516
+ object which can be retrieved from `_writableState.getBuffer()` or
1517
+ `_readableState.buffer`, respectively.
1518
+
1519
+ The amount of data that will potentially be buffered depends on the
1520
+ `highWaterMark` option which is passed into the constructor.
1521
+
1522
+ Buffering in Readable streams happens when the implementation calls
1523
+ [`stream.push(chunk)`][stream-push]. If the consumer of the Stream does not
1524
+ call [`stream.read()`][stream-read], then the data will sit in the internal
1525
+ queue until it is consumed.
1526
+
1527
+ Buffering in Writable streams happens when the user calls
1528
+ [`stream.write(chunk)`][stream-write] repeatedly, even when it returns `false`.
1529
+
1530
+ The purpose of streams, especially with the [`stream.pipe()`][] method, is to
1531
+ limit the buffering of data to acceptable levels, so that sources and
1532
+ destinations of varying speed will not overwhelm the available memory.
1533
+
1534
+ ### Compatibility with Older Node.js Versions
1535
+
1536
+ <!--type=misc-->
1537
+
1538
+ In versions of Node.js prior to v0.10, the Readable stream interface was
1539
+ simpler, but also less powerful and less useful.
1540
+
1541
+ * Rather than waiting for you to call the [`stream.read()`][stream-read] method,
1542
+ [`'data'`][] events would start emitting immediately. If you needed to do
1543
+ some I/O to decide how to handle data, then you had to store the chunks
1544
+ in some kind of buffer so that they would not be lost.
1545
+ * The [`stream.pause()`][stream-pause] method was advisory, rather than
1546
+ guaranteed. This meant that you still had to be prepared to receive
1547
+ [`'data'`][] events even when the stream was in a paused state.
1548
+
1549
+ In Node.js v0.10, the [Readable][] class was added.
1550
+ For backwards compatibility with older Node.js programs, Readable streams
1551
+ switch into "flowing mode" when a [`'data'`][] event handler is added, or
1552
+ when the [`stream.resume()`][stream-resume] method is called. The effect is
1553
+ that, even if you are not using the new [`stream.read()`][stream-read] method
1554
+ and [`'readable'`][] event, you no longer have to worry about losing
1555
+ [`'data'`][] chunks.
1556
+
1557
+ Most programs will continue to function normally. However, this
1558
+ introduces an edge case in the following conditions:
1559
+
1560
+ * No [`'data'`][] event handler is added.
1561
+ * The [`stream.resume()`][stream-resume] method is never called.
1562
+ * The stream is not piped to any writable destination.
1563
+
1564
+ For example, consider the following code:
1565
+
1566
+ ```js
1567
+ // WARNING! BROKEN!
1568
+ net.createServer((socket) => {
1569
+
1570
+ // we add an 'end' method, but never consume the data
1571
+ socket.on('end', () => {
1572
+ // It will never get here.
1573
+ socket.end('I got your message (but didnt read it)\n');
1574
+ });
1575
+
1576
+ }).listen(1337);
1577
+ ```
1578
+
1579
+ In versions of Node.js prior to v0.10, the incoming message data would be
1580
+ simply discarded. However, in Node.js v0.10 and beyond,
1581
+ the socket will remain paused forever.
1582
+
1583
+ The workaround in this situation is to call the
1584
+ [`stream.resume()`][stream-resume] method to start the flow of data:
1585
+
1586
+ ```js
1587
+ // Workaround
1588
+ net.createServer((socket) => {
1589
+
1590
+ socket.on('end', () => {
1591
+ socket.end('I got your message (but didnt read it)\n');
1592
+ });
1593
+
1594
+ // start the flow of data, discarding it.
1595
+ socket.resume();
1596
+
1597
+ }).listen(1337);
1598
+ ```
1599
+
1600
+ In addition to new Readable streams switching into flowing mode,
1601
+ pre-v0.10 style streams can be wrapped in a Readable class using the
1602
+ [`stream.wrap()`][] method.
1603
+
1604
+
1605
+ ### Object Mode
1606
+
1607
+ <!--type=misc-->
1608
+
1609
+ Normally, Streams operate on Strings and Buffers exclusively.
1610
+
1611
+ Streams that are in **object mode** can emit generic JavaScript values
1612
+ other than Buffers and Strings.
1613
+
1614
+ A Readable stream in object mode will always return a single item from
1615
+ a call to [`stream.read(size)`][stream-read], regardless of what the size
1616
+ argument is.
1617
+
1618
+ A Writable stream in object mode will always ignore the `encoding`
1619
+ argument to [`stream.write(data, encoding)`][stream-write].
1620
+
1621
+ The special value `null` still retains its special value for object
1622
+ mode streams. That is, for object mode readable streams, `null` as a
1623
+ return value from [`stream.read()`][stream-read] indicates that there is no more
1624
+ data, and [`stream.push(null)`][stream-push] will signal the end of stream data
1625
+ (`EOF`).
1626
+
1627
+ No streams in Node.js core are object mode streams. This pattern is only
1628
+ used by userland streaming libraries.
1629
+
1630
+ You should set `objectMode` in your stream child class constructor on
1631
+ the options object. Setting `objectMode` mid-stream is not safe.
1632
+
1633
+ For Duplex streams `objectMode` can be set exclusively for readable or
1634
+ writable side with `readableObjectMode` and `writableObjectMode`
1635
+ respectively. These options can be used to implement parsers and
1636
+ serializers with Transform streams.
1637
+
1638
+ ```js
1639
+ const util = require('util');
1640
+ const StringDecoder = require('string_decoder').StringDecoder;
1641
+ const Transform = require('stream').Transform;
1642
+ util.inherits(JSONParseStream, Transform);
1643
+
1644
+ // Gets \n-delimited JSON string data, and emits the parsed objects
1645
+ function JSONParseStream() {
1646
+ if (!(this instanceof JSONParseStream))
1647
+ return new JSONParseStream();
1648
+
1649
+ Transform.call(this, { readableObjectMode : true });
1650
+
1651
+ this._buffer = '';
1652
+ this._decoder = new StringDecoder('utf8');
1653
+ }
1654
+
1655
+ JSONParseStream.prototype._transform = function(chunk, encoding, cb) {
1656
+ this._buffer += this._decoder.write(chunk);
1657
+ // split on newlines
1658
+ var lines = this._buffer.split(/\r?\n/);
1659
+ // keep the last partial line buffered
1660
+ this._buffer = lines.pop();
1661
+ for (var l = 0; l < lines.length; l++) {
1662
+ var line = lines[l];
1663
+ try {
1664
+ var obj = JSON.parse(line);
1665
+ } catch (er) {
1666
+ this.emit('error', er);
1667
+ return;
1668
+ }
1669
+ // push the parsed object out to the readable consumer
1670
+ this.push(obj);
1671
+ }
1672
+ cb();
1673
+ };
1674
+
1675
+ JSONParseStream.prototype._flush = function(cb) {
1676
+ // Just handle any leftover
1677
+ var rem = this._buffer.trim();
1678
+ if (rem) {
1679
+ try {
1680
+ var obj = JSON.parse(rem);
1681
+ } catch (er) {
1682
+ this.emit('error', er);
1683
+ return;
1684
+ }
1685
+ // push the parsed object out to the readable consumer
1686
+ this.push(obj);
1687
+ }
1688
+ cb();
1689
+ };
1690
+ ```
1691
+
1692
+ ### `stream.read(0)`
1693
+
1694
+ There are some cases where you want to trigger a refresh of the
1695
+ underlying readable stream mechanisms, without actually consuming any
1696
+ data. In that case, you can call `stream.read(0)`, which will always
1697
+ return null.
1698
+
1699
+ If the internal read buffer is below the `highWaterMark`, and the
1700
+ stream is not currently reading, then calling `stream.read(0)` will trigger
1701
+ a low-level [`stream._read()`][stream-_read] call.
1702
+
1703
+ There is almost never a need to do this. However, you will see some
1704
+ cases in Node.js's internals where this is done, particularly in the
1705
+ Readable stream class internals.
1706
+
1707
+ ### `stream.push('')`
1708
+
1709
+ Pushing a zero-byte string or Buffer (when not in [Object mode][]) has an
1710
+ interesting side effect. Because it *is* a call to
1711
+ [`stream.push()`][stream-push], it will end the `reading` process. However, it
1712
+ does *not* add any data to the readable buffer, so there's nothing for
1713
+ a user to consume.
1714
+
1715
+ Very rarely, there are cases where you have no data to provide now,
1716
+ but the consumer of your stream (or, perhaps, another bit of your own
1717
+ code) will know when to check again, by calling [`stream.read(0)`][stream-read].
1718
+ In those cases, you *may* call `stream.push('')`.
1719
+
1720
+ So far, the only use case for this functionality is in the
1721
+ [`tls.CryptoStream`][] class, which is deprecated in Node.js/io.js v1.0. If you
1722
+ find that you have to use `stream.push('')`, please consider another
1723
+ approach, because it almost certainly indicates that something is
1724
+ horribly wrong.
1725
+
1726
+ [`'data'`]: #stream_event_data
1727
+ [`'drain'`]: #stream_event_drain
1728
+ [`'end'`]: #stream_event_end
1729
+ [`'finish'`]: #stream_event_finish
1730
+ [`'readable'`]: #stream_event_readable
1731
+ [`buf.toString(encoding)`]: https://nodejs.org/docs/v6.1.0/api/buffer.html#buffer_buf_tostring_encoding_start_end
1732
+ [`EventEmitter`]: https://nodejs.org/docs/v6.1.0/api/events.html#events_class_eventemitter
1733
+ [`process.stderr`]: https://nodejs.org/docs/v6.1.0/api/process.html#process_process_stderr
1734
+ [`process.stdin`]: https://nodejs.org/docs/v6.1.0/api/process.html#process_process_stdin
1735
+ [`process.stdout`]: https://nodejs.org/docs/v6.1.0/api/process.html#process_process_stdout
1736
+ [`stream.cork()`]: #stream_writable_cork
1737
+ [`stream.pipe()`]: #stream_readable_pipe_destination_options
1738
+ [`stream.uncork()`]: #stream_writable_uncork
1739
+ [`stream.unpipe()`]: #stream_readable_unpipe_destination
1740
+ [`stream.wrap()`]: #stream_readable_wrap_stream
1741
+ [`tls.CryptoStream`]: https://nodejs.org/docs/v6.1.0/api/tls.html#tls_class_cryptostream
1742
+ [`util.inherits()`]: https://nodejs.org/docs/v6.1.0/api/util.html#util_util_inherits_constructor_superconstructor
1743
+ [API for Stream Consumers]: #stream_api_for_stream_consumers
1744
+ [API for Stream Implementors]: #stream_api_for_stream_implementors
1745
+ [child process stdin]: https://nodejs.org/docs/v6.1.0/api/child_process.html#child_process_child_stdin
1746
+ [child process stdout and stderr]: https://nodejs.org/docs/v6.1.0/api/child_process.html#child_process_child_stdout
1747
+ [Compatibility]: #stream_compatibility_with_older_node_js_versions
1748
+ [crypto]: crypto.html
1749
+ [Duplex]: #stream_class_stream_duplex
1750
+ [fs read streams]: https://nodejs.org/docs/v6.1.0/api/fs.html#fs_class_fs_readstream
1751
+ [fs write streams]: https://nodejs.org/docs/v6.1.0/api/fs.html#fs_class_fs_writestream
1752
+ [HTTP requests, on the client]: https://nodejs.org/docs/v6.1.0/api/http.html#http_class_http_clientrequest
1753
+ [HTTP responses, on the server]: https://nodejs.org/docs/v6.1.0/api/http.html#http_class_http_serverresponse
1754
+ [http-incoming-message]: https://nodejs.org/docs/v6.1.0/api/http.html#http_class_http_incomingmessage
1755
+ [Object mode]: #stream_object_mode
1756
+ [Readable]: #stream_class_stream_readable
1757
+ [SimpleProtocol v2]: #stream_example_simpleprotocol_parser_v2
1758
+ [stream-_flush]: #stream_transform_flush_callback
1759
+ [stream-_read]: #stream_readable_read_size_1
1760
+ [stream-_transform]: #stream_transform_transform_chunk_encoding_callback
1761
+ [stream-_write]: #stream_writable_write_chunk_encoding_callback_1
1762
+ [stream-_writev]: #stream_writable_writev_chunks_callback
1763
+ [stream-end]: #stream_writable_end_chunk_encoding_callback
1764
+ [stream-pause]: #stream_readable_pause
1765
+ [stream-push]: #stream_readable_push_chunk_encoding
1766
+ [stream-read]: #stream_readable_read_size
1767
+ [stream-resume]: #stream_readable_resume
1768
+ [stream-write]: #stream_writable_write_chunk_encoding_callback
1769
+ [TCP sockets]: https://nodejs.org/docs/v6.1.0/api/net.html#net_class_net_socket
1770
+ [Transform]: #stream_class_stream_transform
1771
+ [Writable]: #stream_class_stream_writable
1772
+ [zlib]: zlib.html