batman-rails-flo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +29 -0
  3. data/Rakefile +2 -0
  4. data/lib/batman-rails-flo.rb +5 -0
  5. data/lib/batman_rails_flo/railtie.rb +9 -0
  6. data/lib/batman_rails_flo/tasks.rake +14 -0
  7. data/lib/batman_rails_flo/version.rb +3 -0
  8. data/vendor/assets/javascripts/batman_rails_flo/flo_server.js +67 -0
  9. data/vendor/assets/javascripts/batman_rails_flo/live_reload.js.coffee +129 -0
  10. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/CNAME +1 -0
  11. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/CONTRIBUTING.md +9 -0
  12. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/LICENSE +22 -0
  13. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/README +50 -0
  14. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/bin/cake +7 -0
  15. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/bin/coffee +7 -0
  16. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/browser.js +134 -0
  17. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/cake.js +112 -0
  18. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/coffee-script.js +335 -0
  19. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/command.js +569 -0
  20. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/grammar.js +631 -0
  21. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/helpers.js +252 -0
  22. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/index.js +11 -0
  23. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/lexer.js +926 -0
  24. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/nodes.js +3158 -0
  25. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/optparse.js +139 -0
  26. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/parser.js +724 -0
  27. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/register.js +66 -0
  28. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/repl.js +163 -0
  29. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/rewriter.js +475 -0
  30. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/scope.js +146 -0
  31. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/sourcemap.js +161 -0
  32. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/LICENSE +21 -0
  33. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/examples/pow.js +6 -0
  34. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/index.js +82 -0
  35. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/package.json +34 -0
  36. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/readme.markdown +63 -0
  37. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/chmod.js +38 -0
  38. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/clobber.js +37 -0
  39. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/mkdirp.js +28 -0
  40. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/perm.js +32 -0
  41. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/perm_sync.js +39 -0
  42. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/race.js +41 -0
  43. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/rel.js +32 -0
  44. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/return.js +25 -0
  45. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/return_sync.js +24 -0
  46. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/root.js +18 -0
  47. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/sync.js +32 -0
  48. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/umask.js +28 -0
  49. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/umask_sync.js +32 -0
  50. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/package.json +50 -0
  51. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/register.js +1 -0
  52. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/LICENSE +30 -0
  53. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/PATENTS +23 -0
  54. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/README.md +124 -0
  55. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/bin/flo +26 -0
  56. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/configure/configure.html +57 -0
  57. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/configure/configure.js +205 -0
  58. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/configure/style.css +334 -0
  59. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/connection.js +235 -0
  60. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/devtools.html +12 -0
  61. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/index.js +323 -0
  62. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/logger.js +42 -0
  63. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/logo.png +0 -0
  64. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/manifest.json +13 -0
  65. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/session.js +305 -0
  66. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/index.js +10 -0
  67. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/lib/flo.js +226 -0
  68. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/lib/server.js +94 -0
  69. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/README.md +66 -0
  70. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/index.js +437 -0
  71. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/LICENSE +23 -0
  72. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/README.md +218 -0
  73. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/minimatch.js +1055 -0
  74. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/CONTRIBUTORS +14 -0
  75. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/LICENSE +23 -0
  76. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/README.md +97 -0
  77. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/lib/lru-cache.js +252 -0
  78. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/package.json +33 -0
  79. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/test/basic.js +369 -0
  80. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/test/foreach.js +52 -0
  81. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/test/memory-leak.js +50 -0
  82. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/LICENSE +27 -0
  83. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/README.md +53 -0
  84. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/bench.js +283 -0
  85. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/package.json +42 -0
  86. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/sigmund.js +39 -0
  87. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/test/basic.js +24 -0
  88. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/package.json +40 -0
  89. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/basic.js +399 -0
  90. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/brace-expand.js +33 -0
  91. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/caching.js +14 -0
  92. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/defaults.js +274 -0
  93. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/extglob-ending-with-state-char.js +8 -0
  94. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/lib/walker.js +111 -0
  95. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/license +13 -0
  96. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/lib/makeerror.js +87 -0
  97. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/node_modules/tmpl/lib/tmpl.js +17 -0
  98. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/node_modules/tmpl/package.json +31 -0
  99. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/node_modules/tmpl/readme.md +10 -0
  100. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/package.json +34 -0
  101. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/readme.md +77 -0
  102. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/package.json +36 -0
  103. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/readme.md +52 -0
  104. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/LICENSE +55 -0
  105. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/main.js +128 -0
  106. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/package.json +34 -0
  107. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/readme.mkd +72 -0
  108. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/d/d/t +0 -0
  109. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/d/t +0 -0
  110. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/test_monitor.js +31 -0
  111. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/test_monitorRootDirectory.js +28 -0
  112. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/test_watchTree.js +20 -0
  113. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/package.json +45 -0
  114. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/test/test.js +243 -0
  115. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/CHANGELOG.md +81 -0
  116. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/LICENSE +177 -0
  117. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/Makefile +11 -0
  118. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/README.md +245 -0
  119. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/binding.gyp +14 -0
  120. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Makefile +355 -0
  121. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/linker.lock +0 -0
  122. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/obj.target/validation/src/validation.o +0 -0
  123. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/obj.target/xor/src/xor.o +0 -0
  124. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/validation.node +0 -0
  125. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/xor.node +0 -0
  126. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/binding.Makefile +6 -0
  127. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/config.gypi +115 -0
  128. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/gyp-mac-tool +512 -0
  129. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/validation.target.mk +154 -0
  130. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/xor.target.mk +154 -0
  131. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/index.js +1 -0
  132. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/install.js +31 -0
  133. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Constants.js +23 -0
  134. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Deprecation.js +38 -0
  135. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Validation.fallback.js +12 -0
  136. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Validation.js +18 -0
  137. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketClient.js +359 -0
  138. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketConnection.js +717 -0
  139. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketFrame.js +282 -0
  140. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketRequest.js +478 -0
  141. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketRouter.js +154 -0
  142. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketRouterRequest.js +59 -0
  143. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketServer.js +216 -0
  144. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/utils.js +7 -0
  145. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/websocket.js +11 -0
  146. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/xor.fallback.js +13 -0
  147. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/xor.js +18 -0
  148. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/package.json +43 -0
  149. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/src/validation.cc +144 -0
  150. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/src/xor.cpp +86 -0
  151. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/vendor/FastBufferList.js +192 -0
  152. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/vendor/node-ctype/LICENSE +18 -0
  153. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/vendor/node-ctype/ctio-faster.js +1126 -0
  154. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/package.json +25 -0
  155. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/browser_websocket.js +63 -0
  156. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/connection_test.js +57 -0
  157. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/logger_mock.js +15 -0
  158. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/session_test.js +194 -0
  159. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/server/flo_test.js +211 -0
  160. data/vendor/assets/javascripts/batman_rails_flo/package.json +15 -0
  161. data/vendor/assets/javascripts/batman_rails_flo/reload_event_handler.js.coffee +56 -0
  162. metadata +232 -0
