Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

writable_streambuffer.js.html 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <title>Code coverage report for lib/writable_streambuffer.js</title>
  5. <meta charset="utf-8">
  6. <link rel="stylesheet" href="../prettify.css">
  7. <link rel="stylesheet" href="../base.css">
  8. <style type='text/css'>
  9. div.coverage-summary .sorter {
  10. background-image: url(../sort-arrow-sprite.png);
  11. }
  12. </style>
  13. </head>
  14. <body>
  15. <div class="header high">
  16. <h1>Code coverage report for <span class="entity">lib/writable_streambuffer.js</span></h1>
  17. <h2>
  18. Statements: <span class="metric">96.77% <small>(60 / 62)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
  19. Branches: <span class="metric">90.63% <small>(29 / 32)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
  20. Functions: <span class="metric">100% <small>(9 / 9)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
  21. Lines: <span class="metric">98.25% <small>(56 / 57)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
  22. Ignored: <span class="metric"><span class="ignore-none">none</span></span> &nbsp;&nbsp;&nbsp;&nbsp;
  23. </h2>
  24. <div class="path"><a href="../index.html">All files</a> &#187; <a href="index.html">lib/</a> &#187; writable_streambuffer.js</div>
  25. </div>
  26. <div class="body">
  27. <pre><table class="coverage">
  28. <tr><td class="line-count">1
  29. 2
  30. 3
  31. 4
  32. 5
  33. 6
  34. 7
  35. 8
  36. 9
  37. 10
  38. 11
  39. 12
  40. 13
  41. 14
  42. 15
  43. 16
  44. 17
  45. 18
  46. 19
  47. 20
  48. 21
  49. 22
  50. 23
  51. 24
  52. 25
  53. 26
  54. 27
  55. 28
  56. 29
  57. 30
  58. 31
  59. 32
  60. 33
  61. 34
  62. 35
  63. 36
  64. 37
  65. 38
  66. 39
  67. 40
  68. 41
  69. 42
  70. 43
  71. 44
  72. 45
  73. 46
  74. 47
  75. 48
  76. 49
  77. 50
  78. 51
  79. 52
  80. 53
  81. 54
  82. 55
  83. 56
  84. 57
  85. 58
  86. 59
  87. 60
  88. 61
  89. 62
  90. 63
  91. 64
  92. 65
  93. 66
  94. 67
  95. 68
  96. 69
  97. 70
  98. 71
  99. 72
  100. 73
  101. 74
  102. 75
  103. 76
  104. 77
  105. 78
  106. 79
  107. 80
  108. 81
  109. 82
  110. 83
  111. 84
  112. 85
  113. 86
  114. 87
  115. 88
  116. 89
  117. 90
  118. 91
  119. 92
  120. 93
  121. 94
  122. 95
  123. 96
  124. 97
  125. 98</td><td class="line-coverage"><span class="cline-any cline-yes">1</span>
  126. <span class="cline-any cline-neutral">&nbsp;</span>
  127. <span class="cline-any cline-neutral">&nbsp;</span>
  128. <span class="cline-any cline-neutral">&nbsp;</span>
  129. <span class="cline-any cline-neutral">&nbsp;</span>
  130. <span class="cline-any cline-neutral">&nbsp;</span>
  131. <span class="cline-any cline-yes">1</span>
  132. <span class="cline-any cline-yes">10</span>
  133. <span class="cline-any cline-neutral">&nbsp;</span>
  134. <span class="cline-any cline-yes">10</span>
  135. <span class="cline-any cline-neutral">&nbsp;</span>
  136. <span class="cline-any cline-yes">10</span>
  137. <span class="cline-any cline-yes">10</span>
  138. <span class="cline-any cline-yes">10</span>
  139. <span class="cline-any cline-neutral">&nbsp;</span>
  140. <span class="cline-any cline-yes">10</span>
  141. <span class="cline-any cline-yes">10</span>
  142. <span class="cline-any cline-neutral">&nbsp;</span>
  143. <span class="cline-any cline-yes">10</span>
  144. <span class="cline-any cline-yes">10</span>
  145. <span class="cline-any cline-neutral">&nbsp;</span>
  146. <span class="cline-any cline-yes">10</span>
  147. <span class="cline-any cline-yes">5</span>
  148. <span class="cline-any cline-neutral">&nbsp;</span>
  149. <span class="cline-any cline-neutral">&nbsp;</span>
  150. <span class="cline-any cline-yes">10</span>
  151. <span class="cline-any cline-yes">5</span>
  152. <span class="cline-any cline-neutral">&nbsp;</span>
  153. <span class="cline-any cline-neutral">&nbsp;</span>
  154. <span class="cline-any cline-yes">10</span>
  155. <span class="cline-any cline-yes">2</span>
  156. <span class="cline-any cline-neutral">&nbsp;</span>
  157. <span class="cline-any cline-yes">1</span>
  158. <span class="cline-any cline-yes">1</span>
  159. <span class="cline-any cline-neutral">&nbsp;</span>
  160. <span class="cline-any cline-yes">1</span>
  161. <span class="cline-any cline-no">&nbsp;</span>
  162. <span class="cline-any cline-neutral">&nbsp;</span>
  163. <span class="cline-any cline-yes">1</span>
  164. <span class="cline-any cline-neutral">&nbsp;</span>
  165. <span class="cline-any cline-yes">1</span>
  166. <span class="cline-any cline-neutral">&nbsp;</span>
  167. <span class="cline-any cline-neutral">&nbsp;</span>
  168. <span class="cline-any cline-yes">10</span>
  169. <span class="cline-any cline-yes">8</span>
  170. <span class="cline-any cline-neutral">&nbsp;</span>
  171. <span class="cline-any cline-yes">7</span>
  172. <span class="cline-any cline-yes">7</span>
  173. <span class="cline-any cline-neutral">&nbsp;</span>
  174. <span class="cline-any cline-yes">7</span>
  175. <span class="cline-any cline-yes">1</span>
  176. <span class="cline-any cline-neutral">&nbsp;</span>
  177. <span class="cline-any cline-yes">7</span>
  178. <span class="cline-any cline-yes">7</span>
  179. <span class="cline-any cline-neutral">&nbsp;</span>
  180. <span class="cline-any cline-neutral">&nbsp;</span>
  181. <span class="cline-any cline-yes">10</span>
  182. <span class="cline-any cline-yes">10</span>
  183. <span class="cline-any cline-yes">2</span>
  184. <span class="cline-any cline-neutral">&nbsp;</span>
  185. <span class="cline-any cline-yes">2</span>
  186. <span class="cline-any cline-yes">2</span>
  187. <span class="cline-any cline-yes">2</span>
  188. <span class="cline-any cline-neutral">&nbsp;</span>
  189. <span class="cline-any cline-neutral">&nbsp;</span>
  190. <span class="cline-any cline-neutral">&nbsp;</span>
  191. <span class="cline-any cline-yes">10</span>
  192. <span class="cline-any cline-yes">11</span>
  193. <span class="cline-any cline-neutral">&nbsp;</span>
  194. <span class="cline-any cline-yes">10</span>
  195. <span class="cline-any cline-yes">2</span>
  196. <span class="cline-any cline-yes">2</span>
  197. <span class="cline-any cline-yes">2</span>
  198. <span class="cline-any cline-neutral">&nbsp;</span>
  199. <span class="cline-any cline-neutral">&nbsp;</span>
  200. <span class="cline-any cline-yes">8</span>
  201. <span class="cline-any cline-yes">8</span>
  202. <span class="cline-any cline-yes">8</span>
  203. <span class="cline-any cline-yes">8</span>
  204. <span class="cline-any cline-neutral">&nbsp;</span>
  205. <span class="cline-any cline-neutral">&nbsp;</span>
  206. <span class="cline-any cline-yes">10</span>
  207. <span class="cline-any cline-neutral">&nbsp;</span>
  208. <span class="cline-any cline-neutral">&nbsp;</span>
  209. <span class="cline-any cline-yes">10</span>
  210. <span class="cline-any cline-yes">1</span>
  211. <span class="cline-any cline-yes">1</span>
  212. <span class="cline-any cline-yes">1</span>
  213. <span class="cline-any cline-yes">1</span>
  214. <span class="cline-any cline-neutral">&nbsp;</span>
  215. <span class="cline-any cline-neutral">&nbsp;</span>
  216. <span class="cline-any cline-yes">10</span>
  217. <span class="cline-any cline-yes">4</span>
  218. <span class="cline-any cline-yes">4</span>
  219. <span class="cline-any cline-neutral">&nbsp;</span>
  220. <span class="cline-any cline-neutral">&nbsp;</span>
  221. <span class="cline-any cline-yes">1</span>
  222. <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">var util = require("util"),
  223. stream = require("stream"),
  224. constants = require("./constants");
  225. &nbsp;
  226. // TODO: clear up specs on returning false from a write and emitting a drain event.
  227. // Does this mean if I return false from a write, I should ignore any write requests between that false return and the drain event?
  228. var WritableStreamBuffer = module.exports = function(opts) {
  229. var that = this;
  230. &nbsp;
  231. stream.Stream.call(this);
  232. &nbsp;
  233. opts = opts || {};
  234. var initialSize = opts.initialSize || constants.DEFAULT_INITIAL_SIZE;
  235. var incrementAmount = opts.incrementAmount || constants.DEFAULT_INCREMENT_AMOUNT;
  236. &nbsp;
  237. var buffer = new Buffer(initialSize);
  238. var size = 0;
  239. &nbsp;
  240. this.writable = true;
  241. this.readable = false;
  242. &nbsp;
  243. this.size = function() {
  244. return size;
  245. };
  246. &nbsp;
  247. this.maxSize = function() {
  248. return buffer.length;
  249. };
  250. &nbsp;
  251. this.getContents = function(length) {
  252. if(!size) return false;
  253. &nbsp;
  254. var data = new Buffer(Math.min(length || size, size));
  255. buffer.copy(data, 0, 0, data.length);
  256. &nbsp;
  257. <span class="missing-if-branch" title="if path not taken" >I</span>if(data.length &lt; size)
  258. <span class="cstat-no" title="statement not covered" > buffer.copy(buffer, 0, data.length);</span>
  259. &nbsp;
  260. size -= data.length;
  261. &nbsp;
  262. return data;
  263. };
  264. &nbsp;
  265. this.getContentsAsString = function(encoding, length) {
  266. if(!size) return false;
  267. &nbsp;
  268. var data = buffer.toString(encoding || "utf8", 0, Math.min(length || size, size));
  269. var dataLength = Buffer.byteLength(data);
  270. &nbsp;
  271. if(dataLength &lt; size)
  272. buffer.copy(buffer, 0, dataLength);
  273. &nbsp;
  274. size -= dataLength;
  275. return data;
  276. };
  277. &nbsp;
  278. var increaseBufferIfNecessary = function(incomingDataSize) {
  279. if((buffer.length - size) &lt; incomingDataSize) {
  280. var factor = Math.ceil((incomingDataSize - (buffer.length - size)) / incrementAmount);
  281. &nbsp;
  282. var newBuffer = new Buffer(buffer.length + (incrementAmount * factor));
  283. buffer.copy(newBuffer, 0, 0, size);
  284. buffer = newBuffer;
  285. }
  286. };
  287. &nbsp;
  288. this.write = function(data, encoding, callback) {
  289. if(!that.writable) return;
  290. &nbsp;
  291. if(Buffer.isBuffer(data)) {
  292. increaseBufferIfNecessary(data.length);
  293. data.copy(buffer, size, 0);
  294. size += data.length;
  295. }
  296. else {
  297. data = data + "";
  298. increaseBufferIfNecessary(Buffer.byteLength(data));
  299. buffer.write(data, size, encoding || "utf8");
  300. size += Buffer.byteLength(data);
  301. }
  302. <span class="missing-if-branch" title="if path not taken" >I</span>if(typeof callback === "function") { <span class="cstat-no" title="statement not covered" >callback() ;}</span>
  303. };
  304. &nbsp;
  305. this.end = function() {
  306. var args = Array.prototype.slice.apply(arguments);
  307. <span class="missing-if-branch" title="else path not taken" >E</span>if(args.length) that.write.apply(that, args);
  308. that.emit('finish');
  309. that.destroy();
  310. };
  311. &nbsp;
  312. this.destroySoon = this.destroy = function() {
  313. that.writable = false;
  314. that.emit("close");
  315. };
  316. };
  317. util.inherits(WritableStreamBuffer, stream.Stream);
  318. &nbsp;</pre></td></tr>
  319. </table></pre>
  320. </div>
  321. <div class="footer">
  322. <div class="meta">Generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Wed Jul 01 2015 04:16:19 GMT+0000 (UTC)</div>
  323. </div>
  324. <script src="../prettify.js"></script>
  325. <script>
  326. window.onload = function () {
  327. if (typeof prettyPrint === 'function') {
  328. prettyPrint();
  329. }
  330. };
  331. </script>
  332. <script src="../sorter.js"></script>
  333. </body>
  334. </html>