passenger 5.0.21 → 5.0.22

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

Potentially problematic release.


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

Files changed (203) hide show
  1. checksums.yaml +8 -8
  2. checksums.yaml.gz.asc +7 -7
  3. data.tar.gz.asc +7 -7
  4. data/CHANGELOG +38 -2
  5. data/CONTRIBUTORS +3 -0
  6. data/README.md +5 -1
  7. data/bin/passenger-status +2 -7
  8. data/build/agent.rb +2 -0
  9. data/build/cxx_dependency_map.rb +1464 -162
  10. data/build/node_tests.rb +1 -1
  11. data/build/packaging.rb +1 -1
  12. data/dev/ci/run_travis.sh +1 -1
  13. data/dev/vagrant/provision.sh +1 -1
  14. data/npm-shrinkwrap.json +635 -125
  15. data/package.json +1 -1
  16. data/resources/templates/standalone/config.erb +33 -161
  17. data/resources/templates/standalone/global.erb +15 -0
  18. data/resources/templates/standalone/http.erb +40 -0
  19. data/resources/templates/standalone/mass_deployment_default_server.erb +11 -0
  20. data/resources/templates/standalone/rails_asset_pipeline.erb +22 -0
  21. data/resources/templates/standalone/server.erb +58 -0
  22. data/src/agent/Core/ApiServer.h +37 -32
  23. data/src/agent/Core/ApplicationPool/BasicGroupInfo.h +1 -1
  24. data/src/agent/Core/ApplicationPool/BasicProcessInfo.h +6 -0
  25. data/src/agent/Core/ApplicationPool/Common.h +1 -1
  26. data/src/agent/Core/ApplicationPool/Group/OutOfBandWork.cpp +1 -1
  27. data/src/agent/Core/ApplicationPool/Group/ProcessListManagement.cpp +4 -0
  28. data/src/agent/Core/ApplicationPool/Implementation.cpp +2 -2
  29. data/src/agent/Core/ApplicationPool/Options.h +18 -1
  30. data/src/agent/Core/ApplicationPool/Pool.h +1 -1
  31. data/src/agent/Core/ApplicationPool/Pool/AnalyticsCollection.cpp +6 -6
  32. data/src/agent/Core/ApplicationPool/Pool/GeneralUtils.cpp +3 -3
  33. data/src/agent/Core/ApplicationPool/Pool/InitializationAndShutdown.cpp +1 -1
  34. data/src/agent/Core/ApplicationPool/Pool/Miscellaneous.cpp +6 -0
  35. data/src/agent/Core/ApplicationPool/Process.h +6 -1
  36. data/src/agent/Core/ApplicationPool/Socket.h +9 -12
  37. data/src/agent/Core/Controller.h +422 -0
  38. data/src/agent/Core/{RequestHandler → Controller}/AppResponse.h +2 -0
  39. data/src/agent/Core/{RequestHandler → Controller}/BufferBody.cpp +27 -5
  40. data/src/agent/Core/{RequestHandler → Controller}/CheckoutSession.cpp +61 -31
  41. data/src/agent/Core/{RequestHandler → Controller}/Client.h +5 -2
  42. data/src/agent/Core/{RequestHandler → Controller}/ForwardResponse.cpp +93 -42
  43. data/src/agent/Core/{RequestHandler → Controller}/Hooks.cpp +107 -60
  44. data/src/agent/Core/Controller/Implementation.cpp +38 -0
  45. data/src/agent/Core/{RequestHandler → Controller}/InitRequest.cpp +134 -80
  46. data/src/agent/Core/Controller/InitializationAndShutdown.cpp +165 -0
  47. data/src/agent/Core/{RequestHandler/Utils.cpp → Controller/InternalUtils.cpp} +49 -32
  48. data/src/agent/Core/Controller/Miscellaneous.cpp +116 -0
  49. data/src/agent/Core/{RequestHandler → Controller}/Request.h +6 -4
  50. data/src/agent/Core/{RequestHandler → Controller}/SendRequest.cpp +205 -130
  51. data/src/agent/Core/Controller/StateInspectionAndConfiguration.cpp +161 -0
  52. data/src/agent/Core/{RequestHandler → Controller}/TurboCaching.h +3 -0
  53. data/src/agent/Core/CoreMain.cpp +62 -51
  54. data/src/agent/Core/OptionParser.h +24 -0
  55. data/src/agent/Core/ResponseCache.h +5 -5
  56. data/src/agent/Core/SpawningKit/Config.h +2 -2
  57. data/src/agent/Core/SpawningKit/SmartSpawner.h +1 -1
  58. data/src/agent/Core/UnionStation/{Core.h → Context.h} +14 -18
  59. data/src/agent/Core/UnionStation/StopwatchLog.h +3 -2
  60. data/src/agent/Core/UnionStation/Transaction.h +7 -7
  61. data/src/agent/Shared/ApiServerUtils.h +9 -1
  62. data/src/agent/UstRouter/ApiServer.h +5 -2
  63. data/src/agent/UstRouter/Controller.h +27 -9
  64. data/src/agent/UstRouter/UstRouterMain.cpp +1 -0
  65. data/src/agent/Watchdog/ApiServer.h +5 -2
  66. data/src/apache2_module/ConfigurationCommands.cpp +7 -0
  67. data/src/apache2_module/ConfigurationFields.hpp +2 -0
  68. data/src/apache2_module/ConfigurationSetters.cpp +24 -0
  69. data/src/apache2_module/CreateDirConfig.cpp +1 -0
  70. data/src/apache2_module/Hooks.cpp +6 -5
  71. data/src/apache2_module/MergeDirConfig.cpp +7 -0
  72. data/src/apache2_module/SetHeaders.cpp +5 -0
  73. data/src/cxx_supportlib/Constants.h +5 -3
  74. data/src/cxx_supportlib/SafeLibev.h +2 -1
  75. data/src/cxx_supportlib/UnionStationFilterSupport.h +2 -1
  76. data/src/cxx_supportlib/Utils/ReleaseableScopedPointer.h +70 -0
  77. data/src/cxx_supportlib/vendor-modified/boost/libs/regex/src/regex_raw_buffer.cpp +6 -6
  78. data/src/helper-scripts/node-loader.js +59 -0
  79. data/src/nginx_module/CacheLocationConfig.c +48 -0
  80. data/src/nginx_module/ConfigurationCommands.c +20 -0
  81. data/src/nginx_module/ConfigurationFields.h +4 -0
  82. data/src/nginx_module/CreateLocationConfig.c +8 -0
  83. data/src/nginx_module/MergeLocationConfig.c +12 -0
  84. data/src/nodejs_supportlib/phusion_passenger/log_express.js +106 -0
  85. data/src/nodejs_supportlib/phusion_passenger/log_mongodb.js +203 -0
  86. data/src/nodejs_supportlib/phusion_passenger/ustreporter.js +227 -0
  87. data/src/nodejs_supportlib/phusion_passenger/ustrouter_connector.js +446 -0
  88. data/src/nodejs_supportlib/vendor-copy/codify/codify.js +44 -0
  89. data/src/nodejs_supportlib/vendor-copy/codify/package.json +29 -0
  90. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/context.js +200 -0
  91. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/glue.js +488 -0
  92. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/index.js +407 -0
  93. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/node_modules/shimmer/index.js +90 -0
  94. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/node_modules/shimmer/package.json +40 -0
  95. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/package.json +54 -0
  96. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/listener.js +160 -0
  97. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/node_modules/shimmer/index.js +90 -0
  98. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/node_modules/shimmer/package.json +40 -0
  99. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/package.json +46 -0
  100. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/package.json +56 -0
  101. data/src/nodejs_supportlib/vendor-copy/network-byte-order/lib/index.js +102 -0
  102. data/src/nodejs_supportlib/vendor-copy/network-byte-order/package.json +51 -0
  103. data/src/nodejs_supportlib/vendor-copy/winston/LICENSE +19 -0
  104. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston.js +165 -0
  105. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/common.js +483 -0
  106. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config.js +62 -0
  107. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config/cli-config.js +35 -0
  108. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config/npm-config.js +27 -0
  109. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config/syslog-config.js +31 -0
  110. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/container.js +127 -0
  111. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/exception.js +56 -0
  112. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/logger.js +701 -0
  113. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports.js +34 -0
  114. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/console.js +128 -0
  115. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/daily-rotate-file.js +601 -0
  116. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/file.js +675 -0
  117. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/http.js +232 -0
  118. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/memory.js +89 -0
  119. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/transport.js +135 -0
  120. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/webhook.js +146 -0
  121. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/LICENSE +19 -0
  122. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/lib/async.js +1283 -0
  123. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/package.json +66 -0
  124. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/support/sync-package-managers.js +53 -0
  125. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/MIT-LICENSE.txt +23 -0
  126. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/colors.js +176 -0
  127. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/custom/trap.js +45 -0
  128. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/custom/zalgo.js +104 -0
  129. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/extendStringPrototype.js +118 -0
  130. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/index.js +12 -0
  131. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/america.js +12 -0
  132. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/rainbow.js +13 -0
  133. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/random.js +8 -0
  134. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/zebra.js +5 -0
  135. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/styles.js +77 -0
  136. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/system/supports-colors.js +61 -0
  137. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/package.json +35 -0
  138. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/safe.js +9 -0
  139. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/themes/generic-logging.js +12 -0
  140. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/cycle/cycle.js +170 -0
  141. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/cycle/package.json +30 -0
  142. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/eyes/LICENSE +20 -0
  143. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/eyes/lib/eyes.js +236 -0
  144. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/eyes/package.json +42 -0
  145. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/isstream/LICENSE.md +11 -0
  146. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/isstream/isstream.js +27 -0
  147. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/isstream/package.json +42 -0
  148. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/pkginfo/LICENSE +19 -0
  149. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/pkginfo/lib/pkginfo.js +136 -0
  150. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/pkginfo/package.json +56 -0
  151. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/stack-trace/License +19 -0
  152. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/stack-trace/lib/stack-trace.js +111 -0
  153. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/stack-trace/package.json +33 -0
  154. data/src/nodejs_supportlib/vendor-copy/winston/package.json +87 -0
  155. data/src/ruby_supportlib/phusion_passenger.rb +3 -4
  156. data/src/ruby_supportlib/phusion_passenger/admin_tools/instance.rb +19 -2
  157. data/src/ruby_supportlib/phusion_passenger/apache2/config_options.rb +8 -0
  158. data/src/ruby_supportlib/phusion_passenger/config/list_instances_command.rb +2 -6
  159. data/src/ruby_supportlib/phusion_passenger/config/reopen_logs_command.rb +13 -0
  160. data/src/ruby_supportlib/phusion_passenger/config/restart_app_command.rb +3 -0
  161. data/src/ruby_supportlib/phusion_passenger/config/utils.rb +9 -7
  162. data/src/ruby_supportlib/phusion_passenger/config/validate_install_command.rb +8 -1
  163. data/src/ruby_supportlib/phusion_passenger/constants.rb +3 -1
  164. data/src/ruby_supportlib/phusion_passenger/native_support.rb +20 -4
  165. data/src/ruby_supportlib/phusion_passenger/nginx/config_options.rb +8 -0
  166. data/src/ruby_supportlib/phusion_passenger/packaging.rb +1 -0
  167. data/src/ruby_supportlib/phusion_passenger/platform_info/apache_detector.rb +1 -1
  168. data/src/ruby_supportlib/phusion_passenger/platform_info/operating_system.rb +11 -4
  169. data/src/ruby_supportlib/phusion_passenger/rack/thread_handler_extension.rb +1 -1
  170. data/src/ruby_supportlib/phusion_passenger/standalone/config_options_list.rb +647 -0
  171. data/src/ruby_supportlib/phusion_passenger/standalone/config_utils.rb +229 -15
  172. data/src/ruby_supportlib/phusion_passenger/standalone/start_command.rb +35 -323
  173. data/src/ruby_supportlib/phusion_passenger/standalone/start_command/builtin_engine.rb +36 -12
  174. data/src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb +123 -14
  175. data/src/ruby_supportlib/phusion_passenger/standalone/status_command.rb +32 -17
  176. data/src/ruby_supportlib/phusion_passenger/standalone/stop_command.rb +32 -21
  177. data/src/ruby_supportlib/phusion_passenger/standalone/version_command.rb +5 -5
  178. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/README.md +2 -2
  179. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/Rakefile +5 -1
  180. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core.rb +68 -24
  181. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/api.rb +9 -1
  182. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/context.rb +9 -7
  183. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter.rb +3 -2
  184. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter/basics.rb +8 -5
  185. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/simple_json.rb +395 -0
  186. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/transaction.rb +10 -7
  187. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/utils.rb +14 -0
  188. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/version_data.rb +2 -2
  189. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml +4 -2
  190. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.example +2 -2
  191. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis +2 -2
  192. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis-with-sudo +16 -0
  193. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Gemfile +1 -1
  194. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Gemfile.lock +2 -2
  195. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/README.md +1 -1
  196. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails.rb +44 -17
  197. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/active_support_cache_subscriber.rb +16 -7
  198. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/version_data.rb +2 -2
  199. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/union_station_hooks_rails.gemspec +1 -1
  200. metadata +99 -16
  201. metadata.gz.asc +7 -7
  202. data/resources/oss-binaries.phusionpassenger.com.crt +0 -248
  203. data/src/agent/Core/RequestHandler.h +0 -471