@@ -0,0 +1,13 @@
1
+ module.exports = {
2
+ xor: function (payload, maskBytes, maskPos) {
3
+ var end = payload.length;
4
+ if (typeof(maskPos) !== 'number') {
5
+ maskPos = 0;
6
+ }
7
+ for (var i=0; i < end; i++) {
8
+ payload[i] = payload[i] ^ maskBytes[maskPos];
9
+ maskPos = (maskPos + 1) & 3;
10
+ }
11
+ return maskPos;
12
+ }
13
+ };
@@ -0,0 +1,18 @@
1
+ /*
2
+ * Buffer xor module
3
+ * Copyright (c) Agora S.A.
4
+ * Licensed under the MIT License.
5
+ * Version: 1.0
6
+ */
7
+
8
+ try {
9
+ module.exports = require('../build/Release/xor');
10
+ } catch (e) { try {
11
+ module.exports = require('../build/default/xor');
12
+ } catch(e) { try {
13
+ module.exports = require('./xor.fallback');
14
+ console.warn("Warning: Native modules not compiled. XOR performance will be degraded.")
15
+ } catch (e) {
16
+ console.error("xor.node seems not to have been built. Run npm install.")
17
+ throw e;
18
+ }}}
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "websocket",
3
+ "description": "Websocket Client & Server Library implementing the WebSocket protocol as specified in RFC 6455.",
4
+ "keywords": [
5
+ "websocket",
6
+ "websockets",
7
+ "socket",
8
+ "networking",
9
+ "comet",
10
+ "push"
11
+ ],
12
+ "author": {
13
+ "name": "Brian McKelvey",
14
+ "email": "brian@worlize.com",
15
+ "url": "https://www.worlize.com/"
16
+ },
17
+ "version": "1.0.8",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "http://github.com/Worlize/WebSocket-Node.git"
21
+ },
22
+ "engines": {
23
+ "node": ">=0.6.10"
24
+ },
25
+ "config": {
26
+ "verbose": false
27
+ },
28
+ "scripts": {
29
+ "install": "node install.js"
30
+ },
31
+ "main": "index",
32
+ "directories": {
33
+ "lib": "./lib"
34
+ },
35
+ "readme": "WebSocket Client & Server Implementation for Node\n=================================================\n\nOverview\n--------\nThis is a (mostly) pure JavaScript implementation of the WebSocket protocol versions 8 and 13 for Node. There are some example client and server applications that implement various interoperability testing protocols in the \"test\" folder.\n\nCurrent News\n------------\n\n- As of version 1.0.7, ***Native modules are now optional.*** If they fail to compile, WebSocket-Node will still work but will not verify that received UTF-8 data is valid, and xor masking/unmasking of payload data for security purposes will not be as efficient as it is performed in JavaScript instead of native code.\n\n- Version 1.0.7 requires node v0.6.10, since that's the first version that I can manage to successfully build the native extensions with node-gyp through npm. If anyone can figure out how to build native extensions in a way that works with both older and newer versions of Node, I'm happy to accept a patch!\n\n- If you want to support Unicode characters outside the Basic Multilingual Plane (BMP) you must use Node v0.8.x, which added support for representing these characters as surrogate pairs inside JavaScript strings. Under Node v0.6.x, characters with code points greater than 65535 (greater than a 16-bit unsigned value) will have their code point truncated, resulting in seemingly unpredictable characters being returned.\n\n- WebSocket-Node was already [one of the fastest WebSocket libraries for Node](http://hobbycoding.posterous.com/websockt-binary-data-transfer-benchmark-rsult), and thanks to a small patch from [kazuyukitanimura](https://github.com/kazuyukitanimura), this library is now [up to 200% faster](http://hobbycoding.posterous.com/how-to-make-websocket-work-2x-faster-on-nodej) as of version 1.0.3!\n\nChangelog\n---------\n\nCurrent Version: 1.0.7\n\n[View the changelog](https://github.com/Worlize/WebSocket-Node/blob/master/CHANGELOG.md)\n\nBrowser Support\n---------------\n\n* Firefox 7-9 (Old) (Protocol Version 8)\n* Firefox 10+ (Protocol Version 13)\n* Chrome 14,15 (Old) (Protocol Version 8)\n* Chrome 16+ (Protocol Version 13)\n* Internet Explorer 10 (Preview) (Protocol Version 13)\n* Safari 6 (Protocol Version 13)\n\n***Safari older than 6.0 is not supported since it uses a very old draft of WebSockets***\n\nI made a decision early on to explicitly avoid maintaining multiple slightly different copies of the same code just to support the browsers currently in the wild. The major browsers that support WebSocket are on a rapid-release schedule (with the exception of Safari) and now that the final version of the protocol has been [published as an official RFC](http://datatracker.ietf.org/doc/rfc6455/), it won't be long before support in the wild stabilizes on that version. My client application is in Flash/ActionScript 3, so for my purposes I'm not dependent on the browser implementations. *I made an exception to my stated intention here to support protocol version 8 along with 13, since only one minor thing changed and it was trivial to handle conditionally.* The library now interoperates with other clients and servers implementing draft -08 all the way up through the final RFC.\n\n***If you need to simultaneously support legacy browser versions that had implemented draft-75/draft-76/draft-00, take a look here: https://gist.github.com/1428579***\n\nFor a WebSocket client written in ActionScript 3, see my [AS3WebScocket](https://github.com/Worlize/AS3WebSocket) project.\n\nBenchmarks\n----------\nThere are some basic benchmarking sections in the Autobahn test suite. I've put up a [benchmark page](http://worlize.github.com/WebSocket-Node/benchmarks/) that shows the results from the Autobahn tests run against AutobahnServer 0.4.10, WebSocket-Node 1.0.2, WebSocket-Node 1.0.4, and ws 0.3.4.\n\nAutobahn Tests\n--------------\nThe very complete [Autobahn Test Suite](http://www.tavendo.de/autobahn/testsuite.html) is used by most WebSocket implementations to test spec compliance and interoperability.\n\n**Note about failing UTF-8 tests:** There are some UTF-8 validation tests that fail due to the fact that according to the ECMAScript spec, V8 and subsequently Node cannot support Unicode characters outside the BMP (Basic Multilingual Plane.) JavaScript's String.fromCharCode() function truncates all code points to 16-bit, so you cannot decode higher plane code points in JavaScript. Google's V8 uses UCS-2 as its internal string representation, and [they have no intention to change that any time soon](http://code.google.com/p/v8/issues/detail?id=761), so it is not possible to decode higher plane code points in C++, to the best of my knowledge, because those characters are not representable in UCS-2 anyway. The Autobahn Test Suite requires that all valid Unicode code points survive a complete round trip, including code points that represent non-existent characters and characters above the BMP. Since JavaScript cannot represent any characters with a code point >= 65535, no JavaScript implementation of WebSockets can pass these UTF-8 tests without using a cheat, such as echoing back the original binary data without decoding and re-encoding the UTF-8 data, which is not representative of real-world practical application. ***I do not consider this to be a problem in the majority of circumstances*** since it is very unlikely to cause major issues in any real-world application as long as you don't need to use characters outside the BMP.\n**Update:** This issue seems to have been resolved in the version of V8 used in Node 0.8.x. I believe they are using surrogate-pairs to accommodate characters that are outside the BMP, but I haven't looked into it.\n\n- [View Server Test Results](http://worlize.github.com/WebSocket-Node/test-report/servers/)\n- [View Client Test Results](http://worlize.github.com/WebSocket-Node/test-report/clients/)\n\nNotes\n-----\nThis library has been used in production on [worlize.com](https://www.worlize.com) since April 2011 and seems to be stable. Your mileage may vary.\n\n**Tested with the following node versions:**\n\n- 0.6.18\n- 0.8.6\n\nIt may work in earlier or later versions but I'm not actively testing it outside of the listed versions. YMMV.\n\nDocumentation\n=============\n\nFor more complete documentation, see the [Documentation Wiki](https://github.com/Worlize/WebSocket-Node/wiki/Documentation).\n\nInstallation\n------------\n\nA few users have reported difficulties building the native extensions without first manually installing node-gyp. If you have trouble building the native extensions, make sure you've got a C++ compiler, and have done `npm install -g node-gyp` first. \n\nNative extensions are optional, however, and WebSocket-Node will work even if the extensions cannot be compiled.\n\nIn your project root:\n\n $ npm install websocket\n \nThen in your code:\n\n```javascript\nvar WebSocketServer = require('websocket').server;\nvar WebSocketClient = require('websocket').client;\nvar WebSocketFrame = require('websocket').frame;\nvar WebSocketRouter = require('websocket').router;\n```\n\nNote for Windows Users\n----------------------\nBecause there is a small C++ component used for validating UTF-8 data, you will need to install a few other software packages in addition to Node to be able to build this module:\n\n- [Microsoft Visual C++](http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express)\n- [Python 2.7](http://www.python.org/download/) (NOT Python 3.x)\n\n\nCurrent Features:\n-----------------\n- Licensed under the Apache License, Version 2.0\n- Protocol version \"8\" and \"13\" (Draft-08 through the final RFC) framing and handshake\n- Can handle/aggregate received fragmented messages\n- Can fragment outgoing messages\n- Router to mount multiple applications to various path and protocol combinations\n- TLS supported for outbound connections via WebSocketClient\n- TLS supported for server connections (use https.createServer instead of http.createServer)\n - Thanks to [pors](https://github.com/pors) for confirming this!\n- Cookie setting and parsing\n- Tunable settings\n - Max Receivable Frame Size\n - Max Aggregate ReceivedMessage Size\n - Whether to fragment outgoing messages\n - Fragmentation chunk size for outgoing messages\n - Whether to automatically send ping frames for the purposes of keepalive\n - Keep-alive ping interval\n - Whether or not to automatically assemble received fragments (allows application to handle individual fragments directly)\n - How long to wait after sending a close frame for acknowledgment before closing the socket.\n\n\nKnown Issues/Missing Features:\n------------------------------\n- No API for user-provided protocol extensions.\n\n\nUsage Examples\n==============\n\nServer Example\n--------------\n\nHere's a short example showing a server that echos back anything sent to it, whether utf-8 or binary.\n\n```javascript\n#!/usr/bin/env node\nvar WebSocketServer = require('websocket').server;\nvar http = require('http');\n\nvar server = http.createServer(function(request, response) {\n console.log((new Date()) + ' Received request for ' + request.url);\n response.writeHead(404);\n response.end();\n});\nserver.listen(8080, function() {\n console.log((new Date()) + ' Server is listening on port 8080');\n});\n\nwsServer = new WebSocketServer({\n httpServer: server,\n // You should not use autoAcceptConnections for production\n // applications, as it defeats all standard cross-origin protection\n // facilities built into the protocol and the browser. You should\n // *always* verify the connection's origin and decide whether or not\n // to accept it.\n autoAcceptConnections: false\n});\n\nfunction originIsAllowed(origin) {\n // put logic here to detect whether the specified origin is allowed.\n return true;\n}\n\nwsServer.on('request', function(request) {\n if (!originIsAllowed(request.origin)) {\n // Make sure we only accept requests from an allowed origin\n request.reject();\n console.log((new Date()) + ' Connection from origin ' + request.origin + ' rejected.');\n return;\n }\n \n var connection = request.accept('echo-protocol', request.origin);\n console.log((new Date()) + ' Connection accepted.');\n connection.on('message', function(message) {\n if (message.type === 'utf8') {\n console.log('Received Message: ' + message.utf8Data);\n connection.sendUTF(message.utf8Data);\n }\n else if (message.type === 'binary') {\n console.log('Received Binary Message of ' + message.binaryData.length + ' bytes');\n connection.sendBytes(message.binaryData);\n }\n });\n connection.on('close', function(reasonCode, description) {\n console.log((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected.');\n });\n});\n```\n\nClient Example\n--------------\n\nThis is a simple example client that will print out any utf-8 messages it receives on the console, and periodically sends a random number.\n\n*This code demonstrates a client in Node.js, not in the browser*\n\n```javascript\n#!/usr/bin/env node\nvar WebSocketClient = require('websocket').client;\n\nvar client = new WebSocketClient();\n\nclient.on('connectFailed', function(error) {\n console.log('Connect Error: ' + error.toString());\n});\n\nclient.on('connect', function(connection) {\n console.log('WebSocket client connected');\n connection.on('error', function(error) {\n console.log(\"Connection Error: \" + error.toString());\n });\n connection.on('close', function() {\n console.log('echo-protocol Connection Closed');\n });\n connection.on('message', function(message) {\n if (message.type === 'utf8') {\n console.log(\"Received: '\" + message.utf8Data + \"'\");\n }\n });\n \n function sendNumber() {\n if (connection.connected) {\n var number = Math.round(Math.random() * 0xFFFFFF);\n connection.sendUTF(number.toString());\n setTimeout(sendNumber, 1000);\n }\n }\n sendNumber();\n});\n\nclient.connect('ws://localhost:8080/', 'echo-protocol');\n```\n \nRequest Router Example\n----------------------\n\nFor an example of using the request router, see `libwebsockets-test-server.js` in the `test` folder.\n\n\nResources\n---------\n\nA presentation on the state of the WebSockets protocol that I gave on July 23, 2011 at the LA Hacker News meetup. [WebSockets: The Real-Time Web, Delivered](http://www.scribd.com/doc/60898569/WebSockets-The-Real-Time-Web-Delivered)",
36
+ "readmeFilename": "README.md",
37
+ "bugs": {
38
+ "url": "https://github.com/Worlize/WebSocket-Node/issues"
39
+ },
40
+ "homepage": "https://github.com/Worlize/WebSocket-Node",
41
+ "_id": "websocket@1.0.8",
42
+ "_from": "websocket@~1.0.8"
43
+ }
@@ -0,0 +1,144 @@
1
+ /*!
2
+ * UTF-8 Validation Code originally from:
3
+ * ws: a node.js websocket client
4
+ * Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com>
5
+ * MIT Licensed
6
+ */
7
+
8
+ #include <v8.h>
9
+ #include <node.h>
10
+ #include <node_buffer.h>
11
+ #include <node_object_wrap.h>
12
+ #include <stdlib.h>
13
+ #include <wchar.h>
14
+ #include <stdio.h>
15
+
16
+ using namespace v8;
17
+ using namespace node;
18
+
19
+ #define UNI_SUR_HIGH_START (uint32_t) 0xD800
20
+ #define UNI_SUR_LOW_END (uint32_t) 0xDFFF
21
+ #define UNI_REPLACEMENT_CHAR (uint32_t) 0x0000FFFD
22
+ #define UNI_MAX_LEGAL_UTF32 (uint32_t) 0x0010FFFF
23
+
24
+ static const uint8_t trailingBytesForUTF8[256] = {
25
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
26
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
27
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
28
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
29
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
30
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
31
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
32
+ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
33
+ };
34
+
35
+ static const uint32_t offsetsFromUTF8[6] = {
36
+ 0x00000000, 0x00003080, 0x000E2080,
37
+ 0x03C82080, 0xFA082080, 0x82082080
38
+ };
39
+
40
+ static int isLegalUTF8(const uint8_t *source, const int length)
41
+ {
42
+ uint8_t a;
43
+ const uint8_t *srcptr = source+length;
44
+ switch (length) {
45
+ default: return 0;
46
+ /* Everything else falls through when "true"... */
47
+ /* RFC3629 makes 5 & 6 bytes UTF-8 illegal
48
+ case 6: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return 0;
49
+ case 5: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return 0; */
50
+ case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return 0;
51
+ case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return 0;
52
+ case 2: if ((a = (*--srcptr)) > 0xBF) return 0;
53
+ switch (*source) {
54
+ /* no fall-through in this inner switch */
55
+ case 0xE0: if (a < 0xA0) return 0; break;
56
+ case 0xED: if (a > 0x9F) return 0; break;
57
+ case 0xF0: if (a < 0x90) return 0; break;
58
+ case 0xF4: if (a > 0x8F) return 0; break;
59
+ default: if (a < 0x80) return 0;
60
+ }
61
+
62
+ case 1: if (*source >= 0x80 && *source < 0xC2) return 0;
63
+ }
64
+ if (*source > 0xF4) return 0;
65
+ return 1;
66
+ }
67
+
68
+ int is_valid_utf8 (size_t len, char *value)
69
+ {
70
+ /* is the string valid UTF-8? */
71
+ for (size_t i = 0; i < len; i++) {
72
+ uint32_t ch = 0;
73
+ uint8_t extrabytes = trailingBytesForUTF8[(uint8_t) value[i]];
74
+
75
+ if (extrabytes + i >= len)
76
+ return 0;
77
+
78
+ if (isLegalUTF8 ((uint8_t *) (value + i), extrabytes + 1) == 0) return 0;
79
+
80
+ switch (extrabytes) {
81
+ case 5 : ch += (uint8_t) value[i++]; ch <<= 6;
82
+ case 4 : ch += (uint8_t) value[i++]; ch <<= 6;
83
+ case 3 : ch += (uint8_t) value[i++]; ch <<= 6;
84
+ case 2 : ch += (uint8_t) value[i++]; ch <<= 6;
85
+ case 1 : ch += (uint8_t) value[i++]; ch <<= 6;
86
+ case 0 : ch += (uint8_t) value[i];
87
+ }
88
+
89
+ ch -= offsetsFromUTF8[extrabytes];
90
+
91
+ if (ch <= UNI_MAX_LEGAL_UTF32) {
92
+ if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END)
93
+ return 0;
94
+ } else {
95
+ return 0;
96
+ }
97
+ }
98
+
99
+ return 1;
100
+ }
101
+
102
+ class Validation : public ObjectWrap
103
+ {
104
+ public:
105
+
106
+ static void Initialize(v8::Handle<v8::Object> target)
107
+ {
108
+ HandleScope scope;
109
+ Local<FunctionTemplate> t = FunctionTemplate::New(New);
110
+ t->InstanceTemplate()->SetInternalFieldCount(1);
111
+ NODE_SET_METHOD(t->GetFunction(), "isValidUTF8", Validation::IsValidUTF8);
112
+ target->Set(String::NewSymbol("Validation"), t->GetFunction());
113
+ }
114
+
115
+ protected:
116
+
117
+ static Handle<Value> New(const Arguments& args)
118
+ {
119
+ HandleScope scope;
120
+ Validation* validation = new Validation();
121
+ validation->Wrap(args.This());
122
+ return args.This();
123
+ }
124
+
125
+ static Handle<Value> IsValidUTF8(const Arguments& args)
126
+ {
127
+ HandleScope scope;
128
+ if (!Buffer::HasInstance(args[0])) {
129
+ return ThrowException(Exception::Error(String::New("First argument needs to be a buffer")));
130
+ }
131
+ Local<Object> buffer_obj = args[0]->ToObject();
132
+ char *buffer_data = Buffer::Data(buffer_obj);
133
+ size_t buffer_length = Buffer::Length(buffer_obj);
134
+ return is_valid_utf8(buffer_length, buffer_data) == 1 ? scope.Close(True()) : scope.Close(False());
135
+ }
136
+ };
137
+
138
+ extern "C" void init (Handle<Object> target)
139
+ {
140
+ HandleScope scope;
141
+ Validation::Initialize(target);
142
+ }
143
+
144
+ NODE_MODULE(validation, init);
@@ -0,0 +1,86 @@
1
+ /*!
2
+ * Buffer xor module
3
+ * Copyright (c) Agora S.A.
4
+ * Licensed under the MIT License.
5
+ * Version: 1.0
6
+ */
7
+
8
+ #include <v8.h>
9
+ #include <node_buffer.h>
10
+ #include <cstring>
11
+
12
+ using namespace node;
13
+ using namespace v8;
14
+
15
+ namespace {
16
+ #define XOR_BUFFER_THROW_EXCEPTION(name, msg) { \
17
+ static Persistent<String> name = Persistent<String>::New(String::New(msg)); \
18
+ return ThrowException(Exception::TypeError(name)); }
19
+
20
+ static Handle<Value> xorBuffer(const Arguments &args) {
21
+ if (args.Length() < 2) {
22
+ XOR_BUFFER_THROW_EXCEPTION(illegalArgumentCountException, "Expected 2 arguments")
23
+ }
24
+
25
+ if (!Buffer::HasInstance(args[0])) {
26
+ XOR_BUFFER_THROW_EXCEPTION(illegalFirstArgumentException, "First argument must be a Buffer.")
27
+ }
28
+ Handle<Object> payload = args[0]->ToObject();
29
+
30
+ if (!Buffer::HasInstance(args[1])) {
31
+ XOR_BUFFER_THROW_EXCEPTION(illegalArgumentException, "Second argument must be a Buffer.")
32
+ }
33
+ Handle<Object> mask = args[1]->ToObject();
34
+ size_t maskSize = Buffer::Length(mask);
35
+
36
+ if (maskSize != 4) {
37
+ XOR_BUFFER_THROW_EXCEPTION(illegalStringArgumentException, "Second argument must be a 4 byte Buffer.")
38
+ }
39
+
40
+ size_t maskOffset = 0;
41
+ if (args.Length() == 3) {
42
+ if (!args[2]->IsUint32()) {
43
+ XOR_BUFFER_THROW_EXCEPTION(illegalThirdArgumentException, "Third argument must be an unsigned number.")
44
+ }
45
+ maskOffset = args[2]->ToUint32()->Uint32Value();
46
+ }
47
+
48
+ if (maskOffset > 3) {
49
+ XOR_BUFFER_THROW_EXCEPTION(illegalStringArgumentException, "Third argument must be less than 4.")
50
+ }
51
+
52
+ size_t payloadLength = Buffer::Length(payload);
53
+ uint8_t* payloadData = (uint8_t*) Buffer::Data(payload);
54
+ uint8_t* maskData = (uint8_t*) Buffer::Data(mask);
55
+
56
+ uint8_t rotatedMask[4];
57
+ memcpy(rotatedMask, maskData + maskOffset, 4 - maskOffset);
58
+ if (maskOffset > 0) {
59
+ memcpy(rotatedMask + 4 - maskOffset, maskData, maskOffset);
60
+ }
61
+
62
+ uint32_t* pos32 = (uint32_t*) payloadData;
63
+ uint32_t* end32 = pos32 + (payloadLength >> 2);
64
+ uint32_t* mask32 = (uint32_t*) rotatedMask;
65
+
66
+ while (pos32 < end32) {
67
+ *(pos32++) ^= *mask32;
68
+ }
69
+
70
+ uint8_t* pos8 = (uint8_t*)pos32;
71
+ uint8_t* end8 = payloadData + payloadLength;
72
+ uint8_t* mask8 = rotatedMask;
73
+
74
+ while (pos8 < end8) {
75
+ *(pos8++) ^= *(mask8++);
76
+ }
77
+
78
+ return Integer::NewFromUnsigned((mask8 - rotatedMask + maskOffset) & 3);
79
+ }
80
+
81
+ void RegisterModule(Handle<Object> target) {
82
+ NODE_SET_METHOD(target, "xor", xorBuffer);
83
+ }
84
+ }
85
+
86
+ NODE_MODULE(xor, RegisterModule);
@@ -0,0 +1,192 @@
1
+ // This file was copied from https://github.com/substack/node-bufferlist
2
+ // and modified to be able to copy bytes from the bufferlist directly into
3
+ // a pre-existing fixed-size buffer without an additional memory allocation.
4
+
5
+ // bufferlist.js
6
+ // Treat a linked list of buffers as a single variable-size buffer.
7
+ var Buffer = require('buffer').Buffer;
8
+ var EventEmitter = require('events').EventEmitter;
9
+
10
+ module.exports = BufferList;
11
+ module.exports.BufferList = BufferList; // backwards compatibility
12
+
13
+ function BufferList(opts) {
14
+ if (!(this instanceof BufferList)) return new BufferList(opts);
15
+ EventEmitter.call(this);
16
+ var self = this;
17
+
18
+ if (typeof(opts) == 'undefined') opts = {};
19
+
20
+ // default encoding to use for take(). Leaving as 'undefined'
21
+ // makes take() return a Buffer instead.
22
+ self.encoding = opts.encoding;
23
+
24
+ // constructor to use for Buffer-esque operations
25
+ self.construct = opts.construct || Buffer;
26
+
27
+ var head = { next : null, buffer : null };
28
+ var last = { next : null, buffer : null };
29
+
30
+ // length can get negative when advanced past the end
31
+ // and this is the desired behavior
32
+ var length = 0;
33
+ self.__defineGetter__('length', function () {
34
+ return length;
35
+ });
36
+
37
+ // keep an offset of the head to decide when to head = head.next
38
+ var offset = 0;
39
+
40
+ // Write to the bufferlist. Emits 'write'. Always returns true.
41
+ self.write = function (buf) {
42
+ if (!head.buffer) {
43
+ head.buffer = buf;
44
+ last = head;
45
+ }
46
+ else {
47
+ last.next = { next : null, buffer : buf };
48
+ last = last.next;
49
+ }
50
+ length += buf.length;
51
+ self.emit('write', buf);
52
+ return true;
53
+ };
54
+
55
+ self.end = function (buf) {
56
+ if (Buffer.isBuffer(buf)) self.write(buf);
57
+ };
58
+
59
+ // Push buffers to the end of the linked list. (deprecated)
60
+ // Return this (self).
61
+ self.push = function () {
62
+ var args = [].concat.apply([], arguments);
63
+ args.forEach(self.write);
64
+ return self;
65
+ };
66
+
67
+ // For each buffer, perform some action.
68
+ // If fn's result is a true value, cut out early.
69
+ // Returns this (self).
70
+ self.forEach = function (fn) {
71
+ if (!head.buffer) return new self.construct(0);
72
+
73
+ if (head.buffer.length - offset <= 0) return self;
74
+ var firstBuf = head.buffer.slice(offset);
75
+
76
+ var b = { buffer : firstBuf, next : head.next };
77
+
78
+ while (b && b.buffer) {
79
+ var r = fn(b.buffer);
80
+ if (r) break;
81
+ b = b.next;
82
+ }
83
+
84
+ return self;
85
+ };
86
+
87
+ // Create a single Buffer out of all the chunks or some subset specified by
88
+ // start and one-past the end (like slice) in bytes.
89
+ self.join = function (start, end) {
90
+ if (!head.buffer) return new self.construct(0);
91
+ if (start == undefined) start = 0;
92
+ if (end == undefined) end = self.length;
93
+
94
+ var big = new self.construct(end - start);
95
+ var ix = 0;
96
+ self.forEach(function (buffer) {
97
+ if (start < (ix + buffer.length) && ix < end) {
98
+ // at least partially contained in the range
99
+ buffer.copy(
100
+ big,
101
+ Math.max(0, ix - start),
102
+ Math.max(0, start - ix),
103
+ Math.min(buffer.length, end - ix)
104
+ );
105
+ }
106
+ ix += buffer.length;
107
+ if (ix > end) return true; // stop processing past end
108
+ });
109
+
110
+ return big;
111
+ };
112
+
113
+ self.joinInto = function (targetBuffer, targetStart, sourceStart, sourceEnd) {
114
+ if (!head.buffer) return new self.construct(0);
115
+ if (sourceStart == undefined) sourceStart = 0;
116
+ if (sourceEnd == undefined) sourceEnd = self.length;
117
+
118
+ var big = targetBuffer;
119
+ if (big.length - targetStart < sourceEnd - sourceStart) {
120
+ throw new Error("Insufficient space available in target Buffer.");
121
+ }
122
+ var ix = 0;
123
+ self.forEach(function (buffer) {
124
+ if (sourceStart < (ix + buffer.length) && ix < sourceEnd) {
125
+ // at least partially contained in the range
126
+ buffer.copy(
127
+ big,
128
+ Math.max(targetStart, targetStart + ix - sourceStart),
129
+ Math.max(0, sourceStart - ix),
130
+ Math.min(buffer.length, sourceEnd - ix)
131
+ );
132
+ }
133
+ ix += buffer.length;
134
+ if (ix > sourceEnd) return true; // stop processing past end
135
+ });
136
+
137
+ return big;
138
+ };
139
+
140
+ // Advance the buffer stream by n bytes.
141
+ // If n the aggregate advance offset passes the end of the buffer list,
142
+ // operations such as .take() will return empty strings until enough data is
143
+ // pushed.
144
+ // Returns this (self).
145
+ self.advance = function (n) {
146
+ offset += n;
147
+ length -= n;
148
+ while (head.buffer && offset >= head.buffer.length) {
149
+ offset -= head.buffer.length;
150
+ head = head.next
151
+ ? head.next
152
+ : { buffer : null, next : null }
153
+ ;
154
+ }
155
+ self.emit('advance', n);
156
+ return self;
157
+ };
158
+
159
+ // Take n bytes from the start of the buffers.
160
+ // Returns a string.
161
+ // If there are less than n bytes in all the buffers or n is undefined,
162
+ // returns the entire concatenated buffer string.
163
+ self.take = function (n, encoding) {
164
+ if (n == undefined) n = self.length;
165
+ else if (typeof n !== 'number') {
166
+ encoding = n;
167
+ n = self.length;
168
+ }
169
+ var b = head;
170
+ if (!encoding) encoding = self.encoding;
171
+ if (encoding) {
172
+ var acc = '';
173
+ self.forEach(function (buffer) {
174
+ if (n <= 0) return true;
175
+ acc += buffer.toString(
176
+ encoding, 0, Math.min(n,buffer.length)
177
+ );
178
+ n -= buffer.length;
179
+ });
180
+ return acc;
181
+ } else {
182
+ // If no 'encoding' is specified, then return a Buffer.
183
+ return self.join(0, n);
184
+ }
185
+ };
186
+
187
+ // The entire concatenated buffer as a string.
188
+ self.toString = function () {
189
+ return self.take('binary');
190
+ };
191
+ }
192
+ require('util').inherits(BufferList, EventEmitter);