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

readable_streambuffer.js.html 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <title>Code coverage report for lib/readable_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/readable_streambuffer.js</span></h1>
  17. <h2>
  18. Statements: <span class="metric">98.82% <small>(84 / 85)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
  19. Branches: <span class="metric">94.34% <small>(50 / 53)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
  20. Functions: <span class="metric">100% <small>(11 / 11)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
  21. Lines: <span class="metric">100% <small>(83 / 83)</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; readable_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
  126. 99
  127. 100
  128. 101
  129. 102
  130. 103
  131. 104
  132. 105
  133. 106
  134. 107
  135. 108
  136. 109
  137. 110
  138. 111
  139. 112
  140. 113
  141. 114
  142. 115
  143. 116
  144. 117
  145. 118
  146. 119
  147. 120
  148. 121
  149. 122
  150. 123
  151. 124
  152. 125
  153. 126
  154. 127
  155. 128
  156. 129
  157. 130
  158. 131
  159. 132
  160. 133
  161. 134
  162. 135
  163. 136
  164. 137</td><td class="line-coverage"><span class="cline-any cline-yes">1</span>
  165. <span class="cline-any cline-neutral">&nbsp;</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">1</span>
  169. <span class="cline-any cline-yes">12</span>
  170. <span class="cline-any cline-neutral">&nbsp;</span>
  171. <span class="cline-any cline-yes">12</span>
  172. <span class="cline-any cline-neutral">&nbsp;</span>
  173. <span class="cline-any cline-yes">12</span>
  174. <span class="cline-any cline-yes">12</span>
  175. <span class="cline-any cline-yes">12</span>
  176. <span class="cline-any cline-yes">12</span>
  177. <span class="cline-any cline-yes">12</span>
  178. <span class="cline-any cline-neutral">&nbsp;</span>
  179. <span class="cline-any cline-yes">12</span>
  180. <span class="cline-any cline-yes">12</span>
  181. <span class="cline-any cline-yes">12</span>
  182. <span class="cline-any cline-neutral">&nbsp;</span>
  183. <span class="cline-any cline-yes">12</span>
  184. <span class="cline-any cline-yes">12</span>
  185. <span class="cline-any cline-neutral">&nbsp;</span>
  186. <span class="cline-any cline-yes">12</span>
  187. <span class="cline-any cline-yes">268</span>
  188. <span class="cline-any cline-neutral">&nbsp;</span>
  189. <span class="cline-any cline-yes">268</span>
  190. <span class="cline-any cline-yes">44</span>
  191. <span class="cline-any cline-yes">44</span>
  192. <span class="cline-any cline-yes">9</span>
  193. <span class="cline-any cline-neutral">&nbsp;</span>
  194. <span class="cline-any cline-neutral">&nbsp;</span>
  195. <span class="cline-any cline-yes">35</span>
  196. <span class="cline-any cline-yes">35</span>
  197. <span class="cline-any cline-neutral">&nbsp;</span>
  198. <span class="cline-any cline-neutral">&nbsp;</span>
  199. <span class="cline-any cline-yes">44</span>
  200. <span class="cline-any cline-neutral">&nbsp;</span>
  201. <span class="cline-any cline-yes">44</span>
  202. <span class="cline-any cline-yes">44</span>
  203. <span class="cline-any cline-yes">44</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">268</span>
  207. <span class="cline-any cline-yes">7</span>
  208. <span class="cline-any cline-yes">7</span>
  209. <span class="cline-any cline-yes">7</span>
  210. <span class="cline-any cline-yes">6</span>
  211. <span class="cline-any cline-yes">6</span>
  212. <span class="cline-any cline-neutral">&nbsp;</span>
  213. <span class="cline-any cline-neutral">&nbsp;</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">12</span>
  217. <span class="cline-any cline-yes">3</span>
  218. <span class="cline-any cline-neutral">&nbsp;</span>
  219. <span class="cline-any cline-neutral">&nbsp;</span>
  220. <span class="cline-any cline-yes">12</span>
  221. <span class="cline-any cline-yes">5</span>
  222. <span class="cline-any cline-neutral">&nbsp;</span>
  223. <span class="cline-any cline-neutral">&nbsp;</span>
  224. <span class="cline-any cline-yes">12</span>
  225. <span class="cline-any cline-yes">13</span>
  226. <span class="cline-any cline-yes">2</span>
  227. <span class="cline-any cline-neutral">&nbsp;</span>
  228. <span class="cline-any cline-yes">2</span>
  229. <span class="cline-any cline-yes">2</span>
  230. <span class="cline-any cline-yes">2</span>
  231. <span class="cline-any cline-neutral">&nbsp;</span>
  232. <span class="cline-any cline-neutral">&nbsp;</span>
  233. <span class="cline-any cline-neutral">&nbsp;</span>
  234. <span class="cline-any cline-yes">12</span>
  235. <span class="cline-any cline-yes">13</span>
  236. <span class="cline-any cline-neutral">&nbsp;</span>
  237. <span class="cline-any cline-yes">13</span>
  238. <span class="cline-any cline-yes">13</span>
  239. <span class="cline-any cline-yes">4</span>
  240. <span class="cline-any cline-yes">4</span>
  241. <span class="cline-any cline-yes">4</span>
  242. <span class="cline-any cline-neutral">&nbsp;</span>
  243. <span class="cline-any cline-neutral">&nbsp;</span>
  244. <span class="cline-any cline-yes">9</span>
  245. <span class="cline-any cline-yes">9</span>
  246. <span class="cline-any cline-yes">9</span>
  247. <span class="cline-any cline-yes">9</span>
  248. <span class="cline-any cline-yes">9</span>
  249. <span class="cline-any cline-neutral">&nbsp;</span>
  250. <span class="cline-any cline-neutral">&nbsp;</span>
  251. <span class="cline-any cline-yes">13</span>
  252. <span class="cline-any cline-yes">12</span>
  253. <span class="cline-any cline-neutral">&nbsp;</span>
  254. <span class="cline-any cline-neutral">&nbsp;</span>
  255. <span class="cline-any cline-yes">13</span>
  256. <span class="cline-any cline-yes">2</span>
  257. <span class="cline-any cline-yes">3</span>
  258. <span class="cline-any cline-neutral">&nbsp;</span>
  259. <span class="cline-any cline-neutral">&nbsp;</span>
  260. <span class="cline-any cline-neutral">&nbsp;</span>
  261. <span class="cline-any cline-neutral">&nbsp;</span>
  262. <span class="cline-any cline-yes">12</span>
  263. <span class="cline-any cline-yes">4</span>
  264. <span class="cline-any cline-yes">4</span>
  265. <span class="cline-any cline-yes">4</span>
  266. <span class="cline-any cline-yes">4</span>
  267. <span class="cline-any cline-neutral">&nbsp;</span>
  268. <span class="cline-any cline-neutral">&nbsp;</span>
  269. <span class="cline-any cline-neutral">&nbsp;</span>
  270. <span class="cline-any cline-yes">12</span>
  271. <span class="cline-any cline-yes">15</span>
  272. <span class="cline-any cline-yes">15</span>
  273. <span class="cline-any cline-yes">14</span>
  274. <span class="cline-any cline-neutral">&nbsp;</span>
  275. <span class="cline-any cline-neutral">&nbsp;</span>
  276. <span class="cline-any cline-neutral">&nbsp;</span>
  277. <span class="cline-any cline-yes">12</span>
  278. <span class="cline-any cline-yes">6</span>
  279. <span class="cline-any cline-yes">6</span>
  280. <span class="cline-any cline-yes">6</span>
  281. <span class="cline-any cline-yes">6</span>
  282. <span class="cline-any cline-yes">6</span>
  283. <span class="cline-any cline-neutral">&nbsp;</span>
  284. <span class="cline-any cline-neutral">&nbsp;</span>
  285. <span class="cline-any cline-yes">12</span>
  286. <span class="cline-any cline-yes">7</span>
  287. <span class="cline-any cline-yes">7</span>
  288. <span class="cline-any cline-yes">1</span>
  289. <span class="cline-any cline-yes">1</span>
  290. <span class="cline-any cline-neutral">&nbsp;</span>
  291. <span class="cline-any cline-neutral">&nbsp;</span>
  292. <span class="cline-any cline-neutral">&nbsp;</span>
  293. <span class="cline-any cline-yes">12</span>
  294. <span class="cline-any cline-yes">5</span>
  295. <span class="cline-any cline-neutral">&nbsp;</span>
  296. <span class="cline-any cline-neutral">&nbsp;</span>
  297. <span class="cline-any cline-yes">12</span>
  298. <span class="cline-any cline-neutral">&nbsp;</span>
  299. <span class="cline-any cline-yes">1</span>
  300. <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">var stream = require("stream"),
  301. constants = require("./constants"),
  302. util = require("util");
  303. &nbsp;
  304. var ReadableStreamBuffer = module.exports = function(opts) {
  305. var that = this;
  306. &nbsp;
  307. stream.Stream.call(this);
  308. &nbsp;
  309. opts = opts || {};
  310. var frequency = opts.hasOwnProperty("frequency") ? opts.frequency : constants.DEFAULT_FREQUENCY;
  311. var chunkSize = opts.chunkSize || constants.DEFAULT_CHUNK_SIZE;
  312. var initialSize = opts.initialSize || constants.DEFAULT_INITIAL_SIZE;
  313. var incrementAmount = opts.incrementAmount || constants.DEFAULT_INCREMENT_AMOUNT;
  314. &nbsp;
  315. var size = 0;
  316. var buffer = new Buffer(initialSize);
  317. var encoding = null;
  318. &nbsp;
  319. this.readable = true;
  320. this.writable = false;
  321. &nbsp;
  322. var sendData = function() {
  323. var amount = Math.min(chunkSize, size);
  324. &nbsp;
  325. if (amount &gt; 0) {
  326. var chunk = null;
  327. if(encoding) {
  328. chunk = buffer.toString(encoding, 0, amount);
  329. }
  330. else {
  331. chunk = new Buffer(amount);
  332. buffer.copy(chunk, 0, 0, amount);
  333. }
  334. &nbsp;
  335. that.emit("data", chunk);
  336. &nbsp;
  337. <span class="missing-if-branch" title="else path not taken" >E</span>if(amount &lt; buffer.length)
  338. buffer.copy(buffer, 0, amount, size);
  339. size -= amount;
  340. }
  341. &nbsp;
  342. if(size === 0 &amp;&amp; !that.readable) {
  343. that.emit("end");
  344. that.emit("close");
  345. if (sendData &amp;&amp; sendData.interval) {
  346. clearInterval(sendData.interval);
  347. sendData.interval = null;
  348. }
  349. }
  350. };
  351. &nbsp;
  352. this.size = function() {
  353. return size;
  354. };
  355. &nbsp;
  356. this.maxSize = function() {
  357. return buffer.length;
  358. };
  359. &nbsp;
  360. var increaseBufferIfNecessary = function(incomingDataSize) {
  361. if((buffer.length - size) &lt; incomingDataSize) {
  362. var factor = Math.ceil((incomingDataSize - (buffer.length - size)) / incrementAmount);
  363. &nbsp;
  364. var newBuffer = new Buffer(buffer.length + (incrementAmount * factor));
  365. buffer.copy(newBuffer, 0, 0, size);
  366. buffer = newBuffer;
  367. }
  368. };
  369. &nbsp;
  370. this.put = function(data, encoding) {
  371. <span class="missing-if-branch" title="if path not taken" >I</span>if(!that.readable) <span class="cstat-no" title="statement not covered" >return;</span>
  372. &nbsp;
  373. var wasEmpty = size === 0;
  374. if(Buffer.isBuffer(data)) {
  375. increaseBufferIfNecessary(data.length);
  376. data.copy(buffer, size, 0);
  377. size += data.length;
  378. }
  379. else {
  380. data = data + "";
  381. var dataSizeInBytes = Buffer.byteLength(data);
  382. increaseBufferIfNecessary(dataSizeInBytes);
  383. buffer.write(data, size, encoding || "utf8");
  384. size += dataSizeInBytes;
  385. }
  386. &nbsp;
  387. if (wasEmpty &amp;&amp; size &gt; 0) {
  388. this.emit('readable')
  389. }
  390. &nbsp;
  391. if (!this.isPaused &amp;&amp; !frequency) {
  392. while (size &gt; 0) {
  393. sendData();
  394. }
  395. }
  396. };
  397. &nbsp;
  398. this.pause = function() {
  399. this.isPaused = true;
  400. <span class="missing-if-branch" title="else path not taken" >E</span>if(sendData &amp;&amp; sendData.interval) {
  401. clearInterval(sendData.interval);
  402. delete sendData.interval;
  403. }
  404. };
  405. &nbsp;
  406. this.resume = function() {
  407. this.isPaused = false;
  408. if(sendData &amp;&amp; !sendData.interval &amp;&amp; frequency &gt; 0) {
  409. sendData.interval = setInterval(sendData, frequency);
  410. }
  411. };
  412. &nbsp;
  413. this.destroy = function() {
  414. that.emit("end");
  415. if(sendData.interval) clearInterval(sendData.interval);
  416. sendData = null;
  417. that.readable = false;
  418. that.emit("close");
  419. };
  420. &nbsp;
  421. this.destroySoon = function() {
  422. that.readable = false;
  423. if (!sendData.interval) {
  424. that.emit("end");
  425. that.emit("close");
  426. }
  427. };
  428. &nbsp;
  429. this.setEncoding = function(_encoding) {
  430. encoding = _encoding;
  431. };
  432. &nbsp;
  433. this.resume();
  434. };
  435. util.inherits(ReadableStreamBuffer, stream.Stream);
  436. &nbsp;</pre></td></tr>
  437. </table></pre>
  438. </div>
  439. <div class="footer">
  440. <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>
  441. </div>
  442. <script src="../prettify.js"></script>
  443. <script>
  444. window.onload = function () {
  445. if (typeof prettyPrint === 'function') {
  446. prettyPrint();
  447. }
  448. };
  449. </script>
  450. <script src="../sorter.js"></script>
  451. </body>
  452. </html>