@@ -0,0 +1,102 @@
1
+ /* Copyright 2010 Membase, Inc.
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ 'use strict';
17
+
18
+ /*jshint node:true*/
19
+
20
+
21
+ /**
22
+ * Convert a 16-bit quantity (short integer) from host byte order to network byte order (Little-Endian to Big-Endian).
23
+ *
24
+ * @param {Array|Buffer} b Array of octets or a nodejs Buffer
25
+ * @param {number} i Zero-based index at which to write into b
26
+ * @param {number} v Value to convert
27
+ */
28
+ exports.htons = function(b, i, v) {
29
+ b[i] = (0xff & (v >> 8));
30
+ b[i + 1] = (0xff & (v));
31
+ };
32
+
33
+
34
+ /**
35
+ * Convert a 16-bit quantity (short integer) from network byte order to host byte order (Big-Endian to Little-Endian).
36
+ *
37
+ * @param {Array|Buffer} b Array of octets or a nodejs Buffer to read value from
38
+ * @param {number} i Zero-based index at which to read from b
39
+ * @returns {number}
40
+ */
41
+ exports.ntohs = function(b, i) {
42
+ return ((0xff & b[i]) << 8) |
43
+ ((0xff & b[i + 1]));
44
+ };
45
+
46
+
47
+ /**
48
+ * Convert a 16-bit quantity (short integer) from network byte order to host byte order (Big-Endian to Little-Endian).
49
+ *
50
+ * @param {string} s String to read value from
51
+ * @param {number} i Zero-based index at which to read from s
52
+ * @returns {number}
53
+ */
54
+ exports.ntohsStr = function(s, i) {
55
+ return ((0xff & s.charCodeAt(i)) << 8) |
56
+ ((0xff & s.charCodeAt(i + 1)));
57
+ };
58
+
59
+
60
+ /**
61
+ * Convert a 32-bit quantity (long integer) from host byte order to network byte order (Little-Endian to Big-Endian).
62
+ *
63
+ * @param {Array|Buffer} b Array of octets or a nodejs Buffer
64
+ * @param {number} i Zero-based index at which to write into b
65
+ * @param {number} v Value to convert
66
+ */
67
+ exports.htonl = function(b, i, v) {
68
+ b[i] = (0xff & (v >> 24));
69
+ b[i + 1] = (0xff & (v >> 16));
70
+ b[i + 2] = (0xff & (v >> 8));
71
+ b[i + 3] = (0xff & (v));
72
+ };
73
+
74
+
75
+ /**
76
+ * Convert a 32-bit quantity (long integer) from network byte order to host byte order (Big-Endian to Little-Endian).
77
+ *
78
+ * @param {Array|Buffer} b Array of octets or a nodejs Buffer to read value from
79
+ * @param {number} i Zero-based index at which to read from b
80
+ * @returns {number}
81
+ */
82
+ exports.ntohl = function(b, i) {
83
+ return ((0xff & b[i]) << 24) |
84
+ ((0xff & b[i + 1]) << 16) |
85
+ ((0xff & b[i + 2]) << 8) |
86
+ ((0xff & b[i + 3]));
87
+ };
88
+
89
+
90
+ /**
91
+ * Convert a 32-bit quantity (long integer) from network byte order to host byte order (Big-Endian to Little-Endian).
92
+ *
93
+ * @param {string} s String to read value from
94
+ * @param {number} i Zero-based index at which to read from s
95
+ * @returns {number}
96
+ */
97
+ exports.ntohlStr = function(s, i) {
98
+ return ((0xff & s.charCodeAt(i)) << 24) |
99
+ ((0xff & s.charCodeAt(i + 1)) << 16) |
100
+ ((0xff & s.charCodeAt(i + 2)) << 8) |
101
+ ((0xff & s.charCodeAt(i + 3)));
102
+ };
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "network-byte-order",
3
+ "description": "htonl, htons, ntohl, ntohs - convert values between host and network byte order.",
4
+ "version": "0.2.0",
5
+ "main": "lib/index.js",
6
+ "homepage": "https://github.com/mattcg/network-byte-order",
7
+ "implements": [
8
+ "CommonJS/Modules/1.0"
9
+ ],
10
+ "contributors": [
11
+ {
12
+ "name": "Matthew Caruana Galizia",
13
+ "email": "m@m.cg"
14
+ }
15
+ ],
16
+ "keywords": [
17
+ "htonl",
18
+ "htons",
19
+ "ntohl",
20
+ "ntohs",
21
+ "byte order",
22
+ "endian",
23
+ "endianness",
24
+ "convert"
25
+ ],
26
+ "bugs": {
27
+ "url": "https://github.com/mattcg/network-byte-order/issues"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/mattcg/network-byte-order.git"
32
+ },
33
+ "licenses": [
34
+ {
35
+ "type": "Apache License, Version 2.0",
36
+ "url": "http://www.apache.org/licenses/LICENSE-2.0"
37
+ }
38
+ ],
39
+ "devDependencies": {
40
+ "jscoverage": "0.x",
41
+ "mocha": "1.x",
42
+ "mocha-lcov-reporter": "0.x",
43
+ "coveralls": "2.x"
44
+ },
45
+ "readme": "# JavaScript implementation of htonl, htons, ntohl, ntohs #\n\n[![Build Status](https://travis-ci.org/mattcg/network-byte-order.png?branch=master)](https://travis-ci.org/mattcg/network-byte-order)\n[![Coverage Status](https://coveralls.io/repos/mattcg/network-byte-order/badge.png)](https://coveralls.io/r/mattcg/network-byte-order)\n\nThese routines are used for converting values between host and [network byte order](http://en.wikipedia.org/wiki/Endianness#Endianness_in_networking).\n\nDerived from [an implementation](http://blog.couchbase.com/starting-membase-nodejs) by Membase, Inc.\n\n## Usage ##\n\n### htonl(b, i, v) ###\n\nThe `htonl()` function converts the given unsigned 32-bit (long) integer from host byte order to network byte order (Little-Endian to Big-Endian).\n\n`b` is an [`Array`](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array) of octets or a Node.JS [`Buffer`](http://nodejs.org/api/buffer.html).\n`i` is the zero-based index at which to write into `b`.\n`v` is the value to convert.\n\n### htons(b, i, v) ###\n\nThe `htons()` function converts the given unsigned 16-bit (short) integer from host byte order to network byte order (Little-Endian to Big-Endian).\n\n`b` is an [`Array`](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array) of octets or a Node.JS [`Buffer`](http://nodejs.org/api/buffer.html).\n`i` is the zero-based index at which to write into `b`.\n`v` is the value to convert.\n\n### ntohl(b, i) ###\n\nThe `ntohl()` function converts the unsigned 32-bit (long) integer from network byte order to host byte order (Big-Endian to Little-Endian).\n\n`b` is an [`Array`](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array) of octets or a Node.JS [`Buffer`](http://nodejs.org/api/buffer.html) to read the value from.\n`i` is the zero-based index at which to read from `b`.\n\n### ntohlStr(s, i) ###\n\n`s` is a `string` to the read value from.\n`i` is the zero-based index at which to read from `s`.\n\n### ntohs(b, i) ###\n\nThe `ntohs()` function converts the unsigned 16-bit (short) integer from network byte order to host byte order (Big-Endian to Little-Endian).\n\n`b` is an [`Array`](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array) of octets or a Node.JS [`Buffer`](http://nodejs.org/api/buffer.html) to read the value from.\n`i` is the zero-based index at which to read from `b`.\n\n### ntohsStr(s, i) ###\n\n`s` is a `string` to the read value from.\n`i` is the zero-based index at which to read from `s`.\n\n## License ##\n\nLicensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).\n",
46
+ "readmeFilename": "README.md",
47
+ "_id": "network-byte-order@0.2.0",
48
+ "_shasum": "6ac11bf44bf610daeddbe90a09a5c817c6e0d2b3",
49
+ "_from": "network-byte-order@^0.2.0",
50
+ "_resolved": "https://registry.npmjs.org/network-byte-order/-/network-byte-order-0.2.0.tgz"
51
+ }
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010 Charlie Robbins
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,165 @@
1
+ /*
2
+ * winston.js: Top-level include defining Winston.
3
+ *
4
+ * (C) 2010 Charlie Robbins
5
+ * MIT LICENCE
6
+ *
7
+ */
8
+
9
+ var winston = exports;
10
+
11
+ //
12
+ // Expose version using `pkginfo`
13
+ //
14
+ require('pkginfo')(module, 'version');
15
+
16
+ //
17
+ // Include transports defined by default by winston
18
+ //
19
+ winston.transports = require('./winston/transports');
20
+
21
+ //
22
+ // Expose utility methods
23
+ //
24
+ var common = require('./winston/common');
25
+ winston.hash = common.hash;
26
+ winston.clone = common.clone;
27
+ winston.longestElement = common.longestElement;
28
+ winston.exception = require('./winston/exception');
29
+ winston.config = require('./winston/config');
30
+ winston.addColors = winston.config.addColors;
31
+
32
+ //
33
+ // Expose core Logging-related prototypes.
34
+ //
35
+ winston.Container = require('./winston/container').Container;
36
+ winston.Logger = require('./winston/logger').Logger;
37
+ winston.Transport = require('./winston/transports/transport').Transport;
38
+
39
+ //
40
+ // We create and expose a default `Container` to `winston.loggers` so that the
41
+ // programmer may manage multiple `winston.Logger` instances without any additional overhead.
42
+ //
43
+ // ### some-file1.js
44
+ //
45
+ // var logger = require('winston').loggers.get('something');
46
+ //
47
+ // ### some-file2.js
48
+ //
49
+ // var logger = require('winston').loggers.get('something');
50
+ //
51
+ winston.loggers = new winston.Container();
52
+
53
+ //
54
+ // We create and expose a 'defaultLogger' so that the programmer may do the
55
+ // following without the need to create an instance of winston.Logger directly:
56
+ //
57
+ // var winston = require('winston');
58
+ // winston.log('info', 'some message');
59
+ // winston.error('some error');
60
+ //
61
+ var defaultLogger = new winston.Logger({
62
+ transports: [new winston.transports.Console()]
63
+ });
64
+
65
+ //
66
+ // Pass through the target methods onto `winston.
67
+ //
68
+ var methods = [
69
+ 'log',
70
+ 'query',
71
+ 'stream',
72
+ 'add',
73
+ 'remove',
74
+ 'clear',
75
+ 'profile',
76
+ 'startTimer',
77
+ 'extend',
78
+ 'cli',
79
+ 'handleExceptions',
80
+ 'unhandleExceptions',
81
+ 'addRewriter',
82
+ 'addFilter'
83
+ ];
84
+ common.setLevels(winston, null, defaultLogger.levels);
85
+ methods.forEach(function (method) {
86
+ winston[method] = function () {
87
+ return defaultLogger[method].apply(defaultLogger, arguments);
88
+ };
89
+ });
90
+
91
+ //
92
+ // ### function cli ()
93
+ // Configures the default winston logger to have the
94
+ // settings for command-line interfaces: no timestamp,
95
+ // colors enabled, padded output, and additional levels.
96
+ //
97
+ winston.cli = function () {
98
+ winston.padLevels = true;
99
+ common.setLevels(winston, defaultLogger.levels, winston.config.cli.levels);
100
+ defaultLogger.setLevels(winston.config.cli.levels);
101
+ winston.config.addColors(winston.config.cli.colors);
102
+
103
+ if (defaultLogger.transports.console) {
104
+ defaultLogger.transports.console.colorize = true;
105
+ defaultLogger.transports.console.timestamp = false;
106
+ }
107
+
108
+ return winston;
109
+ };
110
+
111
+ //
112
+ // ### function setLevels (target)
113
+ // #### @target {Object} Target levels to use
114
+ // Sets the `target` levels specified on the default winston logger.
115
+ //
116
+ winston.setLevels = function (target) {
117
+ common.setLevels(winston, defaultLogger.levels, target);
118
+ defaultLogger.setLevels(target);
119
+ };
120
+
121
+ //
122
+ // Define getter / setter for the default logger level
123
+ // which need to be exposed by winston.
124
+ //
125
+ Object.defineProperty(winston, 'level', {
126
+ get: function () {
127
+ return defaultLogger.level;
128
+ },
129
+ set: function (val) {
130
+ defaultLogger.level = val;
131
+
132
+ Object.keys(defaultLogger.transports).forEach(function(key) {
133
+ defaultLogger.transports[key].level = val;
134
+ });
135
+ }
136
+ });
137
+
138
+ //
139
+ // Define getters / setters for appropriate properties of the
140
+ // default logger which need to be exposed by winston.
141
+ //
142
+ ['emitErrs', 'exitOnError', 'padLevels', 'levelLength', 'stripColors'].forEach(function (prop) {
143
+ Object.defineProperty(winston, prop, {
144
+ get: function () {
145
+ return defaultLogger[prop];
146
+ },
147
+ set: function (val) {
148
+ defaultLogger[prop] = val;
149
+ }
150
+ });
151
+ });
152
+
153
+ //
154
+ // @default {Object}
155
+ // The default transports and exceptionHandlers for
156
+ // the default winston logger.
157
+ //
158
+ Object.defineProperty(winston, 'default', {
159
+ get: function () {
160
+ return {
161
+ transports: defaultLogger.transports,
162
+ exceptionHandlers: defaultLogger.exceptionHandlers
163
+ };
164
+ }
165
+ });
@@ -0,0 +1,483 @@
1
+ /*
2
+ * common.js: Internal helper and utility functions for winston
3
+ *
4
+ * (C) 2010 Charlie Robbins
5
+ * MIT LICENCE
6
+ *
7
+ */
8
+
9
+ var util = require('util'),
10
+ crypto = require('crypto'),
11
+ cycle = require('cycle'),
12
+ fs = require('fs'),
13
+ StringDecoder = require('string_decoder').StringDecoder,
14
+ Stream = require('stream').Stream,
15
+ config = require('./config');
16
+
17
+ //
18
+ // ### function setLevels (target, past, current)
19
+ // #### @target {Object} Object on which to set levels.
20
+ // #### @past {Object} Previous levels set on target.
21
+ // #### @current {Object} Current levels to set on target.
22
+ // Create functions on the target objects for each level
23
+ // in current.levels. If past is defined, remove functions
24
+ // for each of those levels.
25
+ //
26
+ exports.setLevels = function (target, past, current, isDefault) {
27
+ var self = this;
28
+ if (past) {
29
+ Object.keys(past).forEach(function (level) {
30
+ delete target[level];
31
+ });
32
+ }
33
+
34
+ target.levels = current || config.npm.levels;
35
+ if (target.padLevels) {
36
+ target.levelLength = exports.longestElement(Object.keys(target.levels));
37
+ }
38
+
39
+ //
40
+ // Define prototype methods for each log level
41
+ // e.g. target.log('info', msg) <=> target.info(msg)
42
+ //
43
+ Object.keys(target.levels).forEach(function (level) {
44
+
45
+ // TODO Refactor logging methods into a different object to avoid name clashes
46
+ if (level === 'log') {
47
+ console.warn('Log level named "log" will clash with the method "log". Consider using a different name.');
48
+ return;
49
+ }
50
+
51
+ target[level] = function (msg) {
52
+ // build argument list (level, msg, ... [string interpolate], [{metadata}], [callback])
53
+ var args = [level].concat(Array.prototype.slice.call(arguments));
54
+ target.log.apply(target, args);
55
+ };
56
+ });
57
+
58
+ return target;
59
+ };
60
+
61
+ //
62
+ // ### function longestElement
63
+ // #### @xs {Array} Array to calculate against
64
+ // Returns the longest element in the `xs` array.
65
+ //
66
+ exports.longestElement = function (xs) {
67
+ return Math.max.apply(
68
+ null,
69
+ xs.map(function (x) { return x.length; })
70
+ );
71
+ };
72
+
73
+ //
74
+ // ### function clone (obj)
75
+ // #### @obj {Object} Object to clone.
76
+ // Helper method for deep cloning pure JSON objects
77
+ // i.e. JSON objects that are either literals or objects (no Arrays, etc)
78
+ //
79
+ exports.clone = function (obj) {
80
+ //
81
+ // We only need to clone reference types (Object)
82
+ //
83
+ var copy = {};
84
+
85
+ if (obj instanceof Error) {
86
+ // With potential custom Error objects, this might not be exactly correct,
87
+ // but probably close-enough for purposes of this lib.
88
+ copy = new Error(obj.message);
89
+ Object.getOwnPropertyNames(obj).forEach(function (key) {
90
+ copy[key] = obj[key];
91
+ });
92
+
93
+ return copy;
94
+ }
95
+ else if (!(obj instanceof Object)) {
96
+ return obj;
97
+ }
98
+ else if (obj instanceof Date) {
99
+ return new Date(obj.getTime());
100
+ }
101
+
102
+ for (var i in obj) {
103
+ if (Array.isArray(obj[i])) {
104
+ copy[i] = obj[i].slice(0);
105
+ }
106
+ else if (obj[i] instanceof Buffer) {
107
+ copy[i] = obj[i].slice(0);
108
+ }
109
+ else if (typeof obj[i] != 'function') {
110
+ copy[i] = obj[i] instanceof Object ? exports.clone(obj[i]) : obj[i];
111
+ }
112
+ else if (typeof obj[i] === 'function') {
113
+ copy[i] = obj[i];
114
+ }
115
+ }
116
+
117
+ return copy;
118
+ };
119
+
120
+ //
121
+ // ### function log (options)
122
+ // #### @options {Object} All information about the log serialization.
123
+ // Generic logging function for returning timestamped strings
124
+ // with the following options:
125
+ //
126
+ // {
127
+ // level: 'level to add to serialized message',
128
+ // message: 'message to serialize',
129
+ // meta: 'additional logging metadata to serialize',
130
+ // colorize: false, // Colorizes output (only if `.json` is false)
131
+ // align: false // Align message level.
132
+ // timestamp: true // Adds a timestamp to the serialized message
133
+ // label: 'label to prepend the message'
134
+ // }
135
+ //
136
+ exports.log = function (options) {
137
+ var timestampFn = typeof options.timestamp === 'function'
138
+ ? options.timestamp
139
+ : exports.timestamp,
140
+ timestamp = options.timestamp ? timestampFn() : null,
141
+ showLevel = options.showLevel === undefined ? true : options.showLevel,
142
+ meta = options.meta !== null && options.meta !== undefined && !(options.meta instanceof Error)
143
+ ? exports.clone(cycle.decycle(options.meta))
144
+ : options.meta || null,
145
+ output;
146
+
147
+ //
148
+ // raw mode is intended for outputing winston as streaming JSON to STDOUT
149
+ //
150
+ if (options.raw) {
151
+ if (typeof meta !== 'object' && meta != null) {
152
+ meta = { meta: meta };
153
+ }
154
+ output = exports.clone(meta) || {};
155
+ output.level = options.level;
156
+ //
157
+ // Remark (jcrugzz): This used to be output.message = options.message.stripColors.
158
+ // I do not know why this is, it does not make sense but im handling that
159
+ // case here as well as handling the case that does make sense which is to
160
+ // make the `output.message = options.message`
161
+ //
162
+ output.message = options.message.stripColors
163
+ ? options.message.stripColors
164
+ : options.message;
165
+
166
+ return JSON.stringify(output);
167
+ }
168
+
169
+ //
170
+ // json mode is intended for pretty printing multi-line json to the terminal
171
+ //
172
+ if (options.json || true === options.logstash) {
173
+ if (typeof meta !== 'object' && meta != null) {
174
+ meta = { meta: meta };
175
+ }
176
+
177
+ output = exports.clone(meta) || {};
178
+ output.level = options.level;
179
+ output.message = output.message || '';
180
+
181
+ if (options.label) { output.label = options.label; }
182
+ if (options.message) { output.message = options.message; }
183
+ if (timestamp) { output.timestamp = timestamp; }
184
+
185
+ if (options.logstash === true) {
186
+ // use logstash format
187
+ var logstashOutput = {};
188
+ if (output.message !== undefined) {
189
+ logstashOutput['@message'] = output.message;
190
+ delete output.message;
191
+ }
192
+
193
+ if (output.timestamp !== undefined) {
194
+ logstashOutput['@timestamp'] = output.timestamp;
195
+ delete output.timestamp;
196
+ }
197
+
198
+ logstashOutput['@fields'] = exports.clone(output);
199
+ output = logstashOutput;
200
+ }
201
+
202
+ if (typeof options.stringify === 'function') {
203
+ return options.stringify(output);
204
+ }
205
+
206
+ return JSON.stringify(output, function (key, value) {
207
+ return value instanceof Buffer
208
+ ? value.toString('base64')
209
+ : value;
210
+ });
211
+ }
212
+
213
+ //
214
+ // Remark: this should really be a call to `util.format`.
215
+ //
216
+ if (typeof options.formatter == 'function') {
217
+ return String(options.formatter(exports.clone(options)));
218
+ }
219
+
220
+ output = timestamp ? timestamp + ' - ' : '';
221
+ if (showLevel) {
222
+ output += options.colorize === 'all' || options.colorize === 'level' || options.colorize === true
223
+ ? config.colorize(options.level)
224
+ : options.level;
225
+ }
226
+
227
+ output += (options.align) ? '\t' : '';
228
+ output += (timestamp || showLevel) ? ': ' : '';
229
+ output += options.label ? ('[' + options.label + '] ') : '';
230
+ output += options.colorize === 'all' || options.colorize === 'message'
231
+ ? config.colorize(options.level, options.message)
232
+ : options.message;
233
+
234
+ if (meta !== null && meta !== undefined) {
235
+ if (meta && meta instanceof Error && meta.stack) {
236
+ meta = meta.stack;
237
+ }
238
+
239
+ if (typeof meta !== 'object') {
240
+ output += ' ' + meta;
241
+ }
242
+ else if (Object.keys(meta).length > 0) {
243
+ if (typeof options.prettyPrint === 'function') {
244
+ output += ' ' + options.prettyPrint(meta);
245
+ } else if (options.prettyPrint) {
246
+ output += ' ' + '\n' + util.inspect(meta, false, options.depth || null, options.colorize);
247
+ } else if (
248
+ options.humanReadableUnhandledException
249
+ && Object.keys(meta).length === 5
250
+ && meta.hasOwnProperty('date')
251
+ && meta.hasOwnProperty('process')
252
+ && meta.hasOwnProperty('os')
253
+ && meta.hasOwnProperty('trace')
254
+ && meta.hasOwnProperty('stack')) {
255
+
256
+ //
257
+ // If meta carries unhandled exception data serialize the stack nicely
258
+ //
259
+ var stack = meta.stack;
260
+ delete meta.stack;
261
+ delete meta.trace;
262
+ output += ' ' + exports.serialize(meta);
263
+ output += '\n' + stack.join('\n');
264
+ } else {
265
+ output += ' ' + exports.serialize(meta);
266
+ }
267
+ }
268
+ }
269
+
270
+ return output;
271
+ };
272
+
273
+ exports.capitalize = function (str) {
274
+ return str && str[0].toUpperCase() + str.slice(1);
275
+ };
276
+
277
+ //
278
+ // ### function hash (str)
279
+ // #### @str {string} String to hash.
280
+ // Utility function for creating unique ids
281
+ // e.g. Profiling incoming HTTP requests on the same tick
282
+ //
283
+ exports.hash = function (str) {
284
+ return crypto.createHash('sha1').update(str).digest('hex');
285
+ };
286
+
287
+ //
288
+ // ### function pad (n)
289
+ // Returns a padded string if `n < 10`.
290
+ //
291
+ exports.pad = function (n) {
292
+ return n < 10 ? '0' + n.toString(10) : n.toString(10);
293
+ };
294
+
295
+ //
296
+ // ### function timestamp ()
297
+ // Returns a timestamp string for the current time.
298
+ //
299
+ exports.timestamp = function () {
300
+ return new Date().toISOString();
301
+ };
302
+
303
+ //
304
+ // ### function serialize (obj, key)
305
+ // #### @obj {Object|literal} Object to serialize
306
+ // #### @key {string} **Optional** Optional key represented by obj in a larger object
307
+ // Performs simple comma-separated, `key=value` serialization for Loggly when
308
+ // logging to non-JSON inputs.
309
+ //
310
+ exports.serialize = function (obj, key) {
311
+ if (obj === null) {
312
+ obj = 'null';
313
+ }
314
+ else if (obj === undefined) {
315
+ obj = 'undefined';
316
+ }
317
+ else if (obj === false) {
318
+ obj = 'false';
319
+ }
320
+
321
+ if (typeof obj !== 'object') {
322
+ return key ? key + '=' + obj : obj;
323
+ }
324
+
325
+ if (obj instanceof Buffer) {
326
+ return key ? key + '=' + obj.toString('base64') : obj.toString('base64');
327
+ }
328
+
329
+ var msg = '',
330
+ keys = Object.keys(obj),
331
+ length = keys.length;
332
+
333
+ for (var i = 0; i < length; i++) {
334
+ if (Array.isArray(obj[keys[i]])) {
335
+ msg += keys[i] + '=[';
336
+
337
+ for (var j = 0, l = obj[keys[i]].length; j < l; j++) {
338
+ msg += exports.serialize(obj[keys[i]][j]);
339
+ if (j < l - 1) {
340
+ msg += ', ';
341
+ }
342
+ }
343
+
344
+ msg += ']';
345
+ }
346
+ else if (obj[keys[i]] instanceof Date) {
347
+ msg += keys[i] + '=' + obj[keys[i]];
348
+ }
349
+ else {
350
+ msg += exports.serialize(obj[keys[i]], keys[i]);
351
+ }
352
+
353
+ if (i < length - 1) {
354
+ msg += ', ';
355
+ }
356
+ }
357
+
358
+ return msg;
359
+ };
360
+
361
+ //
362
+ // ### function tailFile (options, callback)
363
+ // #### @options {Object} Options for tail.
364
+ // #### @callback {function} Callback to execute on every line.
365
+ // `tail -f` a file. Options must include file.
366
+ //
367
+ exports.tailFile = function(options, callback) {
368
+ var buffer = new Buffer(64 * 1024)
369
+ , decode = new StringDecoder('utf8')
370
+ , stream = new Stream
371
+ , buff = ''
372
+ , pos = 0
373
+ , row = 0;
374
+
375
+ if (options.start === -1) {
376
+ delete options.start;
377
+ }
378
+
379
+ stream.readable = true;
380
+ stream.destroy = function() {
381
+ stream.destroyed = true;
382
+ stream.emit('end');
383
+ stream.emit('close');
384
+ };
385
+
386
+ fs.open(options.file, 'a+', '0644', function(err, fd) {
387
+ if (err) {
388
+ if (!callback) {
389
+ stream.emit('error', err);
390
+ } else {
391
+ callback(err);
392
+ }
393
+ stream.destroy();
394
+ return;
395
+ }
396
+
397
+ (function read() {
398
+ if (stream.destroyed) {
399
+ fs.close(fd);
400
+ return;
401
+ }
402
+
403
+ return fs.read(fd, buffer, 0, buffer.length, pos, function(err, bytes) {
404
+ if (err) {
405
+ if (!callback) {
406
+ stream.emit('error', err);
407
+ } else {
408
+ callback(err);
409
+ }
410
+ stream.destroy();
411
+ return;
412
+ }
413
+
414
+ if (!bytes) {
415
+ if (buff) {
416
+ if (options.start == null || row > options.start) {
417
+ if (!callback) {
418
+ stream.emit('line', buff);
419
+ } else {
420
+ callback(null, buff);
421
+ }
422
+ }
423
+ row++;
424
+ buff = '';
425
+ }
426
+ return setTimeout(read, 1000);
427
+ }
428
+
429
+ var data = decode.write(buffer.slice(0, bytes));
430
+
431
+ if (!callback) {
432
+ stream.emit('data', data);
433
+ }
434
+
435
+ var data = (buff + data).split(/\n+/)
436
+ , l = data.length - 1
437
+ , i = 0;
438
+
439
+ for (; i < l; i++) {
440
+ if (options.start == null || row > options.start) {
441
+ if (!callback) {
442
+ stream.emit('line', data[i]);
443
+ } else {
444
+ callback(null, data[i]);
445
+ }
446
+ }
447
+ row++;
448
+ }
449
+
450
+ buff = data[l];
451
+
452
+ pos += bytes;
453
+
454
+ return read();
455
+ });
456
+ })();
457
+ });
458
+
459
+ if (!callback) {
460
+ return stream;
461
+ }
462
+
463
+ return stream.destroy;
464
+ };
465
+
466
+ //
467
+ // ### function stringArrayToSet (array)
468
+ // #### @strArray {Array} Array of Set-elements as strings.
469
+ // #### @errMsg {string} **Optional** Custom error message thrown on invalid input.
470
+ // Returns a Set-like object with strArray's elements as keys (each with the value true).
471
+ //
472
+ exports.stringArrayToSet = function (strArray, errMsg) {
473
+ if (typeof errMsg === 'undefined') {
474
+ errMsg = 'Cannot make set from Array with non-string elements';
475
+ }
476
+ return strArray.reduce(function (set, el) {
477
+ if (!(typeof el === 'string' || el instanceof String)) {
478
+ throw new Error(errMsg);
479
+ }
480
+ set[el] = true;
481
+ return set;
482
+ }, Object.create(null));
483
+ };