fixed untracked files
parent
d2ef558a06
commit
555f79e097
@ -1 +0,0 @@
|
|||||||
../lzma-native/bin/lzmajs
|
|
@ -1 +0,0 @@
|
|||||||
../seek-bzip/bin/seek-bunzip
|
|
@ -1 +0,0 @@
|
|||||||
../seek-bzip/bin/seek-bzip-table
|
|
@ -1,7 +0,0 @@
|
|||||||
language: node_js
|
|
||||||
node_js:
|
|
||||||
- "6"
|
|
||||||
- "node"
|
|
||||||
script: npm run travis
|
|
||||||
cache:
|
|
||||||
yarn: true
|
|
@ -1,8 +0,0 @@
|
|||||||
The MIT License (MIT)
|
|
||||||
Copyright (c) 2017 Samuel Reed <samuel.trace.reed@gmail.com>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -1 +0,0 @@
|
|||||||
{"/Users/samuelreed/git/forks/async-throttle/index.js":{"path":"/Users/samuelreed/git/forks/async-throttle/index.js","s":{"1":1,"2":7,"3":1,"4":6,"5":6,"6":6,"7":6,"8":6,"9":6,"10":1,"11":1,"12":3,"13":13,"14":13,"15":13,"16":1,"17":19,"18":1,"19":45,"20":6,"21":39,"22":13,"23":13,"24":13,"25":13,"26":39,"27":18,"28":6,"29":6,"30":1,"31":6,"32":6,"33":6,"34":1,"35":13,"36":13,"37":1},"b":{"1":[1,6],"2":[6,5],"3":[6,5],"4":[6,39],"5":[13,26],"6":[18,21],"7":[6,0]},"f":{"1":7,"2":3,"3":13,"4":19,"5":45,"6":6,"7":13},"fnMap":{"1":{"name":"Queue","line":3,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":24}}},"2":{"name":"(anonymous_2)","line":22,"loc":{"start":{"line":22,"column":24},"end":{"line":22,"column":41}}},"3":{"name":"(anonymous_3)","line":23,"loc":{"start":{"line":23,"column":28},"end":{"line":23,"column":39}}},"4":{"name":"(anonymous_4)","line":31,"loc":{"start":{"line":31,"column":7},"end":{"line":31,"column":18}}},"5":{"name":"(anonymous_5)","line":36,"loc":{"start":{"line":36,"column":23},"end":{"line":36,"column":34}}},"6":{"name":"(anonymous_6)","line":55,"loc":{"start":{"line":55,"column":25},"end":{"line":55,"column":38}}},"7":{"name":"done","line":62,"loc":{"start":{"line":62,"column":0},"end":{"line":62,"column":16}}}},"statementMap":{"1":{"start":{"line":3,"column":0},"end":{"line":14,"column":1}},"2":{"start":{"line":4,"column":2},"end":{"line":6,"column":3}},"3":{"start":{"line":5,"column":4},"end":{"line":5,"column":30}},"4":{"start":{"line":8,"column":2},"end":{"line":8,"column":26}},"5":{"start":{"line":9,"column":2},"end":{"line":9,"column":53}},"6":{"start":{"line":10,"column":2},"end":{"line":10,"column":19}},"7":{"start":{"line":11,"column":2},"end":{"line":11,"column":17}},"8":{"start":{"line":12,"column":2},"end":{"line":12,"column":16}},"9":{"start":{"line":13,"column":2},"end":{"line":13,"column":31}},"10":{"start":{"line":16,"column":0},"end":{"line":20,"column":2}},"11":{"start":{"line":22,"column":0},"end":{"line":28,"column":3}},"12":{"start":{"line":23,"column":2},"end":{"line":27,"column":4}},"13":{"start":{"line":24,"column":4},"end":{"line":24,"column":75}},"14":{"start":{"line":25,"column":4},"end":{"line":25,"column":16}},"15":{"start":{"line":26,"column":4},"end":{"line":26,"column":24}},"16":{"start":{"line":30,"column":0},"end":{"line":34,"column":3}},"17":{"start":{"line":32,"column":4},"end":{"line":32,"column":43}},"18":{"start":{"line":36,"column":0},"end":{"line":53,"column":2}},"19":{"start":{"line":37,"column":2},"end":{"line":39,"column":3}},"20":{"start":{"line":38,"column":4},"end":{"line":38,"column":11}},"21":{"start":{"line":40,"column":2},"end":{"line":45,"column":3}},"22":{"start":{"line":41,"column":4},"end":{"line":41,"column":32}},"23":{"start":{"line":42,"column":4},"end":{"line":42,"column":19}},"24":{"start":{"line":43,"column":4},"end":{"line":43,"column":20}},"25":{"start":{"line":44,"column":4},"end":{"line":44,"column":16}},"26":{"start":{"line":47,"column":2},"end":{"line":52,"column":3}},"27":{"start":{"line":48,"column":4},"end":{"line":51,"column":5}},"28":{"start":{"line":49,"column":6},"end":{"line":49,"column":30}},"29":{"start":{"line":50,"column":6},"end":{"line":50,"column":27}},"30":{"start":{"line":55,"column":0},"end":{"line":60,"column":2}},"31":{"start":{"line":56,"column":2},"end":{"line":59,"column":3}},"32":{"start":{"line":57,"column":4},"end":{"line":57,"column":22}},"33":{"start":{"line":58,"column":4},"end":{"line":58,"column":16}},"34":{"start":{"line":62,"column":0},"end":{"line":65,"column":1}},"35":{"start":{"line":63,"column":2},"end":{"line":63,"column":17}},"36":{"start":{"line":64,"column":2},"end":{"line":64,"column":14}},"37":{"start":{"line":67,"column":0},"end":{"line":67,"column":23}}},"branchMap":{"1":{"line":4,"type":"if","locations":[{"start":{"line":4,"column":2},"end":{"line":4,"column":2}},{"start":{"line":4,"column":2},"end":{"line":4,"column":2}}]},"2":{"line":8,"type":"binary-expr","locations":[{"start":{"line":8,"column":12},"end":{"line":8,"column":19}},{"start":{"line":8,"column":23},"end":{"line":8,"column":25}}]},"3":{"line":9,"type":"binary-expr","locations":[{"start":{"line":9,"column":21},"end":{"line":9,"column":40}},{"start":{"line":9,"column":44},"end":{"line":9,"column":52}}]},"4":{"line":37,"type":"if","locations":[{"start":{"line":37,"column":2},"end":{"line":37,"column":2}},{"start":{"line":37,"column":2},"end":{"line":37,"column":2}}]},"5":{"line":40,"type":"if","locations":[{"start":{"line":40,"column":2},"end":{"line":40,"column":2}},{"start":{"line":40,"column":2},"end":{"line":40,"column":2}}]},"6":{"line":47,"type":"if","locations":[{"start":{"line":47,"column":2},"end":{"line":47,"column":2}},{"start":{"line":47,"column":2},"end":{"line":47,"column":2}}]},"7":{"line":56,"type":"if","locations":[{"start":{"line":56,"column":2},"end":{"line":56,"column":2}},{"start":{"line":56,"column":2},"end":{"line":56,"column":2}}]}}}}
|
|
@ -1,73 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<title>Code coverage report for async-throttle/</title>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<link rel="stylesheet" href="../prettify.css">
|
|
||||||
<link rel="stylesheet" href="../base.css">
|
|
||||||
<style type='text/css'>
|
|
||||||
div.coverage-summary .sorter {
|
|
||||||
background-image: url(../sort-arrow-sprite.png);
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="header high">
|
|
||||||
<h1>Code coverage report for <span class="entity">async-throttle/</span></h1>
|
|
||||||
<h2>
|
|
||||||
Statements: <span class="metric">100% <small>(37 / 37)</small></span>
|
|
||||||
Branches: <span class="metric">92.86% <small>(13 / 14)</small></span>
|
|
||||||
Functions: <span class="metric">100% <small>(7 / 7)</small></span>
|
|
||||||
Lines: <span class="metric">100% <small>(37 / 37)</small></span>
|
|
||||||
Ignored: <span class="metric"><span class="ignore-none">none</span></span>
|
|
||||||
</h2>
|
|
||||||
<div class="path"><a href="../index.html">All files</a> » async-throttle/</div>
|
|
||||||
</div>
|
|
||||||
<div class="body">
|
|
||||||
<div class="coverage-summary">
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th data-col="file" data-fmt="html" data-html="true" class="file">File</th>
|
|
||||||
<th data-col="pic" data-type="number" data-fmt="html" data-html="true" class="pic"></th>
|
|
||||||
<th data-col="statements" data-type="number" data-fmt="pct" class="pct">Statements</th>
|
|
||||||
<th data-col="statements_raw" data-type="number" data-fmt="html" class="abs"></th>
|
|
||||||
<th data-col="branches" data-type="number" data-fmt="pct" class="pct">Branches</th>
|
|
||||||
<th data-col="branches_raw" data-type="number" data-fmt="html" class="abs"></th>
|
|
||||||
<th data-col="functions" data-type="number" data-fmt="pct" class="pct">Functions</th>
|
|
||||||
<th data-col="functions_raw" data-type="number" data-fmt="html" class="abs"></th>
|
|
||||||
<th data-col="lines" data-type="number" data-fmt="pct" class="pct">Lines</th>
|
|
||||||
<th data-col="lines_raw" data-type="number" data-fmt="html" class="abs"></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody><tr>
|
|
||||||
<td class="file high" data-value="index.js"><a href="index.js.html">index.js</a></td>
|
|
||||||
<td data-value="100" class="pic high"><span class="cover-fill cover-full" style="width: 100px;"></span><span class="cover-empty" style="width:0px;"></span></td>
|
|
||||||
<td data-value="100" class="pct high">100%</td>
|
|
||||||
<td data-value="37" class="abs high">(37 / 37)</td>
|
|
||||||
<td data-value="92.86" class="pct high">92.86%</td>
|
|
||||||
<td data-value="14" class="abs high">(13 / 14)</td>
|
|
||||||
<td data-value="100" class="pct high">100%</td>
|
|
||||||
<td data-value="7" class="abs high">(7 / 7)</td>
|
|
||||||
<td data-value="100" class="pct high">100%</td>
|
|
||||||
<td data-value="37" class="abs high">(37 / 37)</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="footer">
|
|
||||||
<div class="meta">Generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Mon Sep 11 2017 11:14:14 GMT-0500 (CDT)</div>
|
|
||||||
</div>
|
|
||||||
<script src="../prettify.js"></script>
|
|
||||||
<script>
|
|
||||||
window.onload = function () {
|
|
||||||
if (typeof prettyPrint === 'function') {
|
|
||||||
prettyPrint();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
<script src="../sorter.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,246 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<title>Code coverage report for async-throttle/index.js</title>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<link rel="stylesheet" href="../prettify.css">
|
|
||||||
<link rel="stylesheet" href="../base.css">
|
|
||||||
<style type='text/css'>
|
|
||||||
div.coverage-summary .sorter {
|
|
||||||
background-image: url(../sort-arrow-sprite.png);
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="header high">
|
|
||||||
<h1>Code coverage report for <span class="entity">async-throttle/index.js</span></h1>
|
|
||||||
<h2>
|
|
||||||
Statements: <span class="metric">100% <small>(37 / 37)</small></span>
|
|
||||||
Branches: <span class="metric">92.86% <small>(13 / 14)</small></span>
|
|
||||||
Functions: <span class="metric">100% <small>(7 / 7)</small></span>
|
|
||||||
Lines: <span class="metric">100% <small>(37 / 37)</small></span>
|
|
||||||
Ignored: <span class="metric"><span class="ignore-none">none</span></span>
|
|
||||||
</h2>
|
|
||||||
<div class="path"><a href="../index.html">All files</a> » <a href="index.html">async-throttle/</a> » index.js</div>
|
|
||||||
</div>
|
|
||||||
<div class="body">
|
|
||||||
<pre><table class="coverage">
|
|
||||||
<tr><td class="line-count">1
|
|
||||||
2
|
|
||||||
3
|
|
||||||
4
|
|
||||||
5
|
|
||||||
6
|
|
||||||
7
|
|
||||||
8
|
|
||||||
9
|
|
||||||
10
|
|
||||||
11
|
|
||||||
12
|
|
||||||
13
|
|
||||||
14
|
|
||||||
15
|
|
||||||
16
|
|
||||||
17
|
|
||||||
18
|
|
||||||
19
|
|
||||||
20
|
|
||||||
21
|
|
||||||
22
|
|
||||||
23
|
|
||||||
24
|
|
||||||
25
|
|
||||||
26
|
|
||||||
27
|
|
||||||
28
|
|
||||||
29
|
|
||||||
30
|
|
||||||
31
|
|
||||||
32
|
|
||||||
33
|
|
||||||
34
|
|
||||||
35
|
|
||||||
36
|
|
||||||
37
|
|
||||||
38
|
|
||||||
39
|
|
||||||
40
|
|
||||||
41
|
|
||||||
42
|
|
||||||
43
|
|
||||||
44
|
|
||||||
45
|
|
||||||
46
|
|
||||||
47
|
|
||||||
48
|
|
||||||
49
|
|
||||||
50
|
|
||||||
51
|
|
||||||
52
|
|
||||||
53
|
|
||||||
54
|
|
||||||
55
|
|
||||||
56
|
|
||||||
57
|
|
||||||
58
|
|
||||||
59
|
|
||||||
60
|
|
||||||
61
|
|
||||||
62
|
|
||||||
63
|
|
||||||
64
|
|
||||||
65
|
|
||||||
66
|
|
||||||
67
|
|
||||||
68</td><td class="line-coverage"><span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-yes">1</span>
|
|
||||||
<span class="cline-any cline-yes">7</span>
|
|
||||||
<span class="cline-any cline-yes">1</span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-yes">6</span>
|
|
||||||
<span class="cline-any cline-yes">6</span>
|
|
||||||
<span class="cline-any cline-yes">6</span>
|
|
||||||
<span class="cline-any cline-yes">6</span>
|
|
||||||
<span class="cline-any cline-yes">6</span>
|
|
||||||
<span class="cline-any cline-yes">6</span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-yes">1</span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-yes">1</span>
|
|
||||||
<span class="cline-any cline-yes">3</span>
|
|
||||||
<span class="cline-any cline-yes">13</span>
|
|
||||||
<span class="cline-any cline-yes">13</span>
|
|
||||||
<span class="cline-any cline-yes">13</span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-yes">1</span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-yes">19</span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-yes">1</span>
|
|
||||||
<span class="cline-any cline-yes">45</span>
|
|
||||||
<span class="cline-any cline-yes">6</span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-yes">39</span>
|
|
||||||
<span class="cline-any cline-yes">13</span>
|
|
||||||
<span class="cline-any cline-yes">13</span>
|
|
||||||
<span class="cline-any cline-yes">13</span>
|
|
||||||
<span class="cline-any cline-yes">13</span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-yes">39</span>
|
|
||||||
<span class="cline-any cline-yes">18</span>
|
|
||||||
<span class="cline-any cline-yes">6</span>
|
|
||||||
<span class="cline-any cline-yes">6</span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-yes">1</span>
|
|
||||||
<span class="cline-any cline-yes">6</span>
|
|
||||||
<span class="cline-any cline-yes">6</span>
|
|
||||||
<span class="cline-any cline-yes">6</span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-yes">1</span>
|
|
||||||
<span class="cline-any cline-yes">13</span>
|
|
||||||
<span class="cline-any cline-yes">13</span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-neutral"> </span>
|
|
||||||
<span class="cline-any cline-yes">1</span>
|
|
||||||
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">'use strict';
|
|
||||||
|
|
||||||
function Queue(options) {
|
|
||||||
if (!(this instanceof Queue)) {
|
|
||||||
return new Queue(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
options = options || {};
|
|
||||||
this.concurrency = options.concurrency || Infinity;
|
|
||||||
this.pending = 0;
|
|
||||||
this.jobs = [];
|
|
||||||
this.cbs = [];
|
|
||||||
this._done = done.bind(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
var arrayAddMethods = [
|
|
||||||
'push',
|
|
||||||
'unshift',
|
|
||||||
'splice'
|
|
||||||
];
|
|
||||||
|
|
||||||
arrayAddMethods.forEach(function(method) {
|
|
||||||
Queue.prototype[method] = function() {
|
|
||||||
var methodResult = Array.prototype[method].apply(this.jobs, arguments);
|
|
||||||
this._run();
|
|
||||||
return methodResult;
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
Object.defineProperty(Queue.prototype, 'length', {
|
|
||||||
get: function() {
|
|
||||||
return this.pending + this.jobs.length;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Queue.prototype._run = function() {
|
|
||||||
if (this.pending === this.concurrency) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (this.jobs.length) {
|
|
||||||
var job = this.jobs.shift();
|
|
||||||
this.pending++;
|
|
||||||
job(this._done);
|
|
||||||
this._run();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.pending === 0) {
|
|
||||||
while (this.cbs.length !== 0) {
|
|
||||||
var cb = this.cbs.pop();
|
|
||||||
process.nextTick(cb);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Queue.prototype.onDone = function(cb) {
|
|
||||||
<span class="missing-if-branch" title="else path not taken" >E</span>if (typeof cb === 'function') {
|
|
||||||
this.cbs.push(cb);
|
|
||||||
this._run();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function done() {
|
|
||||||
this.pending--;
|
|
||||||
this._run();
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Queue;
|
|
||||||
</pre></td></tr>
|
|
||||||
</table></pre>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<div class="footer">
|
|
||||||
<div class="meta">Generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Mon Sep 11 2017 11:14:14 GMT-0500 (CDT)</div>
|
|
||||||
</div>
|
|
||||||
<script src="../prettify.js"></script>
|
|
||||||
<script>
|
|
||||||
window.onload = function () {
|
|
||||||
if (typeof prettyPrint === 'function') {
|
|
||||||
prettyPrint();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
<script src="../sorter.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,182 +0,0 @@
|
|||||||
body, html {
|
|
||||||
margin:0; padding: 0;
|
|
||||||
}
|
|
||||||
body {
|
|
||||||
font-family: Helvetica Neue, Helvetica,Arial;
|
|
||||||
font-size: 10pt;
|
|
||||||
}
|
|
||||||
div.header, div.footer {
|
|
||||||
background: #eee;
|
|
||||||
padding: 1em;
|
|
||||||
}
|
|
||||||
div.header {
|
|
||||||
z-index: 100;
|
|
||||||
position: fixed;
|
|
||||||
top: 0;
|
|
||||||
border-bottom: 1px solid #666;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
div.footer {
|
|
||||||
border-top: 1px solid #666;
|
|
||||||
}
|
|
||||||
div.body {
|
|
||||||
margin-top: 10em;
|
|
||||||
}
|
|
||||||
div.meta {
|
|
||||||
font-size: 90%;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
h1, h2, h3 {
|
|
||||||
font-weight: normal;
|
|
||||||
}
|
|
||||||
h1 {
|
|
||||||
font-size: 12pt;
|
|
||||||
}
|
|
||||||
h2 {
|
|
||||||
font-size: 10pt;
|
|
||||||
}
|
|
||||||
pre {
|
|
||||||
font-family: Consolas, Menlo, Monaco, monospace;
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
line-height: 1.3;
|
|
||||||
font-size: 14px;
|
|
||||||
-moz-tab-size: 2;
|
|
||||||
-o-tab-size: 2;
|
|
||||||
tab-size: 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
div.path { font-size: 110%; }
|
|
||||||
div.path a:link, div.path a:visited { color: #000; }
|
|
||||||
table.coverage { border-collapse: collapse; margin:0; padding: 0 }
|
|
||||||
|
|
||||||
table.coverage td {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
color: #111;
|
|
||||||
vertical-align: top;
|
|
||||||
}
|
|
||||||
table.coverage td.line-count {
|
|
||||||
width: 50px;
|
|
||||||
text-align: right;
|
|
||||||
padding-right: 5px;
|
|
||||||
}
|
|
||||||
table.coverage td.line-coverage {
|
|
||||||
color: #777 !important;
|
|
||||||
text-align: right;
|
|
||||||
border-left: 1px solid #666;
|
|
||||||
border-right: 1px solid #666;
|
|
||||||
}
|
|
||||||
|
|
||||||
table.coverage td.text {
|
|
||||||
}
|
|
||||||
|
|
||||||
table.coverage td span.cline-any {
|
|
||||||
display: inline-block;
|
|
||||||
padding: 0 5px;
|
|
||||||
width: 40px;
|
|
||||||
}
|
|
||||||
table.coverage td span.cline-neutral {
|
|
||||||
background: #eee;
|
|
||||||
}
|
|
||||||
table.coverage td span.cline-yes {
|
|
||||||
background: #b5d592;
|
|
||||||
color: #999;
|
|
||||||
}
|
|
||||||
table.coverage td span.cline-no {
|
|
||||||
background: #fc8c84;
|
|
||||||
}
|
|
||||||
|
|
||||||
.cstat-yes { color: #111; }
|
|
||||||
.cstat-no { background: #fc8c84; color: #111; }
|
|
||||||
.fstat-no { background: #ffc520; color: #111 !important; }
|
|
||||||
.cbranch-no { background: yellow !important; color: #111; }
|
|
||||||
|
|
||||||
.cstat-skip { background: #ddd; color: #111; }
|
|
||||||
.fstat-skip { background: #ddd; color: #111 !important; }
|
|
||||||
.cbranch-skip { background: #ddd !important; color: #111; }
|
|
||||||
|
|
||||||
.missing-if-branch {
|
|
||||||
display: inline-block;
|
|
||||||
margin-right: 10px;
|
|
||||||
position: relative;
|
|
||||||
padding: 0 4px;
|
|
||||||
background: black;
|
|
||||||
color: yellow;
|
|
||||||
}
|
|
||||||
|
|
||||||
.skip-if-branch {
|
|
||||||
display: none;
|
|
||||||
margin-right: 10px;
|
|
||||||
position: relative;
|
|
||||||
padding: 0 4px;
|
|
||||||
background: #ccc;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.missing-if-branch .typ, .skip-if-branch .typ {
|
|
||||||
color: inherit !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.entity, .metric { font-weight: bold; }
|
|
||||||
.metric { display: inline-block; border: 1px solid #333; padding: 0.3em; background: white; }
|
|
||||||
.metric small { font-size: 80%; font-weight: normal; color: #666; }
|
|
||||||
|
|
||||||
div.coverage-summary table { border-collapse: collapse; margin: 3em; font-size: 110%; }
|
|
||||||
div.coverage-summary td, div.coverage-summary table th { margin: 0; padding: 0.25em 1em; border-top: 1px solid #666; border-bottom: 1px solid #666; }
|
|
||||||
div.coverage-summary th { text-align: left; border: 1px solid #666; background: #eee; font-weight: normal; }
|
|
||||||
div.coverage-summary th.file { border-right: none !important; }
|
|
||||||
div.coverage-summary th.pic { border-left: none !important; text-align: right; }
|
|
||||||
div.coverage-summary th.pct { border-right: none !important; }
|
|
||||||
div.coverage-summary th.abs { border-left: none !important; text-align: right; }
|
|
||||||
div.coverage-summary td.pct { text-align: right; border-left: 1px solid #666; }
|
|
||||||
div.coverage-summary td.abs { text-align: right; font-size: 90%; color: #444; border-right: 1px solid #666; }
|
|
||||||
div.coverage-summary td.file { border-left: 1px solid #666; white-space: nowrap; }
|
|
||||||
div.coverage-summary td.pic { min-width: 120px !important; }
|
|
||||||
div.coverage-summary a:link { text-decoration: none; color: #000; }
|
|
||||||
div.coverage-summary a:visited { text-decoration: none; color: #777; }
|
|
||||||
div.coverage-summary a:hover { text-decoration: underline; }
|
|
||||||
div.coverage-summary tfoot td { border-top: 1px solid #666; }
|
|
||||||
|
|
||||||
div.coverage-summary .sorter {
|
|
||||||
height: 10px;
|
|
||||||
width: 7px;
|
|
||||||
display: inline-block;
|
|
||||||
margin-left: 0.5em;
|
|
||||||
background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent;
|
|
||||||
}
|
|
||||||
div.coverage-summary .sorted .sorter {
|
|
||||||
background-position: 0 -20px;
|
|
||||||
}
|
|
||||||
div.coverage-summary .sorted-desc .sorter {
|
|
||||||
background-position: 0 -10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.high { background: #b5d592 !important; }
|
|
||||||
.medium { background: #ffe87c !important; }
|
|
||||||
.low { background: #fc8c84 !important; }
|
|
||||||
|
|
||||||
span.cover-fill, span.cover-empty {
|
|
||||||
display:inline-block;
|
|
||||||
border:1px solid #444;
|
|
||||||
background: white;
|
|
||||||
height: 12px;
|
|
||||||
}
|
|
||||||
span.cover-fill {
|
|
||||||
background: #ccc;
|
|
||||||
border-right: 1px solid #444;
|
|
||||||
}
|
|
||||||
span.cover-empty {
|
|
||||||
background: white;
|
|
||||||
border-left: none;
|
|
||||||
}
|
|
||||||
span.cover-full {
|
|
||||||
border-right: none !important;
|
|
||||||
}
|
|
||||||
pre.prettyprint {
|
|
||||||
border: none !important;
|
|
||||||
padding: 0 !important;
|
|
||||||
margin: 0 !important;
|
|
||||||
}
|
|
||||||
.com { color: #999 !important; }
|
|
||||||
.ignore-none { color: #999; font-weight: normal; }
|
|
@ -1,73 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<title>Code coverage report for All files</title>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<link rel="stylesheet" href="prettify.css">
|
|
||||||
<link rel="stylesheet" href="base.css">
|
|
||||||
<style type='text/css'>
|
|
||||||
div.coverage-summary .sorter {
|
|
||||||
background-image: url(sort-arrow-sprite.png);
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="header high">
|
|
||||||
<h1>Code coverage report for <span class="entity">All files</span></h1>
|
|
||||||
<h2>
|
|
||||||
Statements: <span class="metric">100% <small>(37 / 37)</small></span>
|
|
||||||
Branches: <span class="metric">92.86% <small>(13 / 14)</small></span>
|
|
||||||
Functions: <span class="metric">100% <small>(7 / 7)</small></span>
|
|
||||||
Lines: <span class="metric">100% <small>(37 / 37)</small></span>
|
|
||||||
Ignored: <span class="metric"><span class="ignore-none">none</span></span>
|
|
||||||
</h2>
|
|
||||||
<div class="path"></div>
|
|
||||||
</div>
|
|
||||||
<div class="body">
|
|
||||||
<div class="coverage-summary">
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th data-col="file" data-fmt="html" data-html="true" class="file">File</th>
|
|
||||||
<th data-col="pic" data-type="number" data-fmt="html" data-html="true" class="pic"></th>
|
|
||||||
<th data-col="statements" data-type="number" data-fmt="pct" class="pct">Statements</th>
|
|
||||||
<th data-col="statements_raw" data-type="number" data-fmt="html" class="abs"></th>
|
|
||||||
<th data-col="branches" data-type="number" data-fmt="pct" class="pct">Branches</th>
|
|
||||||
<th data-col="branches_raw" data-type="number" data-fmt="html" class="abs"></th>
|
|
||||||
<th data-col="functions" data-type="number" data-fmt="pct" class="pct">Functions</th>
|
|
||||||
<th data-col="functions_raw" data-type="number" data-fmt="html" class="abs"></th>
|
|
||||||
<th data-col="lines" data-type="number" data-fmt="pct" class="pct">Lines</th>
|
|
||||||
<th data-col="lines_raw" data-type="number" data-fmt="html" class="abs"></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody><tr>
|
|
||||||
<td class="file high" data-value="async-throttle/"><a href="async-throttle/index.html">async-throttle/</a></td>
|
|
||||||
<td data-value="100" class="pic high"><span class="cover-fill cover-full" style="width: 100px;"></span><span class="cover-empty" style="width:0px;"></span></td>
|
|
||||||
<td data-value="100" class="pct high">100%</td>
|
|
||||||
<td data-value="37" class="abs high">(37 / 37)</td>
|
|
||||||
<td data-value="92.86" class="pct high">92.86%</td>
|
|
||||||
<td data-value="14" class="abs high">(13 / 14)</td>
|
|
||||||
<td data-value="100" class="pct high">100%</td>
|
|
||||||
<td data-value="7" class="abs high">(7 / 7)</td>
|
|
||||||
<td data-value="100" class="pct high">100%</td>
|
|
||||||
<td data-value="37" class="abs high">(37 / 37)</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="footer">
|
|
||||||
<div class="meta">Generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Mon Sep 11 2017 11:14:14 GMT-0500 (CDT)</div>
|
|
||||||
</div>
|
|
||||||
<script src="prettify.js"></script>
|
|
||||||
<script>
|
|
||||||
window.onload = function () {
|
|
||||||
if (typeof prettyPrint === 'function') {
|
|
||||||
prettyPrint();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
<script src="sorter.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1 +0,0 @@
|
|||||||
.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee}
|
|
File diff suppressed because one or more lines are too long
Binary file not shown.
Before Width: | Height: | Size: 209 B |
@ -1,156 +0,0 @@
|
|||||||
var addSorting = (function () {
|
|
||||||
"use strict";
|
|
||||||
var cols,
|
|
||||||
currentSort = {
|
|
||||||
index: 0,
|
|
||||||
desc: false
|
|
||||||
};
|
|
||||||
|
|
||||||
// returns the summary table element
|
|
||||||
function getTable() { return document.querySelector('.coverage-summary table'); }
|
|
||||||
// returns the thead element of the summary table
|
|
||||||
function getTableHeader() { return getTable().querySelector('thead tr'); }
|
|
||||||
// returns the tbody element of the summary table
|
|
||||||
function getTableBody() { return getTable().querySelector('tbody'); }
|
|
||||||
// returns the th element for nth column
|
|
||||||
function getNthColumn(n) { return getTableHeader().querySelectorAll('th')[n]; }
|
|
||||||
|
|
||||||
// loads all columns
|
|
||||||
function loadColumns() {
|
|
||||||
var colNodes = getTableHeader().querySelectorAll('th'),
|
|
||||||
colNode,
|
|
||||||
cols = [],
|
|
||||||
col,
|
|
||||||
i;
|
|
||||||
|
|
||||||
for (i = 0; i < colNodes.length; i += 1) {
|
|
||||||
colNode = colNodes[i];
|
|
||||||
col = {
|
|
||||||
key: colNode.getAttribute('data-col'),
|
|
||||||
sortable: !colNode.getAttribute('data-nosort'),
|
|
||||||
type: colNode.getAttribute('data-type') || 'string'
|
|
||||||
};
|
|
||||||
cols.push(col);
|
|
||||||
if (col.sortable) {
|
|
||||||
col.defaultDescSort = col.type === 'number';
|
|
||||||
colNode.innerHTML = colNode.innerHTML + '<span class="sorter"></span>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cols;
|
|
||||||
}
|
|
||||||
// attaches a data attribute to every tr element with an object
|
|
||||||
// of data values keyed by column name
|
|
||||||
function loadRowData(tableRow) {
|
|
||||||
var tableCols = tableRow.querySelectorAll('td'),
|
|
||||||
colNode,
|
|
||||||
col,
|
|
||||||
data = {},
|
|
||||||
i,
|
|
||||||
val;
|
|
||||||
for (i = 0; i < tableCols.length; i += 1) {
|
|
||||||
colNode = tableCols[i];
|
|
||||||
col = cols[i];
|
|
||||||
val = colNode.getAttribute('data-value');
|
|
||||||
if (col.type === 'number') {
|
|
||||||
val = Number(val);
|
|
||||||
}
|
|
||||||
data[col.key] = val;
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
// loads all row data
|
|
||||||
function loadData() {
|
|
||||||
var rows = getTableBody().querySelectorAll('tr'),
|
|
||||||
i;
|
|
||||||
|
|
||||||
for (i = 0; i < rows.length; i += 1) {
|
|
||||||
rows[i].data = loadRowData(rows[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// sorts the table using the data for the ith column
|
|
||||||
function sortByIndex(index, desc) {
|
|
||||||
var key = cols[index].key,
|
|
||||||
sorter = function (a, b) {
|
|
||||||
a = a.data[key];
|
|
||||||
b = b.data[key];
|
|
||||||
return a < b ? -1 : a > b ? 1 : 0;
|
|
||||||
},
|
|
||||||
finalSorter = sorter,
|
|
||||||
tableBody = document.querySelector('.coverage-summary tbody'),
|
|
||||||
rowNodes = tableBody.querySelectorAll('tr'),
|
|
||||||
rows = [],
|
|
||||||
i;
|
|
||||||
|
|
||||||
if (desc) {
|
|
||||||
finalSorter = function (a, b) {
|
|
||||||
return -1 * sorter(a, b);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < rowNodes.length; i += 1) {
|
|
||||||
rows.push(rowNodes[i]);
|
|
||||||
tableBody.removeChild(rowNodes[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
rows.sort(finalSorter);
|
|
||||||
|
|
||||||
for (i = 0; i < rows.length; i += 1) {
|
|
||||||
tableBody.appendChild(rows[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// removes sort indicators for current column being sorted
|
|
||||||
function removeSortIndicators() {
|
|
||||||
var col = getNthColumn(currentSort.index),
|
|
||||||
cls = col.className;
|
|
||||||
|
|
||||||
cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
|
|
||||||
col.className = cls;
|
|
||||||
}
|
|
||||||
// adds sort indicators for current column being sorted
|
|
||||||
function addSortIndicators() {
|
|
||||||
getNthColumn(currentSort.index).className += currentSort.desc ? ' sorted-desc' : ' sorted';
|
|
||||||
}
|
|
||||||
// adds event listeners for all sorter widgets
|
|
||||||
function enableUI() {
|
|
||||||
var i,
|
|
||||||
el,
|
|
||||||
ithSorter = function ithSorter(i) {
|
|
||||||
var col = cols[i];
|
|
||||||
|
|
||||||
return function () {
|
|
||||||
var desc = col.defaultDescSort;
|
|
||||||
|
|
||||||
if (currentSort.index === i) {
|
|
||||||
desc = !currentSort.desc;
|
|
||||||
}
|
|
||||||
sortByIndex(i, desc);
|
|
||||||
removeSortIndicators();
|
|
||||||
currentSort.index = i;
|
|
||||||
currentSort.desc = desc;
|
|
||||||
addSortIndicators();
|
|
||||||
};
|
|
||||||
};
|
|
||||||
for (i =0 ; i < cols.length; i += 1) {
|
|
||||||
if (cols[i].sortable) {
|
|
||||||
el = getNthColumn(i).querySelector('.sorter');
|
|
||||||
if (el.addEventListener) {
|
|
||||||
el.addEventListener('click', ithSorter(i));
|
|
||||||
} else {
|
|
||||||
el.attachEvent('onclick', ithSorter(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// adds sorting functionality to the UI
|
|
||||||
return function () {
|
|
||||||
if (!getTable()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cols = loadColumns();
|
|
||||||
loadData(cols);
|
|
||||||
addSortIndicators();
|
|
||||||
enableUI();
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
|
|
||||||
window.addEventListener('load', addSorting);
|
|
@ -1,74 +0,0 @@
|
|||||||
TN:
|
|
||||||
SF:/Users/samuelreed/git/forks/async-throttle/index.js
|
|
||||||
FN:3,Queue
|
|
||||||
FN:22,(anonymous_2)
|
|
||||||
FN:23,(anonymous_3)
|
|
||||||
FN:31,(anonymous_4)
|
|
||||||
FN:36,(anonymous_5)
|
|
||||||
FN:55,(anonymous_6)
|
|
||||||
FN:62,done
|
|
||||||
FNF:7
|
|
||||||
FNH:7
|
|
||||||
FNDA:7,Queue
|
|
||||||
FNDA:3,(anonymous_2)
|
|
||||||
FNDA:13,(anonymous_3)
|
|
||||||
FNDA:19,(anonymous_4)
|
|
||||||
FNDA:45,(anonymous_5)
|
|
||||||
FNDA:6,(anonymous_6)
|
|
||||||
FNDA:13,done
|
|
||||||
DA:3,1
|
|
||||||
DA:4,7
|
|
||||||
DA:5,1
|
|
||||||
DA:8,6
|
|
||||||
DA:9,6
|
|
||||||
DA:10,6
|
|
||||||
DA:11,6
|
|
||||||
DA:12,6
|
|
||||||
DA:13,6
|
|
||||||
DA:16,1
|
|
||||||
DA:22,1
|
|
||||||
DA:23,3
|
|
||||||
DA:24,13
|
|
||||||
DA:25,13
|
|
||||||
DA:26,13
|
|
||||||
DA:30,1
|
|
||||||
DA:32,19
|
|
||||||
DA:36,1
|
|
||||||
DA:37,45
|
|
||||||
DA:38,6
|
|
||||||
DA:40,39
|
|
||||||
DA:41,13
|
|
||||||
DA:42,13
|
|
||||||
DA:43,13
|
|
||||||
DA:44,13
|
|
||||||
DA:47,39
|
|
||||||
DA:48,18
|
|
||||||
DA:49,6
|
|
||||||
DA:50,6
|
|
||||||
DA:55,1
|
|
||||||
DA:56,6
|
|
||||||
DA:57,6
|
|
||||||
DA:58,6
|
|
||||||
DA:62,1
|
|
||||||
DA:63,13
|
|
||||||
DA:64,13
|
|
||||||
DA:67,1
|
|
||||||
LF:37
|
|
||||||
LH:37
|
|
||||||
BRDA:4,1,0,1
|
|
||||||
BRDA:4,1,1,6
|
|
||||||
BRDA:8,2,0,6
|
|
||||||
BRDA:8,2,1,5
|
|
||||||
BRDA:9,3,0,6
|
|
||||||
BRDA:9,3,1,5
|
|
||||||
BRDA:37,4,0,6
|
|
||||||
BRDA:37,4,1,39
|
|
||||||
BRDA:40,5,0,13
|
|
||||||
BRDA:40,5,1,26
|
|
||||||
BRDA:47,6,0,18
|
|
||||||
BRDA:47,6,1,21
|
|
||||||
BRDA:56,7,0,6
|
|
||||||
BRDA:56,7,1,0
|
|
||||||
BRF:14
|
|
||||||
BRH:13
|
|
||||||
end_of_record
|
|
@ -1,67 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
function Queue(options) {
|
|
||||||
if (!(this instanceof Queue)) {
|
|
||||||
return new Queue(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
options = options || {};
|
|
||||||
this.concurrency = options.concurrency || Infinity;
|
|
||||||
this.pending = 0;
|
|
||||||
this.jobs = [];
|
|
||||||
this.cbs = [];
|
|
||||||
this._done = done.bind(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
var arrayAddMethods = [
|
|
||||||
'push',
|
|
||||||
'unshift',
|
|
||||||
'splice'
|
|
||||||
];
|
|
||||||
|
|
||||||
arrayAddMethods.forEach(function(method) {
|
|
||||||
Queue.prototype[method] = function() {
|
|
||||||
var methodResult = Array.prototype[method].apply(this.jobs, arguments);
|
|
||||||
this._run();
|
|
||||||
return methodResult;
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
Object.defineProperty(Queue.prototype, 'length', {
|
|
||||||
get: function() {
|
|
||||||
return this.pending + this.jobs.length;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Queue.prototype._run = function() {
|
|
||||||
if (this.pending === this.concurrency) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (this.jobs.length) {
|
|
||||||
var job = this.jobs.shift();
|
|
||||||
this.pending++;
|
|
||||||
job(this._done);
|
|
||||||
this._run();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.pending === 0) {
|
|
||||||
while (this.cbs.length !== 0) {
|
|
||||||
var cb = this.cbs.pop();
|
|
||||||
process.nextTick(cb);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Queue.prototype.onDone = function(cb) {
|
|
||||||
if (typeof cb === 'function') {
|
|
||||||
this.cbs.push(cb);
|
|
||||||
this._run();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function done() {
|
|
||||||
this.pending--;
|
|
||||||
this._run();
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Queue;
|
|
@ -1,69 +0,0 @@
|
|||||||
{
|
|
||||||
"_from": "async-limiter@~1.0.0",
|
|
||||||
"_id": "async-limiter@1.0.0",
|
|
||||||
"_inBundle": false,
|
|
||||||
"_integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==",
|
|
||||||
"_location": "/async-limiter",
|
|
||||||
"_phantomChildren": {},
|
|
||||||
"_requested": {
|
|
||||||
"type": "range",
|
|
||||||
"registry": true,
|
|
||||||
"raw": "async-limiter@~1.0.0",
|
|
||||||
"name": "async-limiter",
|
|
||||||
"escapedName": "async-limiter",
|
|
||||||
"rawSpec": "~1.0.0",
|
|
||||||
"saveSpec": null,
|
|
||||||
"fetchSpec": "~1.0.0"
|
|
||||||
},
|
|
||||||
"_requiredBy": [
|
|
||||||
"/ws"
|
|
||||||
],
|
|
||||||
"_resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz",
|
|
||||||
"_shasum": "78faed8c3d074ab81f22b4e985d79e8738f720f8",
|
|
||||||
"_spec": "async-limiter@~1.0.0",
|
|
||||||
"_where": "/Users/loic/Documents/DiscordBotV2/node_modules/ws",
|
|
||||||
"author": {
|
|
||||||
"name": "Samuel Reed"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/strml/async-limiter/issues"
|
|
||||||
},
|
|
||||||
"bundleDependencies": false,
|
|
||||||
"dependencies": {},
|
|
||||||
"deprecated": false,
|
|
||||||
"description": "asynchronous function queue with adjustable concurrency",
|
|
||||||
"devDependencies": {
|
|
||||||
"coveralls": "^2.11.2",
|
|
||||||
"eslint": "^4.6.1",
|
|
||||||
"eslint-plugin-mocha": "^4.11.0",
|
|
||||||
"intelli-espower-loader": "^1.0.1",
|
|
||||||
"istanbul": "^0.3.2",
|
|
||||||
"mocha": "^3.5.2",
|
|
||||||
"power-assert": "^1.4.4"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/strml/async-limiter#readme",
|
|
||||||
"keywords": [
|
|
||||||
"throttle",
|
|
||||||
"async",
|
|
||||||
"limiter",
|
|
||||||
"asynchronous",
|
|
||||||
"job",
|
|
||||||
"task",
|
|
||||||
"concurrency",
|
|
||||||
"concurrent"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"name": "async-limiter",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/strml/async-limiter.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls",
|
|
||||||
"example": "node example",
|
|
||||||
"lint": "eslint .",
|
|
||||||
"test": "mocha --R intelli-espower-loader test/",
|
|
||||||
"travis": "npm run lint && npm run coverage"
|
|
||||||
},
|
|
||||||
"version": "1.0.0"
|
|
||||||
}
|
|
@ -1,132 +0,0 @@
|
|||||||
# Async-Limiter
|
|
||||||
|
|
||||||
A module for limiting concurrent asynchronous actions in flight. Forked from [queue](https://github.com/jessetane/queue).
|
|
||||||
|
|
||||||
[![npm](http://img.shields.io/npm/v/async-limiter.svg?style=flat-square)](http://www.npmjs.org/async-limiter)
|
|
||||||
[![tests](https://img.shields.io/travis/STRML/async-limiter.svg?style=flat-square&branch=master)](https://travis-ci.org/STRML/async-limiter)
|
|
||||||
[![coverage](https://img.shields.io/coveralls/STRML/async-limiter.svg?style=flat-square&branch=master)](https://coveralls.io/r/STRML/async-limiter)
|
|
||||||
|
|
||||||
This module exports a class `Limiter` that implements some of the `Array` API.
|
|
||||||
Pass async functions (ones that accept a callback or return a promise) to an instance's additive array methods.
|
|
||||||
|
|
||||||
## Motivation
|
|
||||||
|
|
||||||
Certain functions, like `zlib`, have [undesirable behavior](https://github.com/nodejs/node/issues/8871#issuecomment-250915913) when
|
|
||||||
run at infinite concurrency.
|
|
||||||
|
|
||||||
In this case, it is actually faster, and takes far less memory, to limit concurrency.
|
|
||||||
|
|
||||||
This module should do the absolute minimum work necessary to queue up functions. PRs are welcome that would
|
|
||||||
make this module faster or lighter, but new functionality is not desired.
|
|
||||||
|
|
||||||
Style should confirm to nodejs/node style.
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
``` javascript
|
|
||||||
var Limiter = require('async-limiter')
|
|
||||||
|
|
||||||
var t = new Limiter({concurrency: 2});
|
|
||||||
var results = []
|
|
||||||
|
|
||||||
// add jobs using the familiar Array API
|
|
||||||
t.push(function (cb) {
|
|
||||||
results.push('two')
|
|
||||||
cb()
|
|
||||||
})
|
|
||||||
|
|
||||||
t.push(
|
|
||||||
function (cb) {
|
|
||||||
results.push('four')
|
|
||||||
cb()
|
|
||||||
},
|
|
||||||
function (cb) {
|
|
||||||
results.push('five')
|
|
||||||
cb()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
t.unshift(function (cb) {
|
|
||||||
results.push('one')
|
|
||||||
cb()
|
|
||||||
})
|
|
||||||
|
|
||||||
t.splice(2, 0, function (cb) {
|
|
||||||
results.push('three')
|
|
||||||
cb()
|
|
||||||
})
|
|
||||||
|
|
||||||
// Jobs run automatically. If you want a callback when all are done,
|
|
||||||
// call 'onDone()'.
|
|
||||||
t.onDone(function () {
|
|
||||||
console.log('all done:', results)
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
## Zlib Example
|
|
||||||
|
|
||||||
```js
|
|
||||||
const zlib = require('zlib');
|
|
||||||
const Limiter = require('async-limiter');
|
|
||||||
|
|
||||||
const message = {some: "data"};
|
|
||||||
const payload = new Buffer(JSON.stringify(message));
|
|
||||||
|
|
||||||
// Try with different concurrency values to see how this actually
|
|
||||||
// slows significantly with higher concurrency!
|
|
||||||
//
|
|
||||||
// 5: 1398.607ms
|
|
||||||
// 10: 1375.668ms
|
|
||||||
// Infinity: 4423.300ms
|
|
||||||
//
|
|
||||||
const t = new Limiter({concurrency: 5});
|
|
||||||
function deflate(payload, cb) {
|
|
||||||
t.push(function(done) {
|
|
||||||
zlib.deflate(payload, function(err, buffer) {
|
|
||||||
done();
|
|
||||||
cb(err, buffer);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
console.time('deflate');
|
|
||||||
for(let i = 0; i < 30000; ++i) {
|
|
||||||
deflate(payload, function (err, buffer) {});
|
|
||||||
}
|
|
||||||
q.onDone(function() {
|
|
||||||
console.timeEnd('deflate');
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
`npm install async-limiter`
|
|
||||||
|
|
||||||
## Test
|
|
||||||
|
|
||||||
`npm test`
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
### `var t = new Limiter([opts])`
|
|
||||||
Constructor. `opts` may contain inital values for:
|
|
||||||
* `q.concurrency`
|
|
||||||
|
|
||||||
## Instance methods
|
|
||||||
|
|
||||||
### `q.onDone(fn)`
|
|
||||||
`fn` will be called once and only once, when the queue is empty.
|
|
||||||
|
|
||||||
## Instance methods mixed in from `Array`
|
|
||||||
Mozilla has docs on how these methods work [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).
|
|
||||||
### `q.push(element1, ..., elementN)`
|
|
||||||
### `q.unshift(element1, ..., elementN)`
|
|
||||||
### `q.splice(index , howMany[, element1[, ...[, elementN]]])`
|
|
||||||
|
|
||||||
## Properties
|
|
||||||
### `q.concurrency`
|
|
||||||
Max number of jobs the queue should process concurrently, defaults to `Infinity`.
|
|
||||||
|
|
||||||
### `q.length`
|
|
||||||
Jobs pending + jobs to process (readonly).
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
|||||||
language: node_js
|
|
||||||
node_js:
|
|
||||||
- "0.8"
|
|
||||||
- "0.10"
|
|
||||||
- "0.11"
|
|
@ -1,21 +0,0 @@
|
|||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2014
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
@ -1,31 +0,0 @@
|
|||||||
base64-js
|
|
||||||
=========
|
|
||||||
|
|
||||||
`base64-js` does basic base64 encoding/decoding in pure JS.
|
|
||||||
|
|
||||||
[![build status](https://secure.travis-ci.org/beatgammit/base64-js.png)](http://travis-ci.org/beatgammit/base64-js)
|
|
||||||
|
|
||||||
[![testling badge](https://ci.testling.com/beatgammit/base64-js.png)](https://ci.testling.com/beatgammit/base64-js)
|
|
||||||
|
|
||||||
Many browsers already have base64 encoding/decoding functionality, but it is for text data, not all-purpose binary data.
|
|
||||||
|
|
||||||
Sometimes encoding/decoding binary data in the browser is useful, and that is what this module does.
|
|
||||||
|
|
||||||
## install
|
|
||||||
|
|
||||||
With [npm](https://npmjs.org) do:
|
|
||||||
|
|
||||||
`npm install base64-js`
|
|
||||||
|
|
||||||
## methods
|
|
||||||
|
|
||||||
`var base64 = require('base64-js')`
|
|
||||||
|
|
||||||
`base64` has two exposed functions, `toByteArray` and `fromByteArray`, which both take a single argument.
|
|
||||||
|
|
||||||
* `toByteArray` - Takes a base64 string and returns a byte array
|
|
||||||
* `fromByteArray` - Takes a byte array and returns a base64 string
|
|
||||||
|
|
||||||
## license
|
|
||||||
|
|
||||||
MIT
|
|
@ -1,19 +0,0 @@
|
|||||||
var random = require('crypto').pseudoRandomBytes
|
|
||||||
|
|
||||||
var b64 = require('../')
|
|
||||||
var fs = require('fs')
|
|
||||||
var path = require('path')
|
|
||||||
var data = random(1e6).toString('base64')
|
|
||||||
//fs.readFileSync(path.join(__dirname, 'example.b64'), 'ascii').split('\n').join('')
|
|
||||||
var start = Date.now()
|
|
||||||
var raw = b64.toByteArray(data)
|
|
||||||
var middle = Date.now()
|
|
||||||
var data = b64.fromByteArray(raw)
|
|
||||||
var end = Date.now()
|
|
||||||
|
|
||||||
console.log('decode ms, decode ops/ms, encode ms, encode ops/ms')
|
|
||||||
console.log(
|
|
||||||
middle - start, data.length / (middle - start),
|
|
||||||
end - middle, data.length / (end - middle))
|
|
||||||
//console.log(data)
|
|
||||||
|
|
@ -1,124 +0,0 @@
|
|||||||
var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
||||||
|
|
||||||
;(function (exports) {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var Arr = (typeof Uint8Array !== 'undefined')
|
|
||||||
? Uint8Array
|
|
||||||
: Array
|
|
||||||
|
|
||||||
var PLUS = '+'.charCodeAt(0)
|
|
||||||
var SLASH = '/'.charCodeAt(0)
|
|
||||||
var NUMBER = '0'.charCodeAt(0)
|
|
||||||
var LOWER = 'a'.charCodeAt(0)
|
|
||||||
var UPPER = 'A'.charCodeAt(0)
|
|
||||||
var PLUS_URL_SAFE = '-'.charCodeAt(0)
|
|
||||||
var SLASH_URL_SAFE = '_'.charCodeAt(0)
|
|
||||||
|
|
||||||
function decode (elt) {
|
|
||||||
var code = elt.charCodeAt(0)
|
|
||||||
if (code === PLUS ||
|
|
||||||
code === PLUS_URL_SAFE)
|
|
||||||
return 62 // '+'
|
|
||||||
if (code === SLASH ||
|
|
||||||
code === SLASH_URL_SAFE)
|
|
||||||
return 63 // '/'
|
|
||||||
if (code < NUMBER)
|
|
||||||
return -1 //no match
|
|
||||||
if (code < NUMBER + 10)
|
|
||||||
return code - NUMBER + 26 + 26
|
|
||||||
if (code < UPPER + 26)
|
|
||||||
return code - UPPER
|
|
||||||
if (code < LOWER + 26)
|
|
||||||
return code - LOWER + 26
|
|
||||||
}
|
|
||||||
|
|
||||||
function b64ToByteArray (b64) {
|
|
||||||
var i, j, l, tmp, placeHolders, arr
|
|
||||||
|
|
||||||
if (b64.length % 4 > 0) {
|
|
||||||
throw new Error('Invalid string. Length must be a multiple of 4')
|
|
||||||
}
|
|
||||||
|
|
||||||
// the number of equal signs (place holders)
|
|
||||||
// if there are two placeholders, than the two characters before it
|
|
||||||
// represent one byte
|
|
||||||
// if there is only one, then the three characters before it represent 2 bytes
|
|
||||||
// this is just a cheap hack to not do indexOf twice
|
|
||||||
var len = b64.length
|
|
||||||
placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0
|
|
||||||
|
|
||||||
// base64 is 4/3 + up to two characters of the original data
|
|
||||||
arr = new Arr(b64.length * 3 / 4 - placeHolders)
|
|
||||||
|
|
||||||
// if there are placeholders, only get up to the last complete 4 chars
|
|
||||||
l = placeHolders > 0 ? b64.length - 4 : b64.length
|
|
||||||
|
|
||||||
var L = 0
|
|
||||||
|
|
||||||
function push (v) {
|
|
||||||
arr[L++] = v
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0, j = 0; i < l; i += 4, j += 3) {
|
|
||||||
tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3))
|
|
||||||
push((tmp & 0xFF0000) >> 16)
|
|
||||||
push((tmp & 0xFF00) >> 8)
|
|
||||||
push(tmp & 0xFF)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (placeHolders === 2) {
|
|
||||||
tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4)
|
|
||||||
push(tmp & 0xFF)
|
|
||||||
} else if (placeHolders === 1) {
|
|
||||||
tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2)
|
|
||||||
push((tmp >> 8) & 0xFF)
|
|
||||||
push(tmp & 0xFF)
|
|
||||||
}
|
|
||||||
|
|
||||||
return arr
|
|
||||||
}
|
|
||||||
|
|
||||||
function uint8ToBase64 (uint8) {
|
|
||||||
var i,
|
|
||||||
extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
|
|
||||||
output = "",
|
|
||||||
temp, length
|
|
||||||
|
|
||||||
function encode (num) {
|
|
||||||
return lookup.charAt(num)
|
|
||||||
}
|
|
||||||
|
|
||||||
function tripletToBase64 (num) {
|
|
||||||
return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F)
|
|
||||||
}
|
|
||||||
|
|
||||||
// go through the array every three bytes, we'll deal with trailing stuff later
|
|
||||||
for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
|
|
||||||
temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
|
|
||||||
output += tripletToBase64(temp)
|
|
||||||
}
|
|
||||||
|
|
||||||
// pad the end with zeros, but make sure to not forget the extra bytes
|
|
||||||
switch (extraBytes) {
|
|
||||||
case 1:
|
|
||||||
temp = uint8[uint8.length - 1]
|
|
||||||
output += encode(temp >> 2)
|
|
||||||
output += encode((temp << 4) & 0x3F)
|
|
||||||
output += '=='
|
|
||||||
break
|
|
||||||
case 2:
|
|
||||||
temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1])
|
|
||||||
output += encode(temp >> 10)
|
|
||||||
output += encode((temp >> 4) & 0x3F)
|
|
||||||
output += encode((temp << 2) & 0x3F)
|
|
||||||
output += '='
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
return output
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.toByteArray = b64ToByteArray
|
|
||||||
exports.fromByteArray = uint8ToBase64
|
|
||||||
}(typeof exports === 'undefined' ? (this.base64js = {}) : exports))
|
|
@ -1,51 +0,0 @@
|
|||||||
var test = require('tape'),
|
|
||||||
b64 = require('../lib/b64'),
|
|
||||||
checks = [
|
|
||||||
'a',
|
|
||||||
'aa',
|
|
||||||
'aaa',
|
|
||||||
'hi',
|
|
||||||
'hi!',
|
|
||||||
'hi!!',
|
|
||||||
'sup',
|
|
||||||
'sup?',
|
|
||||||
'sup?!'
|
|
||||||
];
|
|
||||||
|
|
||||||
test('convert to base64 and back', function (t) {
|
|
||||||
t.plan(checks.length);
|
|
||||||
|
|
||||||
for (var i = 0; i < checks.length; i++) {
|
|
||||||
var check = checks[i],
|
|
||||||
b64Str,
|
|
||||||
arr,
|
|
||||||
str;
|
|
||||||
|
|
||||||
b64Str = b64.fromByteArray(map(check, function (char) { return char.charCodeAt(0); }));
|
|
||||||
|
|
||||||
arr = b64.toByteArray(b64Str);
|
|
||||||
str = map(arr, function (byte) { return String.fromCharCode(byte); }).join('');
|
|
||||||
|
|
||||||
t.equal(check, str, 'Checked ' + check);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
function map (arr, callback) {
|
|
||||||
var res = [],
|
|
||||||
kValue,
|
|
||||||
mappedValue;
|
|
||||||
|
|
||||||
for (var k = 0, len = arr.length; k < len; k++) {
|
|
||||||
if ((typeof arr === 'string' && !!arr.charAt(k))) {
|
|
||||||
kValue = arr.charAt(k);
|
|
||||||
mappedValue = callback(kValue, k, arr);
|
|
||||||
res[k] = mappedValue;
|
|
||||||
} else if (typeof arr !== 'string' && k in arr) {
|
|
||||||
kValue = arr[k];
|
|
||||||
mappedValue = callback(kValue, k, arr);
|
|
||||||
res[k] = mappedValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
var test = require('tape'),
|
|
||||||
b64 = require('../lib/b64');
|
|
||||||
|
|
||||||
test('decode url-safe style base64 strings', function (t) {
|
|
||||||
var expected = [0xff, 0xff, 0xbe, 0xff, 0xef, 0xbf, 0xfb, 0xef, 0xff];
|
|
||||||
|
|
||||||
var actual = b64.toByteArray('//++/++/++//');
|
|
||||||
for (var i = 0; i < actual.length; i++) {
|
|
||||||
t.equal(actual[i], expected[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
actual = b64.toByteArray('__--_--_--__');
|
|
||||||
for (var i = 0; i < actual.length; i++) {
|
|
||||||
t.equal(actual[i], expected[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
t.end();
|
|
||||||
});
|
|
@ -1,97 +0,0 @@
|
|||||||
node-bindings
|
|
||||||
=============
|
|
||||||
### Helper module for loading your native module's .node file
|
|
||||||
|
|
||||||
This is a helper module for authors of Node.js native addon modules.
|
|
||||||
It is basically the "swiss army knife" of `require()`ing your native module's
|
|
||||||
`.node` file.
|
|
||||||
|
|
||||||
Throughout the course of Node's native addon history, addons have ended up being
|
|
||||||
compiled in a variety of different places, depending on which build tool and which
|
|
||||||
version of node was used. To make matters worse, now the _gyp_ build tool can
|
|
||||||
produce either a _Release_ or _Debug_ build, each being built into different
|
|
||||||
locations.
|
|
||||||
|
|
||||||
This module checks _all_ the possible locations that a native addon would be built
|
|
||||||
at, and returns the first one that loads successfully.
|
|
||||||
|
|
||||||
|
|
||||||
Installation
|
|
||||||
------------
|
|
||||||
|
|
||||||
Install with `npm`:
|
|
||||||
|
|
||||||
``` bash
|
|
||||||
$ npm install bindings
|
|
||||||
```
|
|
||||||
|
|
||||||
Or add it to the `"dependencies"` section of your _package.json_ file.
|
|
||||||
|
|
||||||
|
|
||||||
Example
|
|
||||||
-------
|
|
||||||
|
|
||||||
`require()`ing the proper bindings file for the current node version, platform
|
|
||||||
and architecture is as simple as:
|
|
||||||
|
|
||||||
``` js
|
|
||||||
var bindings = require('bindings')('binding.node')
|
|
||||||
|
|
||||||
// Use your bindings defined in your C files
|
|
||||||
bindings.your_c_function()
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
Nice Error Output
|
|
||||||
-----------------
|
|
||||||
|
|
||||||
When the `.node` file could not be loaded, `node-bindings` throws an Error with
|
|
||||||
a nice error message telling you exactly what was tried. You can also check the
|
|
||||||
`err.tries` Array property.
|
|
||||||
|
|
||||||
```
|
|
||||||
Error: Could not load the bindings file. Tried:
|
|
||||||
→ /Users/nrajlich/ref/build/binding.node
|
|
||||||
→ /Users/nrajlich/ref/build/Debug/binding.node
|
|
||||||
→ /Users/nrajlich/ref/build/Release/binding.node
|
|
||||||
→ /Users/nrajlich/ref/out/Debug/binding.node
|
|
||||||
→ /Users/nrajlich/ref/Debug/binding.node
|
|
||||||
→ /Users/nrajlich/ref/out/Release/binding.node
|
|
||||||
→ /Users/nrajlich/ref/Release/binding.node
|
|
||||||
→ /Users/nrajlich/ref/build/default/binding.node
|
|
||||||
→ /Users/nrajlich/ref/compiled/0.8.2/darwin/x64/binding.node
|
|
||||||
at bindings (/Users/nrajlich/ref/node_modules/bindings/bindings.js:84:13)
|
|
||||||
at Object.<anonymous> (/Users/nrajlich/ref/lib/ref.js:5:47)
|
|
||||||
at Module._compile (module.js:449:26)
|
|
||||||
at Object.Module._extensions..js (module.js:467:10)
|
|
||||||
at Module.load (module.js:356:32)
|
|
||||||
at Function.Module._load (module.js:312:12)
|
|
||||||
...
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
License
|
|
||||||
-------
|
|
||||||
|
|
||||||
(The MIT License)
|
|
||||||
|
|
||||||
Copyright (c) 2012 Nathan Rajlich <nathan@tootallnate.net>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
a copy of this software and associated documentation files (the
|
|
||||||
'Software'), to deal in the Software without restriction, including
|
|
||||||
without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be
|
|
||||||
included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
||||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
||||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
||||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
||||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -1,166 +0,0 @@
|
|||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var fs = require('fs')
|
|
||||||
, path = require('path')
|
|
||||||
, join = path.join
|
|
||||||
, dirname = path.dirname
|
|
||||||
, exists = fs.existsSync || path.existsSync
|
|
||||||
, defaults = {
|
|
||||||
arrow: process.env.NODE_BINDINGS_ARROW || ' → '
|
|
||||||
, compiled: process.env.NODE_BINDINGS_COMPILED_DIR || 'compiled'
|
|
||||||
, platform: process.platform
|
|
||||||
, arch: process.arch
|
|
||||||
, version: process.versions.node
|
|
||||||
, bindings: 'bindings.node'
|
|
||||||
, try: [
|
|
||||||
// node-gyp's linked version in the "build" dir
|
|
||||||
[ 'module_root', 'build', 'bindings' ]
|
|
||||||
// node-waf and gyp_addon (a.k.a node-gyp)
|
|
||||||
, [ 'module_root', 'build', 'Debug', 'bindings' ]
|
|
||||||
, [ 'module_root', 'build', 'Release', 'bindings' ]
|
|
||||||
// Debug files, for development (legacy behavior, remove for node v0.9)
|
|
||||||
, [ 'module_root', 'out', 'Debug', 'bindings' ]
|
|
||||||
, [ 'module_root', 'Debug', 'bindings' ]
|
|
||||||
// Release files, but manually compiled (legacy behavior, remove for node v0.9)
|
|
||||||
, [ 'module_root', 'out', 'Release', 'bindings' ]
|
|
||||||
, [ 'module_root', 'Release', 'bindings' ]
|
|
||||||
// Legacy from node-waf, node <= 0.4.x
|
|
||||||
, [ 'module_root', 'build', 'default', 'bindings' ]
|
|
||||||
// Production "Release" buildtype binary (meh...)
|
|
||||||
, [ 'module_root', 'compiled', 'version', 'platform', 'arch', 'bindings' ]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The main `bindings()` function loads the compiled bindings for a given module.
|
|
||||||
* It uses V8's Error API to determine the parent filename that this function is
|
|
||||||
* being invoked from, which is then used to find the root directory.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function bindings (opts) {
|
|
||||||
|
|
||||||
// Argument surgery
|
|
||||||
if (typeof opts == 'string') {
|
|
||||||
opts = { bindings: opts }
|
|
||||||
} else if (!opts) {
|
|
||||||
opts = {}
|
|
||||||
}
|
|
||||||
opts.__proto__ = defaults
|
|
||||||
|
|
||||||
// Get the module root
|
|
||||||
if (!opts.module_root) {
|
|
||||||
opts.module_root = exports.getRoot(exports.getFileName())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure the given bindings name ends with .node
|
|
||||||
if (path.extname(opts.bindings) != '.node') {
|
|
||||||
opts.bindings += '.node'
|
|
||||||
}
|
|
||||||
|
|
||||||
var tries = []
|
|
||||||
, i = 0
|
|
||||||
, l = opts.try.length
|
|
||||||
, n
|
|
||||||
, b
|
|
||||||
, err
|
|
||||||
|
|
||||||
for (; i<l; i++) {
|
|
||||||
n = join.apply(null, opts.try[i].map(function (p) {
|
|
||||||
return opts[p] || p
|
|
||||||
}))
|
|
||||||
tries.push(n)
|
|
||||||
try {
|
|
||||||
b = opts.path ? require.resolve(n) : require(n)
|
|
||||||
if (!opts.path) {
|
|
||||||
b.path = n
|
|
||||||
}
|
|
||||||
return b
|
|
||||||
} catch (e) {
|
|
||||||
if (!/not find/i.test(e.message)) {
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
err = new Error('Could not locate the bindings file. Tried:\n'
|
|
||||||
+ tries.map(function (a) { return opts.arrow + a }).join('\n'))
|
|
||||||
err.tries = tries
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
module.exports = exports = bindings
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the filename of the JavaScript file that invokes this function.
|
|
||||||
* Used to help find the root directory of a module.
|
|
||||||
* Optionally accepts an filename argument to skip when searching for the invoking filename
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.getFileName = function getFileName (calling_file) {
|
|
||||||
var origPST = Error.prepareStackTrace
|
|
||||||
, origSTL = Error.stackTraceLimit
|
|
||||||
, dummy = {}
|
|
||||||
, fileName
|
|
||||||
|
|
||||||
Error.stackTraceLimit = 10
|
|
||||||
|
|
||||||
Error.prepareStackTrace = function (e, st) {
|
|
||||||
for (var i=0, l=st.length; i<l; i++) {
|
|
||||||
fileName = st[i].getFileName()
|
|
||||||
if (fileName !== __filename) {
|
|
||||||
if (calling_file) {
|
|
||||||
if (fileName !== calling_file) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// run the 'prepareStackTrace' function above
|
|
||||||
Error.captureStackTrace(dummy)
|
|
||||||
dummy.stack
|
|
||||||
|
|
||||||
// cleanup
|
|
||||||
Error.prepareStackTrace = origPST
|
|
||||||
Error.stackTraceLimit = origSTL
|
|
||||||
|
|
||||||
return fileName
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the root directory of a module, given an arbitrary filename
|
|
||||||
* somewhere in the module tree. The "root directory" is the directory
|
|
||||||
* containing the `package.json` file.
|
|
||||||
*
|
|
||||||
* In: /home/nate/node-native-module/lib/index.js
|
|
||||||
* Out: /home/nate/node-native-module
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.getRoot = function getRoot (file) {
|
|
||||||
var dir = dirname(file)
|
|
||||||
, prev
|
|
||||||
while (true) {
|
|
||||||
if (dir === '.') {
|
|
||||||
// Avoids an infinite loop in rare cases, like the REPL
|
|
||||||
dir = process.cwd()
|
|
||||||
}
|
|
||||||
if (exists(join(dir, 'package.json')) || exists(join(dir, 'node_modules'))) {
|
|
||||||
// Found the 'package.json' file or 'node_modules' dir; we're done
|
|
||||||
return dir
|
|
||||||
}
|
|
||||||
if (prev === dir) {
|
|
||||||
// Got to the top
|
|
||||||
throw new Error('Could not find module root given file: "' + file
|
|
||||||
+ '". Do you have a `package.json` file? ')
|
|
||||||
}
|
|
||||||
// Try the parent dir next
|
|
||||||
prev = dir
|
|
||||||
dir = join(dir, '..')
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
{
|
|
||||||
"predef": [ ]
|
|
||||||
, "bitwise": false
|
|
||||||
, "camelcase": false
|
|
||||||
, "curly": false
|
|
||||||
, "eqeqeq": false
|
|
||||||
, "forin": false
|
|
||||||
, "immed": false
|
|
||||||
, "latedef": false
|
|
||||||
, "noarg": true
|
|
||||||
, "noempty": true
|
|
||||||
, "nonew": true
|
|
||||||
, "plusplus": false
|
|
||||||
, "quotmark": true
|
|
||||||
, "regexp": false
|
|
||||||
, "undef": true
|
|
||||||
, "unused": true
|
|
||||||
, "strict": false
|
|
||||||
, "trailing": true
|
|
||||||
, "maxlen": 120
|
|
||||||
, "asi": true
|
|
||||||
, "boss": true
|
|
||||||
, "debug": true
|
|
||||||
, "eqnull": true
|
|
||||||
, "esnext": true
|
|
||||||
, "evil": true
|
|
||||||
, "expr": true
|
|
||||||
, "funcscope": false
|
|
||||||
, "globalstrict": false
|
|
||||||
, "iterator": false
|
|
||||||
, "lastsemic": true
|
|
||||||
, "laxbreak": true
|
|
||||||
, "laxcomma": true
|
|
||||||
, "loopfunc": true
|
|
||||||
, "multistr": false
|
|
||||||
, "onecase": false
|
|
||||||
, "proto": false
|
|
||||||
, "regexdash": false
|
|
||||||
, "scripturl": true
|
|
||||||
, "smarttabs": false
|
|
||||||
, "shadow": false
|
|
||||||
, "sub": true
|
|
||||||
, "supernew": false
|
|
||||||
, "validthis": true
|
|
||||||
, "browser": true
|
|
||||||
, "couch": false
|
|
||||||
, "devel": false
|
|
||||||
, "dojo": false
|
|
||||||
, "mootools": false
|
|
||||||
, "node": true
|
|
||||||
, "nonstandard": true
|
|
||||||
, "prototypejs": false
|
|
||||||
, "rhino": false
|
|
||||||
, "worker": true
|
|
||||||
, "wsh": false
|
|
||||||
, "nomen": false
|
|
||||||
, "onevar": false
|
|
||||||
, "passfail": false
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
sudo: false
|
|
||||||
language: node_js
|
|
||||||
node_js:
|
|
||||||
- '0.10'
|
|
||||||
- '0.12'
|
|
||||||
- '4'
|
|
||||||
- '6'
|
|
||||||
- '8'
|
|
||||||
- '9'
|
|
||||||
branches:
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
notifications:
|
|
||||||
email:
|
|
||||||
- rod@vagg.org
|
|
||||||
- matteo.collina@gmail.com
|
|
@ -1,13 +0,0 @@
|
|||||||
The MIT License (MIT)
|
|
||||||
=====================
|
|
||||||
|
|
||||||
Copyright (c) 2013-2016 bl contributors
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
*bl contributors listed at <https://github.com/rvagg/bl#contributors>*
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -1,208 +0,0 @@
|
|||||||
# bl *(BufferList)*
|
|
||||||
|
|
||||||
[![Build Status](https://travis-ci.org/rvagg/bl.svg?branch=master)](https://travis-ci.org/rvagg/bl)
|
|
||||||
|
|
||||||
**A Node.js Buffer list collector, reader and streamer thingy.**
|
|
||||||
|
|
||||||
[![NPM](https://nodei.co/npm/bl.png?downloads=true&downloadRank=true)](https://nodei.co/npm/bl/)
|
|
||||||
[![NPM](https://nodei.co/npm-dl/bl.png?months=6&height=3)](https://nodei.co/npm/bl/)
|
|
||||||
|
|
||||||
**bl** is a storage object for collections of Node Buffers, exposing them with the main Buffer readable API. Also works as a duplex stream so you can collect buffers from a stream that emits them and emit buffers to a stream that consumes them!
|
|
||||||
|
|
||||||
The original buffers are kept intact and copies are only done as necessary. Any reads that require the use of a single original buffer will return a slice of that buffer only (which references the same memory as the original buffer). Reads that span buffers perform concatenation as required and return the results transparently.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const BufferList = require('bl')
|
|
||||||
|
|
||||||
var bl = new BufferList()
|
|
||||||
bl.append(new Buffer('abcd'))
|
|
||||||
bl.append(new Buffer('efg'))
|
|
||||||
bl.append('hi') // bl will also accept & convert Strings
|
|
||||||
bl.append(new Buffer('j'))
|
|
||||||
bl.append(new Buffer([ 0x3, 0x4 ]))
|
|
||||||
|
|
||||||
console.log(bl.length) // 12
|
|
||||||
|
|
||||||
console.log(bl.slice(0, 10).toString('ascii')) // 'abcdefghij'
|
|
||||||
console.log(bl.slice(3, 10).toString('ascii')) // 'defghij'
|
|
||||||
console.log(bl.slice(3, 6).toString('ascii')) // 'def'
|
|
||||||
console.log(bl.slice(3, 8).toString('ascii')) // 'defgh'
|
|
||||||
console.log(bl.slice(5, 10).toString('ascii')) // 'fghij'
|
|
||||||
|
|
||||||
// or just use toString!
|
|
||||||
console.log(bl.toString()) // 'abcdefghij\u0003\u0004'
|
|
||||||
console.log(bl.toString('ascii', 3, 8)) // 'defgh'
|
|
||||||
console.log(bl.toString('ascii', 5, 10)) // 'fghij'
|
|
||||||
|
|
||||||
// other standard Buffer readables
|
|
||||||
console.log(bl.readUInt16BE(10)) // 0x0304
|
|
||||||
console.log(bl.readUInt16LE(10)) // 0x0403
|
|
||||||
```
|
|
||||||
|
|
||||||
Give it a callback in the constructor and use it just like **[concat-stream](https://github.com/maxogden/node-concat-stream)**:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const bl = require('bl')
|
|
||||||
, fs = require('fs')
|
|
||||||
|
|
||||||
fs.createReadStream('README.md')
|
|
||||||
.pipe(bl(function (err, data) { // note 'new' isn't strictly required
|
|
||||||
// `data` is a complete Buffer object containing the full data
|
|
||||||
console.log(data.toString())
|
|
||||||
}))
|
|
||||||
```
|
|
||||||
|
|
||||||
Note that when you use the *callback* method like this, the resulting `data` parameter is a concatenation of all `Buffer` objects in the list. If you want to avoid the overhead of this concatenation (in cases of extreme performance consciousness), then avoid the *callback* method and just listen to `'end'` instead, like a standard Stream.
|
|
||||||
|
|
||||||
Or to fetch a URL using [hyperquest](https://github.com/substack/hyperquest) (should work with [request](http://github.com/mikeal/request) and even plain Node http too!):
|
|
||||||
```js
|
|
||||||
const hyperquest = require('hyperquest')
|
|
||||||
, bl = require('bl')
|
|
||||||
, url = 'https://raw.github.com/rvagg/bl/master/README.md'
|
|
||||||
|
|
||||||
hyperquest(url).pipe(bl(function (err, data) {
|
|
||||||
console.log(data.toString())
|
|
||||||
}))
|
|
||||||
```
|
|
||||||
|
|
||||||
Or, use it as a readable stream to recompose a list of Buffers to an output source:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const BufferList = require('bl')
|
|
||||||
, fs = require('fs')
|
|
||||||
|
|
||||||
var bl = new BufferList()
|
|
||||||
bl.append(new Buffer('abcd'))
|
|
||||||
bl.append(new Buffer('efg'))
|
|
||||||
bl.append(new Buffer('hi'))
|
|
||||||
bl.append(new Buffer('j'))
|
|
||||||
|
|
||||||
bl.pipe(fs.createWriteStream('gibberish.txt'))
|
|
||||||
```
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
* <a href="#ctor"><code><b>new BufferList([ callback ])</b></code></a>
|
|
||||||
* <a href="#length"><code>bl.<b>length</b></code></a>
|
|
||||||
* <a href="#append"><code>bl.<b>append(buffer)</b></code></a>
|
|
||||||
* <a href="#get"><code>bl.<b>get(index)</b></code></a>
|
|
||||||
* <a href="#slice"><code>bl.<b>slice([ start[, end ] ])</b></code></a>
|
|
||||||
* <a href="#shallowSlice"><code>bl.<b>shallowSlice([ start[, end ] ])</b></code></a>
|
|
||||||
* <a href="#copy"><code>bl.<b>copy(dest, [ destStart, [ srcStart [, srcEnd ] ] ])</b></code></a>
|
|
||||||
* <a href="#duplicate"><code>bl.<b>duplicate()</b></code></a>
|
|
||||||
* <a href="#consume"><code>bl.<b>consume(bytes)</b></code></a>
|
|
||||||
* <a href="#toString"><code>bl.<b>toString([encoding, [ start, [ end ]]])</b></code></a>
|
|
||||||
* <a href="#readXX"><code>bl.<b>readDoubleBE()</b></code>, <code>bl.<b>readDoubleLE()</b></code>, <code>bl.<b>readFloatBE()</b></code>, <code>bl.<b>readFloatLE()</b></code>, <code>bl.<b>readInt32BE()</b></code>, <code>bl.<b>readInt32LE()</b></code>, <code>bl.<b>readUInt32BE()</b></code>, <code>bl.<b>readUInt32LE()</b></code>, <code>bl.<b>readInt16BE()</b></code>, <code>bl.<b>readInt16LE()</b></code>, <code>bl.<b>readUInt16BE()</b></code>, <code>bl.<b>readUInt16LE()</b></code>, <code>bl.<b>readInt8()</b></code>, <code>bl.<b>readUInt8()</b></code></a>
|
|
||||||
* <a href="#streams">Streams</a>
|
|
||||||
|
|
||||||
--------------------------------------------------------
|
|
||||||
<a name="ctor"></a>
|
|
||||||
### new BufferList([ callback | Buffer | Buffer array | BufferList | BufferList array | String ])
|
|
||||||
The constructor takes an optional callback, if supplied, the callback will be called with an error argument followed by a reference to the **bl** instance, when `bl.end()` is called (i.e. from a piped stream). This is a convenient method of collecting the entire contents of a stream, particularly when the stream is *chunky*, such as a network stream.
|
|
||||||
|
|
||||||
Normally, no arguments are required for the constructor, but you can initialise the list by passing in a single `Buffer` object or an array of `Buffer` object.
|
|
||||||
|
|
||||||
`new` is not strictly required, if you don't instantiate a new object, it will be done automatically for you so you can create a new instance simply with:
|
|
||||||
|
|
||||||
```js
|
|
||||||
var bl = require('bl')
|
|
||||||
var myinstance = bl()
|
|
||||||
|
|
||||||
// equivalent to:
|
|
||||||
|
|
||||||
var BufferList = require('bl')
|
|
||||||
var myinstance = new BufferList()
|
|
||||||
```
|
|
||||||
|
|
||||||
--------------------------------------------------------
|
|
||||||
<a name="length"></a>
|
|
||||||
### bl.length
|
|
||||||
Get the length of the list in bytes. This is the sum of the lengths of all of the buffers contained in the list, minus any initial offset for a semi-consumed buffer at the beginning. Should accurately represent the total number of bytes that can be read from the list.
|
|
||||||
|
|
||||||
--------------------------------------------------------
|
|
||||||
<a name="append"></a>
|
|
||||||
### bl.append(Buffer | Buffer array | BufferList | BufferList array | String)
|
|
||||||
`append(buffer)` adds an additional buffer or BufferList to the internal list. `this` is returned so it can be chained.
|
|
||||||
|
|
||||||
--------------------------------------------------------
|
|
||||||
<a name="get"></a>
|
|
||||||
### bl.get(index)
|
|
||||||
`get()` will return the byte at the specified index.
|
|
||||||
|
|
||||||
--------------------------------------------------------
|
|
||||||
<a name="slice"></a>
|
|
||||||
### bl.slice([ start, [ end ] ])
|
|
||||||
`slice()` returns a new `Buffer` object containing the bytes within the range specified. Both `start` and `end` are optional and will default to the beginning and end of the list respectively.
|
|
||||||
|
|
||||||
If the requested range spans a single internal buffer then a slice of that buffer will be returned which shares the original memory range of that Buffer. If the range spans multiple buffers then copy operations will likely occur to give you a uniform Buffer.
|
|
||||||
|
|
||||||
--------------------------------------------------------
|
|
||||||
<a name="shallowSlice"></a>
|
|
||||||
### bl.shallowSlice([ start, [ end ] ])
|
|
||||||
`shallowSlice()` returns a new `BufferList` object containing the bytes within the range specified. Both `start` and `end` are optional and will default to the beginning and end of the list respectively.
|
|
||||||
|
|
||||||
No copies will be performed. All buffers in the result share memory with the original list.
|
|
||||||
|
|
||||||
--------------------------------------------------------
|
|
||||||
<a name="copy"></a>
|
|
||||||
### bl.copy(dest, [ destStart, [ srcStart [, srcEnd ] ] ])
|
|
||||||
`copy()` copies the content of the list in the `dest` buffer, starting from `destStart` and containing the bytes within the range specified with `srcStart` to `srcEnd`. `destStart`, `start` and `end` are optional and will default to the beginning of the `dest` buffer, and the beginning and end of the list respectively.
|
|
||||||
|
|
||||||
--------------------------------------------------------
|
|
||||||
<a name="duplicate"></a>
|
|
||||||
### bl.duplicate()
|
|
||||||
`duplicate()` performs a **shallow-copy** of the list. The internal Buffers remains the same, so if you change the underlying Buffers, the change will be reflected in both the original and the duplicate. This method is needed if you want to call `consume()` or `pipe()` and still keep the original list.Example:
|
|
||||||
|
|
||||||
```js
|
|
||||||
var bl = new BufferList()
|
|
||||||
|
|
||||||
bl.append('hello')
|
|
||||||
bl.append(' world')
|
|
||||||
bl.append('\n')
|
|
||||||
|
|
||||||
bl.duplicate().pipe(process.stdout, { end: false })
|
|
||||||
|
|
||||||
console.log(bl.toString())
|
|
||||||
```
|
|
||||||
|
|
||||||
--------------------------------------------------------
|
|
||||||
<a name="consume"></a>
|
|
||||||
### bl.consume(bytes)
|
|
||||||
`consume()` will shift bytes *off the start of the list*. The number of bytes consumed don't need to line up with the sizes of the internal Buffers—initial offsets will be calculated accordingly in order to give you a consistent view of the data.
|
|
||||||
|
|
||||||
--------------------------------------------------------
|
|
||||||
<a name="toString"></a>
|
|
||||||
### bl.toString([encoding, [ start, [ end ]]])
|
|
||||||
`toString()` will return a string representation of the buffer. The optional `start` and `end` arguments are passed on to `slice()`, while the `encoding` is passed on to `toString()` of the resulting Buffer. See the [Buffer#toString()](http://nodejs.org/docs/latest/api/buffer.html#buffer_buf_tostring_encoding_start_end) documentation for more information.
|
|
||||||
|
|
||||||
--------------------------------------------------------
|
|
||||||
<a name="readXX"></a>
|
|
||||||
### bl.readDoubleBE(), bl.readDoubleLE(), bl.readFloatBE(), bl.readFloatLE(), bl.readInt32BE(), bl.readInt32LE(), bl.readUInt32BE(), bl.readUInt32LE(), bl.readInt16BE(), bl.readInt16LE(), bl.readUInt16BE(), bl.readUInt16LE(), bl.readInt8(), bl.readUInt8()
|
|
||||||
|
|
||||||
All of the standard byte-reading methods of the `Buffer` interface are implemented and will operate across internal Buffer boundaries transparently.
|
|
||||||
|
|
||||||
See the <b><code>[Buffer](http://nodejs.org/docs/latest/api/buffer.html)</code></b> documentation for how these work.
|
|
||||||
|
|
||||||
--------------------------------------------------------
|
|
||||||
<a name="streams"></a>
|
|
||||||
### Streams
|
|
||||||
**bl** is a Node **[Duplex Stream](http://nodejs.org/docs/latest/api/stream.html#stream_class_stream_duplex)**, so it can be read from and written to like a standard Node stream. You can also `pipe()` to and from a **bl** instance.
|
|
||||||
|
|
||||||
--------------------------------------------------------
|
|
||||||
|
|
||||||
## Contributors
|
|
||||||
|
|
||||||
**bl** is brought to you by the following hackers:
|
|
||||||
|
|
||||||
* [Rod Vagg](https://github.com/rvagg)
|
|
||||||
* [Matteo Collina](https://github.com/mcollina)
|
|
||||||
* [Jarett Cruger](https://github.com/jcrugzz)
|
|
||||||
|
|
||||||
=======
|
|
||||||
|
|
||||||
<a name="license"></a>
|
|
||||||
## License & copyright
|
|
||||||
|
|
||||||
Copyright (c) 2013-2016 bl contributors (listed above).
|
|
||||||
|
|
||||||
bl is licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details.
|
|
@ -1,281 +0,0 @@
|
|||||||
var DuplexStream = require('readable-stream/duplex')
|
|
||||||
, util = require('util')
|
|
||||||
, Buffer = require('safe-buffer').Buffer
|
|
||||||
|
|
||||||
|
|
||||||
function BufferList (callback) {
|
|
||||||
if (!(this instanceof BufferList))
|
|
||||||
return new BufferList(callback)
|
|
||||||
|
|
||||||
this._bufs = []
|
|
||||||
this.length = 0
|
|
||||||
|
|
||||||
if (typeof callback == 'function') {
|
|
||||||
this._callback = callback
|
|
||||||
|
|
||||||
var piper = function piper (err) {
|
|
||||||
if (this._callback) {
|
|
||||||
this._callback(err)
|
|
||||||
this._callback = null
|
|
||||||
}
|
|
||||||
}.bind(this)
|
|
||||||
|
|
||||||
this.on('pipe', function onPipe (src) {
|
|
||||||
src.on('error', piper)
|
|
||||||
})
|
|
||||||
this.on('unpipe', function onUnpipe (src) {
|
|
||||||
src.removeListener('error', piper)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
this.append(callback)
|
|
||||||
}
|
|
||||||
|
|
||||||
DuplexStream.call(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
util.inherits(BufferList, DuplexStream)
|
|
||||||
|
|
||||||
|
|
||||||
BufferList.prototype._offset = function _offset (offset) {
|
|
||||||
var tot = 0, i = 0, _t
|
|
||||||
if (offset === 0) return [ 0, 0 ]
|
|
||||||
for (; i < this._bufs.length; i++) {
|
|
||||||
_t = tot + this._bufs[i].length
|
|
||||||
if (offset < _t || i == this._bufs.length - 1)
|
|
||||||
return [ i, offset - tot ]
|
|
||||||
tot = _t
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BufferList.prototype.append = function append (buf) {
|
|
||||||
var i = 0
|
|
||||||
|
|
||||||
if (Buffer.isBuffer(buf)) {
|
|
||||||
this._appendBuffer(buf);
|
|
||||||
} else if (Array.isArray(buf)) {
|
|
||||||
for (; i < buf.length; i++)
|
|
||||||
this.append(buf[i])
|
|
||||||
} else if (buf instanceof BufferList) {
|
|
||||||
// unwrap argument into individual BufferLists
|
|
||||||
for (; i < buf._bufs.length; i++)
|
|
||||||
this.append(buf._bufs[i])
|
|
||||||
} else if (buf != null) {
|
|
||||||
// coerce number arguments to strings, since Buffer(number) does
|
|
||||||
// uninitialized memory allocation
|
|
||||||
if (typeof buf == 'number')
|
|
||||||
buf = buf.toString()
|
|
||||||
|
|
||||||
this._appendBuffer(Buffer.from(buf));
|
|
||||||
}
|
|
||||||
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BufferList.prototype._appendBuffer = function appendBuffer (buf) {
|
|
||||||
this._bufs.push(buf)
|
|
||||||
this.length += buf.length
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BufferList.prototype._write = function _write (buf, encoding, callback) {
|
|
||||||
this._appendBuffer(buf)
|
|
||||||
|
|
||||||
if (typeof callback == 'function')
|
|
||||||
callback()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BufferList.prototype._read = function _read (size) {
|
|
||||||
if (!this.length)
|
|
||||||
return this.push(null)
|
|
||||||
|
|
||||||
size = Math.min(size, this.length)
|
|
||||||
this.push(this.slice(0, size))
|
|
||||||
this.consume(size)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BufferList.prototype.end = function end (chunk) {
|
|
||||||
DuplexStream.prototype.end.call(this, chunk)
|
|
||||||
|
|
||||||
if (this._callback) {
|
|
||||||
this._callback(null, this.slice())
|
|
||||||
this._callback = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BufferList.prototype.get = function get (index) {
|
|
||||||
return this.slice(index, index + 1)[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BufferList.prototype.slice = function slice (start, end) {
|
|
||||||
if (typeof start == 'number' && start < 0)
|
|
||||||
start += this.length
|
|
||||||
if (typeof end == 'number' && end < 0)
|
|
||||||
end += this.length
|
|
||||||
return this.copy(null, 0, start, end)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) {
|
|
||||||
if (typeof srcStart != 'number' || srcStart < 0)
|
|
||||||
srcStart = 0
|
|
||||||
if (typeof srcEnd != 'number' || srcEnd > this.length)
|
|
||||||
srcEnd = this.length
|
|
||||||
if (srcStart >= this.length)
|
|
||||||
return dst || Buffer.alloc(0)
|
|
||||||
if (srcEnd <= 0)
|
|
||||||
return dst || Buffer.alloc(0)
|
|
||||||
|
|
||||||
var copy = !!dst
|
|
||||||
, off = this._offset(srcStart)
|
|
||||||
, len = srcEnd - srcStart
|
|
||||||
, bytes = len
|
|
||||||
, bufoff = (copy && dstStart) || 0
|
|
||||||
, start = off[1]
|
|
||||||
, l
|
|
||||||
, i
|
|
||||||
|
|
||||||
// copy/slice everything
|
|
||||||
if (srcStart === 0 && srcEnd == this.length) {
|
|
||||||
if (!copy) { // slice, but full concat if multiple buffers
|
|
||||||
return this._bufs.length === 1
|
|
||||||
? this._bufs[0]
|
|
||||||
: Buffer.concat(this._bufs, this.length)
|
|
||||||
}
|
|
||||||
|
|
||||||
// copy, need to copy individual buffers
|
|
||||||
for (i = 0; i < this._bufs.length; i++) {
|
|
||||||
this._bufs[i].copy(dst, bufoff)
|
|
||||||
bufoff += this._bufs[i].length
|
|
||||||
}
|
|
||||||
|
|
||||||
return dst
|
|
||||||
}
|
|
||||||
|
|
||||||
// easy, cheap case where it's a subset of one of the buffers
|
|
||||||
if (bytes <= this._bufs[off[0]].length - start) {
|
|
||||||
return copy
|
|
||||||
? this._bufs[off[0]].copy(dst, dstStart, start, start + bytes)
|
|
||||||
: this._bufs[off[0]].slice(start, start + bytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!copy) // a slice, we need something to copy in to
|
|
||||||
dst = Buffer.allocUnsafe(len)
|
|
||||||
|
|
||||||
for (i = off[0]; i < this._bufs.length; i++) {
|
|
||||||
l = this._bufs[i].length - start
|
|
||||||
|
|
||||||
if (bytes > l) {
|
|
||||||
this._bufs[i].copy(dst, bufoff, start)
|
|
||||||
} else {
|
|
||||||
this._bufs[i].copy(dst, bufoff, start, start + bytes)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
bufoff += l
|
|
||||||
bytes -= l
|
|
||||||
|
|
||||||
if (start)
|
|
||||||
start = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
return dst
|
|
||||||
}
|
|
||||||
|
|
||||||
BufferList.prototype.shallowSlice = function shallowSlice (start, end) {
|
|
||||||
start = start || 0
|
|
||||||
end = end || this.length
|
|
||||||
|
|
||||||
if (start < 0)
|
|
||||||
start += this.length
|
|
||||||
if (end < 0)
|
|
||||||
end += this.length
|
|
||||||
|
|
||||||
var startOffset = this._offset(start)
|
|
||||||
, endOffset = this._offset(end)
|
|
||||||
, buffers = this._bufs.slice(startOffset[0], endOffset[0] + 1)
|
|
||||||
|
|
||||||
if (endOffset[1] == 0)
|
|
||||||
buffers.pop()
|
|
||||||
else
|
|
||||||
buffers[buffers.length-1] = buffers[buffers.length-1].slice(0, endOffset[1])
|
|
||||||
|
|
||||||
if (startOffset[1] != 0)
|
|
||||||
buffers[0] = buffers[0].slice(startOffset[1])
|
|
||||||
|
|
||||||
return new BufferList(buffers)
|
|
||||||
}
|
|
||||||
|
|
||||||
BufferList.prototype.toString = function toString (encoding, start, end) {
|
|
||||||
return this.slice(start, end).toString(encoding)
|
|
||||||
}
|
|
||||||
|
|
||||||
BufferList.prototype.consume = function consume (bytes) {
|
|
||||||
while (this._bufs.length) {
|
|
||||||
if (bytes >= this._bufs[0].length) {
|
|
||||||
bytes -= this._bufs[0].length
|
|
||||||
this.length -= this._bufs[0].length
|
|
||||||
this._bufs.shift()
|
|
||||||
} else {
|
|
||||||
this._bufs[0] = this._bufs[0].slice(bytes)
|
|
||||||
this.length -= bytes
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BufferList.prototype.duplicate = function duplicate () {
|
|
||||||
var i = 0
|
|
||||||
, copy = new BufferList()
|
|
||||||
|
|
||||||
for (; i < this._bufs.length; i++)
|
|
||||||
copy.append(this._bufs[i])
|
|
||||||
|
|
||||||
return copy
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BufferList.prototype.destroy = function destroy () {
|
|
||||||
this._bufs.length = 0
|
|
||||||
this.length = 0
|
|
||||||
this.push(null)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
;(function () {
|
|
||||||
var methods = {
|
|
||||||
'readDoubleBE' : 8
|
|
||||||
, 'readDoubleLE' : 8
|
|
||||||
, 'readFloatBE' : 4
|
|
||||||
, 'readFloatLE' : 4
|
|
||||||
, 'readInt32BE' : 4
|
|
||||||
, 'readInt32LE' : 4
|
|
||||||
, 'readUInt32BE' : 4
|
|
||||||
, 'readUInt32LE' : 4
|
|
||||||
, 'readInt16BE' : 2
|
|
||||||
, 'readInt16LE' : 2
|
|
||||||
, 'readUInt16BE' : 2
|
|
||||||
, 'readUInt16LE' : 2
|
|
||||||
, 'readInt8' : 1
|
|
||||||
, 'readUInt8' : 1
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var m in methods) {
|
|
||||||
(function (m) {
|
|
||||||
BufferList.prototype[m] = function (offset) {
|
|
||||||
return this.slice(offset, offset + methods[m])[m](0)
|
|
||||||
}
|
|
||||||
}(m))
|
|
||||||
}
|
|
||||||
}())
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = BufferList
|
|
@ -1,702 +0,0 @@
|
|||||||
var tape = require('tape')
|
|
||||||
, crypto = require('crypto')
|
|
||||||
, fs = require('fs')
|
|
||||||
, hash = require('hash_file')
|
|
||||||
, BufferList = require('../')
|
|
||||||
, Buffer = require('safe-buffer').Buffer
|
|
||||||
|
|
||||||
, encodings =
|
|
||||||
('hex utf8 utf-8 ascii binary base64'
|
|
||||||
+ (process.browser ? '' : ' ucs2 ucs-2 utf16le utf-16le')).split(' ')
|
|
||||||
|
|
||||||
tape('single bytes from single buffer', function (t) {
|
|
||||||
var bl = new BufferList()
|
|
||||||
bl.append(Buffer.from('abcd'))
|
|
||||||
|
|
||||||
t.equal(bl.length, 4)
|
|
||||||
|
|
||||||
t.equal(bl.get(0), 97)
|
|
||||||
t.equal(bl.get(1), 98)
|
|
||||||
t.equal(bl.get(2), 99)
|
|
||||||
t.equal(bl.get(3), 100)
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('single bytes from multiple buffers', function (t) {
|
|
||||||
var bl = new BufferList()
|
|
||||||
bl.append(Buffer.from('abcd'))
|
|
||||||
bl.append(Buffer.from('efg'))
|
|
||||||
bl.append(Buffer.from('hi'))
|
|
||||||
bl.append(Buffer.from('j'))
|
|
||||||
|
|
||||||
t.equal(bl.length, 10)
|
|
||||||
|
|
||||||
t.equal(bl.get(0), 97)
|
|
||||||
t.equal(bl.get(1), 98)
|
|
||||||
t.equal(bl.get(2), 99)
|
|
||||||
t.equal(bl.get(3), 100)
|
|
||||||
t.equal(bl.get(4), 101)
|
|
||||||
t.equal(bl.get(5), 102)
|
|
||||||
t.equal(bl.get(6), 103)
|
|
||||||
t.equal(bl.get(7), 104)
|
|
||||||
t.equal(bl.get(8), 105)
|
|
||||||
t.equal(bl.get(9), 106)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('multi bytes from single buffer', function (t) {
|
|
||||||
var bl = new BufferList()
|
|
||||||
bl.append(Buffer.from('abcd'))
|
|
||||||
|
|
||||||
t.equal(bl.length, 4)
|
|
||||||
|
|
||||||
t.equal(bl.slice(0, 4).toString('ascii'), 'abcd')
|
|
||||||
t.equal(bl.slice(0, 3).toString('ascii'), 'abc')
|
|
||||||
t.equal(bl.slice(1, 4).toString('ascii'), 'bcd')
|
|
||||||
t.equal(bl.slice(-4, -1).toString('ascii'), 'abc')
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('multi bytes from single buffer (negative indexes)', function (t) {
|
|
||||||
var bl = new BufferList()
|
|
||||||
bl.append(Buffer.from('buffer'))
|
|
||||||
|
|
||||||
t.equal(bl.length, 6)
|
|
||||||
|
|
||||||
t.equal(bl.slice(-6, -1).toString('ascii'), 'buffe')
|
|
||||||
t.equal(bl.slice(-6, -2).toString('ascii'), 'buff')
|
|
||||||
t.equal(bl.slice(-5, -2).toString('ascii'), 'uff')
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('multiple bytes from multiple buffers', function (t) {
|
|
||||||
var bl = new BufferList()
|
|
||||||
|
|
||||||
bl.append(Buffer.from('abcd'))
|
|
||||||
bl.append(Buffer.from('efg'))
|
|
||||||
bl.append(Buffer.from('hi'))
|
|
||||||
bl.append(Buffer.from('j'))
|
|
||||||
|
|
||||||
t.equal(bl.length, 10)
|
|
||||||
|
|
||||||
t.equal(bl.slice(0, 10).toString('ascii'), 'abcdefghij')
|
|
||||||
t.equal(bl.slice(3, 10).toString('ascii'), 'defghij')
|
|
||||||
t.equal(bl.slice(3, 6).toString('ascii'), 'def')
|
|
||||||
t.equal(bl.slice(3, 8).toString('ascii'), 'defgh')
|
|
||||||
t.equal(bl.slice(5, 10).toString('ascii'), 'fghij')
|
|
||||||
t.equal(bl.slice(-7, -4).toString('ascii'), 'def')
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('multiple bytes from multiple buffer lists', function (t) {
|
|
||||||
var bl = new BufferList()
|
|
||||||
|
|
||||||
bl.append(new BufferList([ Buffer.from('abcd'), Buffer.from('efg') ]))
|
|
||||||
bl.append(new BufferList([ Buffer.from('hi'), Buffer.from('j') ]))
|
|
||||||
|
|
||||||
t.equal(bl.length, 10)
|
|
||||||
|
|
||||||
t.equal(bl.slice(0, 10).toString('ascii'), 'abcdefghij')
|
|
||||||
|
|
||||||
t.equal(bl.slice(3, 10).toString('ascii'), 'defghij')
|
|
||||||
t.equal(bl.slice(3, 6).toString('ascii'), 'def')
|
|
||||||
t.equal(bl.slice(3, 8).toString('ascii'), 'defgh')
|
|
||||||
t.equal(bl.slice(5, 10).toString('ascii'), 'fghij')
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
// same data as previous test, just using nested constructors
|
|
||||||
tape('multiple bytes from crazy nested buffer lists', function (t) {
|
|
||||||
var bl = new BufferList()
|
|
||||||
|
|
||||||
bl.append(new BufferList([
|
|
||||||
new BufferList([
|
|
||||||
new BufferList(Buffer.from('abc'))
|
|
||||||
, Buffer.from('d')
|
|
||||||
, new BufferList(Buffer.from('efg'))
|
|
||||||
])
|
|
||||||
, new BufferList([ Buffer.from('hi') ])
|
|
||||||
, new BufferList(Buffer.from('j'))
|
|
||||||
]))
|
|
||||||
|
|
||||||
t.equal(bl.length, 10)
|
|
||||||
|
|
||||||
t.equal(bl.slice(0, 10).toString('ascii'), 'abcdefghij')
|
|
||||||
|
|
||||||
t.equal(bl.slice(3, 10).toString('ascii'), 'defghij')
|
|
||||||
t.equal(bl.slice(3, 6).toString('ascii'), 'def')
|
|
||||||
t.equal(bl.slice(3, 8).toString('ascii'), 'defgh')
|
|
||||||
t.equal(bl.slice(5, 10).toString('ascii'), 'fghij')
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('append accepts arrays of Buffers', function (t) {
|
|
||||||
var bl = new BufferList()
|
|
||||||
bl.append(Buffer.from('abc'))
|
|
||||||
bl.append([ Buffer.from('def') ])
|
|
||||||
bl.append([ Buffer.from('ghi'), Buffer.from('jkl') ])
|
|
||||||
bl.append([ Buffer.from('mnop'), Buffer.from('qrstu'), Buffer.from('vwxyz') ])
|
|
||||||
t.equal(bl.length, 26)
|
|
||||||
t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('append accepts arrays of BufferLists', function (t) {
|
|
||||||
var bl = new BufferList()
|
|
||||||
bl.append(Buffer.from('abc'))
|
|
||||||
bl.append([ new BufferList('def') ])
|
|
||||||
bl.append(new BufferList([ Buffer.from('ghi'), new BufferList('jkl') ]))
|
|
||||||
bl.append([ Buffer.from('mnop'), new BufferList([ Buffer.from('qrstu'), Buffer.from('vwxyz') ]) ])
|
|
||||||
t.equal(bl.length, 26)
|
|
||||||
t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('append chainable', function (t) {
|
|
||||||
var bl = new BufferList()
|
|
||||||
t.ok(bl.append(Buffer.from('abcd')) === bl)
|
|
||||||
t.ok(bl.append([ Buffer.from('abcd') ]) === bl)
|
|
||||||
t.ok(bl.append(new BufferList(Buffer.from('abcd'))) === bl)
|
|
||||||
t.ok(bl.append([ new BufferList(Buffer.from('abcd')) ]) === bl)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('append chainable (test results)', function (t) {
|
|
||||||
var bl = new BufferList('abc')
|
|
||||||
.append([ new BufferList('def') ])
|
|
||||||
.append(new BufferList([ Buffer.from('ghi'), new BufferList('jkl') ]))
|
|
||||||
.append([ Buffer.from('mnop'), new BufferList([ Buffer.from('qrstu'), Buffer.from('vwxyz') ]) ])
|
|
||||||
|
|
||||||
t.equal(bl.length, 26)
|
|
||||||
t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('consuming from multiple buffers', function (t) {
|
|
||||||
var bl = new BufferList()
|
|
||||||
|
|
||||||
bl.append(Buffer.from('abcd'))
|
|
||||||
bl.append(Buffer.from('efg'))
|
|
||||||
bl.append(Buffer.from('hi'))
|
|
||||||
bl.append(Buffer.from('j'))
|
|
||||||
|
|
||||||
t.equal(bl.length, 10)
|
|
||||||
|
|
||||||
t.equal(bl.slice(0, 10).toString('ascii'), 'abcdefghij')
|
|
||||||
|
|
||||||
bl.consume(3)
|
|
||||||
t.equal(bl.length, 7)
|
|
||||||
t.equal(bl.slice(0, 7).toString('ascii'), 'defghij')
|
|
||||||
|
|
||||||
bl.consume(2)
|
|
||||||
t.equal(bl.length, 5)
|
|
||||||
t.equal(bl.slice(0, 5).toString('ascii'), 'fghij')
|
|
||||||
|
|
||||||
bl.consume(1)
|
|
||||||
t.equal(bl.length, 4)
|
|
||||||
t.equal(bl.slice(0, 4).toString('ascii'), 'ghij')
|
|
||||||
|
|
||||||
bl.consume(1)
|
|
||||||
t.equal(bl.length, 3)
|
|
||||||
t.equal(bl.slice(0, 3).toString('ascii'), 'hij')
|
|
||||||
|
|
||||||
bl.consume(2)
|
|
||||||
t.equal(bl.length, 1)
|
|
||||||
t.equal(bl.slice(0, 1).toString('ascii'), 'j')
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('complete consumption', function (t) {
|
|
||||||
var bl = new BufferList()
|
|
||||||
|
|
||||||
bl.append(Buffer.from('a'))
|
|
||||||
bl.append(Buffer.from('b'))
|
|
||||||
|
|
||||||
bl.consume(2)
|
|
||||||
|
|
||||||
t.equal(bl.length, 0)
|
|
||||||
t.equal(bl._bufs.length, 0)
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('test readUInt8 / readInt8', function (t) {
|
|
||||||
var buf1 = Buffer.alloc(1)
|
|
||||||
, buf2 = Buffer.alloc(3)
|
|
||||||
, buf3 = Buffer.alloc(3)
|
|
||||||
, bl = new BufferList()
|
|
||||||
|
|
||||||
buf2[1] = 0x3
|
|
||||||
buf2[2] = 0x4
|
|
||||||
buf3[0] = 0x23
|
|
||||||
buf3[1] = 0x42
|
|
||||||
|
|
||||||
bl.append(buf1)
|
|
||||||
bl.append(buf2)
|
|
||||||
bl.append(buf3)
|
|
||||||
|
|
||||||
t.equal(bl.readUInt8(2), 0x3)
|
|
||||||
t.equal(bl.readInt8(2), 0x3)
|
|
||||||
t.equal(bl.readUInt8(3), 0x4)
|
|
||||||
t.equal(bl.readInt8(3), 0x4)
|
|
||||||
t.equal(bl.readUInt8(4), 0x23)
|
|
||||||
t.equal(bl.readInt8(4), 0x23)
|
|
||||||
t.equal(bl.readUInt8(5), 0x42)
|
|
||||||
t.equal(bl.readInt8(5), 0x42)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('test readUInt16LE / readUInt16BE / readInt16LE / readInt16BE', function (t) {
|
|
||||||
var buf1 = Buffer.alloc(1)
|
|
||||||
, buf2 = Buffer.alloc(3)
|
|
||||||
, buf3 = Buffer.alloc(3)
|
|
||||||
, bl = new BufferList()
|
|
||||||
|
|
||||||
buf2[1] = 0x3
|
|
||||||
buf2[2] = 0x4
|
|
||||||
buf3[0] = 0x23
|
|
||||||
buf3[1] = 0x42
|
|
||||||
|
|
||||||
bl.append(buf1)
|
|
||||||
bl.append(buf2)
|
|
||||||
bl.append(buf3)
|
|
||||||
|
|
||||||
t.equal(bl.readUInt16BE(2), 0x0304)
|
|
||||||
t.equal(bl.readUInt16LE(2), 0x0403)
|
|
||||||
t.equal(bl.readInt16BE(2), 0x0304)
|
|
||||||
t.equal(bl.readInt16LE(2), 0x0403)
|
|
||||||
t.equal(bl.readUInt16BE(3), 0x0423)
|
|
||||||
t.equal(bl.readUInt16LE(3), 0x2304)
|
|
||||||
t.equal(bl.readInt16BE(3), 0x0423)
|
|
||||||
t.equal(bl.readInt16LE(3), 0x2304)
|
|
||||||
t.equal(bl.readUInt16BE(4), 0x2342)
|
|
||||||
t.equal(bl.readUInt16LE(4), 0x4223)
|
|
||||||
t.equal(bl.readInt16BE(4), 0x2342)
|
|
||||||
t.equal(bl.readInt16LE(4), 0x4223)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('test readUInt32LE / readUInt32BE / readInt32LE / readInt32BE', function (t) {
|
|
||||||
var buf1 = Buffer.alloc(1)
|
|
||||||
, buf2 = Buffer.alloc(3)
|
|
||||||
, buf3 = Buffer.alloc(3)
|
|
||||||
, bl = new BufferList()
|
|
||||||
|
|
||||||
buf2[1] = 0x3
|
|
||||||
buf2[2] = 0x4
|
|
||||||
buf3[0] = 0x23
|
|
||||||
buf3[1] = 0x42
|
|
||||||
|
|
||||||
bl.append(buf1)
|
|
||||||
bl.append(buf2)
|
|
||||||
bl.append(buf3)
|
|
||||||
|
|
||||||
t.equal(bl.readUInt32BE(2), 0x03042342)
|
|
||||||
t.equal(bl.readUInt32LE(2), 0x42230403)
|
|
||||||
t.equal(bl.readInt32BE(2), 0x03042342)
|
|
||||||
t.equal(bl.readInt32LE(2), 0x42230403)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('test readFloatLE / readFloatBE', function (t) {
|
|
||||||
var buf1 = Buffer.alloc(1)
|
|
||||||
, buf2 = Buffer.alloc(3)
|
|
||||||
, buf3 = Buffer.alloc(3)
|
|
||||||
, bl = new BufferList()
|
|
||||||
|
|
||||||
buf2[1] = 0x00
|
|
||||||
buf2[2] = 0x00
|
|
||||||
buf3[0] = 0x80
|
|
||||||
buf3[1] = 0x3f
|
|
||||||
|
|
||||||
bl.append(buf1)
|
|
||||||
bl.append(buf2)
|
|
||||||
bl.append(buf3)
|
|
||||||
|
|
||||||
t.equal(bl.readFloatLE(2), 0x01)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('test readDoubleLE / readDoubleBE', function (t) {
|
|
||||||
var buf1 = Buffer.alloc(1)
|
|
||||||
, buf2 = Buffer.alloc(3)
|
|
||||||
, buf3 = Buffer.alloc(10)
|
|
||||||
, bl = new BufferList()
|
|
||||||
|
|
||||||
buf2[1] = 0x55
|
|
||||||
buf2[2] = 0x55
|
|
||||||
buf3[0] = 0x55
|
|
||||||
buf3[1] = 0x55
|
|
||||||
buf3[2] = 0x55
|
|
||||||
buf3[3] = 0x55
|
|
||||||
buf3[4] = 0xd5
|
|
||||||
buf3[5] = 0x3f
|
|
||||||
|
|
||||||
bl.append(buf1)
|
|
||||||
bl.append(buf2)
|
|
||||||
bl.append(buf3)
|
|
||||||
|
|
||||||
t.equal(bl.readDoubleLE(2), 0.3333333333333333)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('test toString', function (t) {
|
|
||||||
var bl = new BufferList()
|
|
||||||
|
|
||||||
bl.append(Buffer.from('abcd'))
|
|
||||||
bl.append(Buffer.from('efg'))
|
|
||||||
bl.append(Buffer.from('hi'))
|
|
||||||
bl.append(Buffer.from('j'))
|
|
||||||
|
|
||||||
t.equal(bl.toString('ascii', 0, 10), 'abcdefghij')
|
|
||||||
t.equal(bl.toString('ascii', 3, 10), 'defghij')
|
|
||||||
t.equal(bl.toString('ascii', 3, 6), 'def')
|
|
||||||
t.equal(bl.toString('ascii', 3, 8), 'defgh')
|
|
||||||
t.equal(bl.toString('ascii', 5, 10), 'fghij')
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('test toString encoding', function (t) {
|
|
||||||
var bl = new BufferList()
|
|
||||||
, b = Buffer.from('abcdefghij\xff\x00')
|
|
||||||
|
|
||||||
bl.append(Buffer.from('abcd'))
|
|
||||||
bl.append(Buffer.from('efg'))
|
|
||||||
bl.append(Buffer.from('hi'))
|
|
||||||
bl.append(Buffer.from('j'))
|
|
||||||
bl.append(Buffer.from('\xff\x00'))
|
|
||||||
|
|
||||||
encodings.forEach(function (enc) {
|
|
||||||
t.equal(bl.toString(enc), b.toString(enc), enc)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
!process.browser && tape('test stream', function (t) {
|
|
||||||
var random = crypto.randomBytes(65534)
|
|
||||||
, rndhash = hash(random, 'md5')
|
|
||||||
, md5sum = crypto.createHash('md5')
|
|
||||||
, bl = new BufferList(function (err, buf) {
|
|
||||||
t.ok(Buffer.isBuffer(buf))
|
|
||||||
t.ok(err === null)
|
|
||||||
t.equal(rndhash, hash(bl.slice(), 'md5'))
|
|
||||||
t.equal(rndhash, hash(buf, 'md5'))
|
|
||||||
|
|
||||||
bl.pipe(fs.createWriteStream('/tmp/bl_test_rnd_out.dat'))
|
|
||||||
.on('close', function () {
|
|
||||||
var s = fs.createReadStream('/tmp/bl_test_rnd_out.dat')
|
|
||||||
s.on('data', md5sum.update.bind(md5sum))
|
|
||||||
s.on('end', function() {
|
|
||||||
t.equal(rndhash, md5sum.digest('hex'), 'woohoo! correct hash!')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
fs.writeFileSync('/tmp/bl_test_rnd.dat', random)
|
|
||||||
fs.createReadStream('/tmp/bl_test_rnd.dat').pipe(bl)
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('instantiation with Buffer', function (t) {
|
|
||||||
var buf = crypto.randomBytes(1024)
|
|
||||||
, buf2 = crypto.randomBytes(1024)
|
|
||||||
, b = BufferList(buf)
|
|
||||||
|
|
||||||
t.equal(buf.toString('hex'), b.slice().toString('hex'), 'same buffer')
|
|
||||||
b = BufferList([ buf, buf2 ])
|
|
||||||
t.equal(b.slice().toString('hex'), Buffer.concat([ buf, buf2 ]).toString('hex'), 'same buffer')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('test String appendage', function (t) {
|
|
||||||
var bl = new BufferList()
|
|
||||||
, b = Buffer.from('abcdefghij\xff\x00')
|
|
||||||
|
|
||||||
bl.append('abcd')
|
|
||||||
bl.append('efg')
|
|
||||||
bl.append('hi')
|
|
||||||
bl.append('j')
|
|
||||||
bl.append('\xff\x00')
|
|
||||||
|
|
||||||
encodings.forEach(function (enc) {
|
|
||||||
t.equal(bl.toString(enc), b.toString(enc))
|
|
||||||
})
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('test Number appendage', function (t) {
|
|
||||||
var bl = new BufferList()
|
|
||||||
, b = Buffer.from('1234567890')
|
|
||||||
|
|
||||||
bl.append(1234)
|
|
||||||
bl.append(567)
|
|
||||||
bl.append(89)
|
|
||||||
bl.append(0)
|
|
||||||
|
|
||||||
encodings.forEach(function (enc) {
|
|
||||||
t.equal(bl.toString(enc), b.toString(enc))
|
|
||||||
})
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('write nothing, should get empty buffer', function (t) {
|
|
||||||
t.plan(3)
|
|
||||||
BufferList(function (err, data) {
|
|
||||||
t.notOk(err, 'no error')
|
|
||||||
t.ok(Buffer.isBuffer(data), 'got a buffer')
|
|
||||||
t.equal(0, data.length, 'got a zero-length buffer')
|
|
||||||
t.end()
|
|
||||||
}).end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('unicode string', function (t) {
|
|
||||||
t.plan(2)
|
|
||||||
var inp1 = '\u2600'
|
|
||||||
, inp2 = '\u2603'
|
|
||||||
, exp = inp1 + ' and ' + inp2
|
|
||||||
, bl = BufferList()
|
|
||||||
bl.write(inp1)
|
|
||||||
bl.write(' and ')
|
|
||||||
bl.write(inp2)
|
|
||||||
t.equal(exp, bl.toString())
|
|
||||||
t.equal(Buffer.from(exp).toString('hex'), bl.toString('hex'))
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('should emit finish', function (t) {
|
|
||||||
var source = BufferList()
|
|
||||||
, dest = BufferList()
|
|
||||||
|
|
||||||
source.write('hello')
|
|
||||||
source.pipe(dest)
|
|
||||||
|
|
||||||
dest.on('finish', function () {
|
|
||||||
t.equal(dest.toString('utf8'), 'hello')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('basic copy', function (t) {
|
|
||||||
var buf = crypto.randomBytes(1024)
|
|
||||||
, buf2 = Buffer.alloc(1024)
|
|
||||||
, b = BufferList(buf)
|
|
||||||
|
|
||||||
b.copy(buf2)
|
|
||||||
t.equal(b.slice().toString('hex'), buf2.toString('hex'), 'same buffer')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('copy after many appends', function (t) {
|
|
||||||
var buf = crypto.randomBytes(512)
|
|
||||||
, buf2 = Buffer.alloc(1024)
|
|
||||||
, b = BufferList(buf)
|
|
||||||
|
|
||||||
b.append(buf)
|
|
||||||
b.copy(buf2)
|
|
||||||
t.equal(b.slice().toString('hex'), buf2.toString('hex'), 'same buffer')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('copy at a precise position', function (t) {
|
|
||||||
var buf = crypto.randomBytes(1004)
|
|
||||||
, buf2 = Buffer.alloc(1024)
|
|
||||||
, b = BufferList(buf)
|
|
||||||
|
|
||||||
b.copy(buf2, 20)
|
|
||||||
t.equal(b.slice().toString('hex'), buf2.slice(20).toString('hex'), 'same buffer')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('copy starting from a precise location', function (t) {
|
|
||||||
var buf = crypto.randomBytes(10)
|
|
||||||
, buf2 = Buffer.alloc(5)
|
|
||||||
, b = BufferList(buf)
|
|
||||||
|
|
||||||
b.copy(buf2, 0, 5)
|
|
||||||
t.equal(b.slice(5).toString('hex'), buf2.toString('hex'), 'same buffer')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('copy in an interval', function (t) {
|
|
||||||
var rnd = crypto.randomBytes(10)
|
|
||||||
, b = BufferList(rnd) // put the random bytes there
|
|
||||||
, actual = Buffer.alloc(3)
|
|
||||||
, expected = Buffer.alloc(3)
|
|
||||||
|
|
||||||
rnd.copy(expected, 0, 5, 8)
|
|
||||||
b.copy(actual, 0, 5, 8)
|
|
||||||
|
|
||||||
t.equal(actual.toString('hex'), expected.toString('hex'), 'same buffer')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('copy an interval between two buffers', function (t) {
|
|
||||||
var buf = crypto.randomBytes(10)
|
|
||||||
, buf2 = Buffer.alloc(10)
|
|
||||||
, b = BufferList(buf)
|
|
||||||
|
|
||||||
b.append(buf)
|
|
||||||
b.copy(buf2, 0, 5, 15)
|
|
||||||
|
|
||||||
t.equal(b.slice(5, 15).toString('hex'), buf2.toString('hex'), 'same buffer')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('shallow slice across buffer boundaries', function (t) {
|
|
||||||
var bl = new BufferList(['First', 'Second', 'Third'])
|
|
||||||
|
|
||||||
t.equal(bl.shallowSlice(3, 13).toString(), 'stSecondTh')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('shallow slice within single buffer', function (t) {
|
|
||||||
t.plan(2)
|
|
||||||
var bl = new BufferList(['First', 'Second', 'Third'])
|
|
||||||
|
|
||||||
t.equal(bl.shallowSlice(5, 10).toString(), 'Secon')
|
|
||||||
t.equal(bl.shallowSlice(7, 10).toString(), 'con')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('shallow slice single buffer', function (t) {
|
|
||||||
t.plan(3)
|
|
||||||
var bl = new BufferList(['First', 'Second', 'Third'])
|
|
||||||
|
|
||||||
t.equal(bl.shallowSlice(0, 5).toString(), 'First')
|
|
||||||
t.equal(bl.shallowSlice(5, 11).toString(), 'Second')
|
|
||||||
t.equal(bl.shallowSlice(11, 16).toString(), 'Third')
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('shallow slice with negative or omitted indices', function (t) {
|
|
||||||
t.plan(4)
|
|
||||||
var bl = new BufferList(['First', 'Second', 'Third'])
|
|
||||||
|
|
||||||
t.equal(bl.shallowSlice().toString(), 'FirstSecondThird')
|
|
||||||
t.equal(bl.shallowSlice(5).toString(), 'SecondThird')
|
|
||||||
t.equal(bl.shallowSlice(5, -3).toString(), 'SecondTh')
|
|
||||||
t.equal(bl.shallowSlice(-8).toString(), 'ondThird')
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('shallow slice does not make a copy', function (t) {
|
|
||||||
t.plan(1)
|
|
||||||
var buffers = [Buffer.from('First'), Buffer.from('Second'), Buffer.from('Third')]
|
|
||||||
var bl = (new BufferList(buffers)).shallowSlice(5, -3)
|
|
||||||
|
|
||||||
buffers[1].fill('h')
|
|
||||||
buffers[2].fill('h')
|
|
||||||
|
|
||||||
t.equal(bl.toString(), 'hhhhhhhh')
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('duplicate', function (t) {
|
|
||||||
t.plan(2)
|
|
||||||
|
|
||||||
var bl = new BufferList('abcdefghij\xff\x00')
|
|
||||||
, dup = bl.duplicate()
|
|
||||||
|
|
||||||
t.equal(bl.prototype, dup.prototype)
|
|
||||||
t.equal(bl.toString('hex'), dup.toString('hex'))
|
|
||||||
})
|
|
||||||
|
|
||||||
tape('destroy no pipe', function (t) {
|
|
||||||
t.plan(2)
|
|
||||||
|
|
||||||
var bl = new BufferList('alsdkfja;lsdkfja;lsdk')
|
|
||||||
bl.destroy()
|
|
||||||
|
|
||||||
t.equal(bl._bufs.length, 0)
|
|
||||||
t.equal(bl.length, 0)
|
|
||||||
})
|
|
||||||
|
|
||||||
!process.browser && tape('destroy with pipe before read end', function (t) {
|
|
||||||
t.plan(2)
|
|
||||||
|
|
||||||
var bl = new BufferList()
|
|
||||||
fs.createReadStream(__dirname + '/test.js')
|
|
||||||
.pipe(bl)
|
|
||||||
|
|
||||||
bl.destroy()
|
|
||||||
|
|
||||||
t.equal(bl._bufs.length, 0)
|
|
||||||
t.equal(bl.length, 0)
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
!process.browser && tape('destroy with pipe before read end with race', function (t) {
|
|
||||||
t.plan(2)
|
|
||||||
|
|
||||||
var bl = new BufferList()
|
|
||||||
fs.createReadStream(__dirname + '/test.js')
|
|
||||||
.pipe(bl)
|
|
||||||
|
|
||||||
setTimeout(function () {
|
|
||||||
bl.destroy()
|
|
||||||
setTimeout(function () {
|
|
||||||
t.equal(bl._bufs.length, 0)
|
|
||||||
t.equal(bl.length, 0)
|
|
||||||
}, 500)
|
|
||||||
}, 500)
|
|
||||||
})
|
|
||||||
|
|
||||||
!process.browser && tape('destroy with pipe after read end', function (t) {
|
|
||||||
t.plan(2)
|
|
||||||
|
|
||||||
var bl = new BufferList()
|
|
||||||
fs.createReadStream(__dirname + '/test.js')
|
|
||||||
.on('end', onEnd)
|
|
||||||
.pipe(bl)
|
|
||||||
|
|
||||||
function onEnd () {
|
|
||||||
bl.destroy()
|
|
||||||
|
|
||||||
t.equal(bl._bufs.length, 0)
|
|
||||||
t.equal(bl.length, 0)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
!process.browser && tape('destroy with pipe while writing to a destination', function (t) {
|
|
||||||
t.plan(4)
|
|
||||||
|
|
||||||
var bl = new BufferList()
|
|
||||||
, ds = new BufferList()
|
|
||||||
|
|
||||||
fs.createReadStream(__dirname + '/test.js')
|
|
||||||
.on('end', onEnd)
|
|
||||||
.pipe(bl)
|
|
||||||
|
|
||||||
function onEnd () {
|
|
||||||
bl.pipe(ds)
|
|
||||||
|
|
||||||
setTimeout(function () {
|
|
||||||
bl.destroy()
|
|
||||||
|
|
||||||
t.equals(bl._bufs.length, 0)
|
|
||||||
t.equals(bl.length, 0)
|
|
||||||
|
|
||||||
ds.destroy()
|
|
||||||
|
|
||||||
t.equals(bl._bufs.length, 0)
|
|
||||||
t.equals(bl.length, 0)
|
|
||||||
|
|
||||||
}, 100)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
!process.browser && tape('handle error', function (t) {
|
|
||||||
t.plan(2)
|
|
||||||
fs.createReadStream('/does/not/exist').pipe(BufferList(function (err, data) {
|
|
||||||
t.ok(err instanceof Error, 'has error')
|
|
||||||
t.notOk(data, 'no data')
|
|
||||||
}))
|
|
||||||
})
|
|
@ -1,17 +0,0 @@
|
|||||||
function allocUnsafe (size) {
|
|
||||||
if (typeof size !== 'number') {
|
|
||||||
throw new TypeError('"size" argument must be a number')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size < 0) {
|
|
||||||
throw new RangeError('"size" argument must not be negative')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Buffer.allocUnsafe) {
|
|
||||||
return Buffer.allocUnsafe(size)
|
|
||||||
} else {
|
|
||||||
return new Buffer(size)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = allocUnsafe
|
|
@ -1,46 +0,0 @@
|
|||||||
# Buffer Alloc Unsafe
|
|
||||||
|
|
||||||
A [ponyfill](https://ponyfill.com) for `Buffer.allocUnsafe`.
|
|
||||||
|
|
||||||
Works as Node.js: `v7.0.0` <br>
|
|
||||||
Works on Node.js: `v0.10.0`
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm install --save buffer-alloc-unsafe
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```js
|
|
||||||
const allocUnsafe = require('buffer-alloc-unsafe')
|
|
||||||
|
|
||||||
console.log(allocUnsafe(10))
|
|
||||||
//=> <Buffer 78 0c 80 03 01 00 00 00 05 00>
|
|
||||||
|
|
||||||
console.log(allocUnsafe(10))
|
|
||||||
//=> <Buffer 58 ed bf 5f ff 7f 00 00 01 00>
|
|
||||||
|
|
||||||
console.log(allocUnsafe(10))
|
|
||||||
//=> <Buffer 50 0c 80 03 01 00 00 00 0a 00>
|
|
||||||
|
|
||||||
allocUnsafe(-10)
|
|
||||||
//=> RangeError: "size" argument must not be negative
|
|
||||||
```
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
### allocUnsafe(size)
|
|
||||||
|
|
||||||
- `size` <Integer> The desired length of the new `Buffer`
|
|
||||||
|
|
||||||
Allocates a new *non-zero-filled* `Buffer` of `size` bytes. The `size` must be
|
|
||||||
less than or equal to the value of `buffer.kMaxLength` and greater than or equal
|
|
||||||
to zero. Otherwise, a `RangeError` is thrown.
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [buffer-alloc](https://github.com/LinusU/buffer-alloc) A ponyfill for `Buffer.alloc`
|
|
||||||
- [buffer-fill](https://github.com/LinusU/buffer-fill) A ponyfill for `Buffer.fill`
|
|
||||||
- [buffer-from](https://github.com/LinusU/buffer-from) A ponyfill for `Buffer.from`
|
|
@ -1,32 +0,0 @@
|
|||||||
var bufferFill = require('buffer-fill')
|
|
||||||
var allocUnsafe = require('buffer-alloc-unsafe')
|
|
||||||
|
|
||||||
module.exports = function alloc (size, fill, encoding) {
|
|
||||||
if (typeof size !== 'number') {
|
|
||||||
throw new TypeError('"size" argument must be a number')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size < 0) {
|
|
||||||
throw new RangeError('"size" argument must not be negative')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Buffer.alloc) {
|
|
||||||
return Buffer.alloc(size, fill, encoding)
|
|
||||||
}
|
|
||||||
|
|
||||||
var buffer = allocUnsafe(size)
|
|
||||||
|
|
||||||
if (size === 0) {
|
|
||||||
return buffer
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fill === undefined) {
|
|
||||||
return bufferFill(buffer, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof encoding !== 'string') {
|
|
||||||
encoding = undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
return bufferFill(buffer, fill, encoding)
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
# Buffer Alloc
|
|
||||||
|
|
||||||
A [ponyfill](https://ponyfill.com) for `Buffer.alloc`.
|
|
||||||
|
|
||||||
Works as Node.js: `v7.0.0` <br>
|
|
||||||
Works on Node.js: `v0.10.0`
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm install --save buffer-alloc
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```js
|
|
||||||
const alloc = require('buffer-alloc')
|
|
||||||
|
|
||||||
console.log(alloc(4))
|
|
||||||
//=> <Buffer 00 00 00 00>
|
|
||||||
|
|
||||||
console.log(alloc(6, 0x41))
|
|
||||||
//=> <Buffer 41 41 41 41 41 41>
|
|
||||||
|
|
||||||
console.log(alloc(10, 'linus', 'utf8'))
|
|
||||||
//=> <Buffer 6c 69 6e 75 73 6c 69 6e 75 73>
|
|
||||||
```
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
### alloc(size[, fill[, encoding]])
|
|
||||||
|
|
||||||
- `size` <Integer> The desired length of the new `Buffer`
|
|
||||||
- `fill` <String> | <Buffer> | <Integer> A value to pre-fill the new `Buffer` with. **Default:** `0`
|
|
||||||
- `encoding` <String> If `fill` is a string, this is its encoding. **Default:** `'utf8'`
|
|
||||||
|
|
||||||
Allocates a new `Buffer` of `size` bytes. If `fill` is `undefined`, the `Buffer` will be zero-filled.
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [buffer-alloc-unsafe](https://github.com/LinusU/buffer-alloc-unsafe) A ponyfill for `Buffer.allocUnsafe`
|
|
||||||
- [buffer-fill](https://github.com/LinusU/buffer-fill) A ponyfill for `Buffer.fill`
|
|
||||||
- [buffer-from](https://github.com/LinusU/buffer-from) A ponyfill for `Buffer.from`
|
|
@ -1,19 +0,0 @@
|
|||||||
The MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2013 Brian J. Brennan
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal in
|
|
||||||
the Software without restriction, including without limitation the rights to use,
|
|
||||||
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
|
||||||
Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
||||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -1,47 +0,0 @@
|
|||||||
# buffer-crc32
|
|
||||||
|
|
||||||
[![Build Status](https://secure.travis-ci.org/brianloveswords/buffer-crc32.png?branch=master)](http://travis-ci.org/brianloveswords/buffer-crc32)
|
|
||||||
|
|
||||||
crc32 that works with binary data and fancy character sets, outputs
|
|
||||||
buffer, signed or unsigned data and has tests.
|
|
||||||
|
|
||||||
Derived from the sample CRC implementation in the PNG specification: http://www.w3.org/TR/PNG/#D-CRCAppendix
|
|
||||||
|
|
||||||
# install
|
|
||||||
```
|
|
||||||
npm install buffer-crc32
|
|
||||||
```
|
|
||||||
|
|
||||||
# example
|
|
||||||
```js
|
|
||||||
var crc32 = require('buffer-crc32');
|
|
||||||
// works with buffers
|
|
||||||
var buf = Buffer([0x00, 0x73, 0x75, 0x70, 0x20, 0x62, 0x72, 0x6f, 0x00])
|
|
||||||
crc32(buf) // -> <Buffer 94 5a ab 4a>
|
|
||||||
|
|
||||||
// has convenience methods for getting signed or unsigned ints
|
|
||||||
crc32.signed(buf) // -> -1805997238
|
|
||||||
crc32.unsigned(buf) // -> 2488970058
|
|
||||||
|
|
||||||
// will cast to buffer if given a string, so you can
|
|
||||||
// directly use foreign characters safely
|
|
||||||
crc32('自動販売機') // -> <Buffer cb 03 1a c5>
|
|
||||||
|
|
||||||
// and works in append mode too
|
|
||||||
var partialCrc = crc32('hey');
|
|
||||||
var partialCrc = crc32(' ', partialCrc);
|
|
||||||
var partialCrc = crc32('sup', partialCrc);
|
|
||||||
var partialCrc = crc32(' ', partialCrc);
|
|
||||||
var finalCrc = crc32('bros', partialCrc); // -> <Buffer 47 fa 55 70>
|
|
||||||
```
|
|
||||||
|
|
||||||
# tests
|
|
||||||
This was tested against the output of zlib's crc32 method. You can run
|
|
||||||
the tests with`npm test` (requires tap)
|
|
||||||
|
|
||||||
# see also
|
|
||||||
https://github.com/alexgorbatchev/node-crc, `crc.buffer.crc32` also
|
|
||||||
supports buffer inputs and return unsigned ints (thanks @tjholowaychuk).
|
|
||||||
|
|
||||||
# license
|
|
||||||
MIT/X11
|
|
@ -1,111 +0,0 @@
|
|||||||
var Buffer = require('buffer').Buffer;
|
|
||||||
|
|
||||||
var CRC_TABLE = [
|
|
||||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
|
|
||||||
0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
|
|
||||||
0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
|
|
||||||
0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
|
|
||||||
0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
|
|
||||||
0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
|
|
||||||
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
|
|
||||||
0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
|
|
||||||
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
|
|
||||||
0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
|
|
||||||
0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
|
|
||||||
0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
|
|
||||||
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
|
|
||||||
0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
|
|
||||||
0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
|
|
||||||
0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
|
|
||||||
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
|
|
||||||
0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
|
|
||||||
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
|
|
||||||
0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
|
|
||||||
0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
|
|
||||||
0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
|
|
||||||
0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
|
|
||||||
0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
|
||||||
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
|
|
||||||
0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
|
|
||||||
0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
|
|
||||||
0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
|
|
||||||
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
|
|
||||||
0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
|
|
||||||
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
|
|
||||||
0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
|
|
||||||
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
|
|
||||||
0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
|
|
||||||
0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
|
|
||||||
0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
|
|
||||||
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
|
|
||||||
0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
|
|
||||||
0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
|
|
||||||
0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
|
|
||||||
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
|
|
||||||
0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
|
|
||||||
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
|
|
||||||
0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
|
|
||||||
0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
|
|
||||||
0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
|
|
||||||
0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
|
|
||||||
0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
|
||||||
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
|
|
||||||
0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
|
|
||||||
0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
|
|
||||||
0x2d02ef8d
|
|
||||||
];
|
|
||||||
|
|
||||||
if (typeof Int32Array !== 'undefined') {
|
|
||||||
CRC_TABLE = new Int32Array(CRC_TABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ensureBuffer(input) {
|
|
||||||
if (Buffer.isBuffer(input)) {
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
|
|
||||||
var hasNewBufferAPI =
|
|
||||||
typeof Buffer.alloc === "function" &&
|
|
||||||
typeof Buffer.from === "function";
|
|
||||||
|
|
||||||
if (typeof input === "number") {
|
|
||||||
return hasNewBufferAPI ? Buffer.alloc(input) : new Buffer(input);
|
|
||||||
}
|
|
||||||
else if (typeof input === "string") {
|
|
||||||
return hasNewBufferAPI ? Buffer.from(input) : new Buffer(input);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new Error("input must be buffer, number, or string, received " +
|
|
||||||
typeof input);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function bufferizeInt(num) {
|
|
||||||
var tmp = ensureBuffer(4);
|
|
||||||
tmp.writeInt32BE(num, 0);
|
|
||||||
return tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
function _crc32(buf, previous) {
|
|
||||||
buf = ensureBuffer(buf);
|
|
||||||
if (Buffer.isBuffer(previous)) {
|
|
||||||
previous = previous.readUInt32BE(0);
|
|
||||||
}
|
|
||||||
var crc = ~~previous ^ -1;
|
|
||||||
for (var n = 0; n < buf.length; n++) {
|
|
||||||
crc = CRC_TABLE[(crc ^ buf[n]) & 0xff] ^ (crc >>> 8);
|
|
||||||
}
|
|
||||||
return (crc ^ -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function crc32() {
|
|
||||||
return bufferizeInt(_crc32.apply(null, arguments));
|
|
||||||
}
|
|
||||||
crc32.signed = function () {
|
|
||||||
return _crc32.apply(null, arguments);
|
|
||||||
};
|
|
||||||
crc32.unsigned = function () {
|
|
||||||
return _crc32.apply(null, arguments) >>> 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = crc32;
|
|
@ -1,113 +0,0 @@
|
|||||||
/* Node.js 6.4.0 and up has full support */
|
|
||||||
var hasFullSupport = (function () {
|
|
||||||
try {
|
|
||||||
if (!Buffer.isEncoding('latin1')) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
var buf = Buffer.alloc ? Buffer.alloc(4) : new Buffer(4)
|
|
||||||
|
|
||||||
buf.fill('ab', 'ucs2')
|
|
||||||
|
|
||||||
return (buf.toString('hex') === '61006200')
|
|
||||||
} catch (_) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}())
|
|
||||||
|
|
||||||
function isSingleByte (val) {
|
|
||||||
return (val.length === 1 && val.charCodeAt(0) < 256)
|
|
||||||
}
|
|
||||||
|
|
||||||
function fillWithNumber (buffer, val, start, end) {
|
|
||||||
if (start < 0 || end > buffer.length) {
|
|
||||||
throw new RangeError('Out of range index')
|
|
||||||
}
|
|
||||||
|
|
||||||
start = start >>> 0
|
|
||||||
end = end === undefined ? buffer.length : end >>> 0
|
|
||||||
|
|
||||||
if (end > start) {
|
|
||||||
buffer.fill(val, start, end)
|
|
||||||
}
|
|
||||||
|
|
||||||
return buffer
|
|
||||||
}
|
|
||||||
|
|
||||||
function fillWithBuffer (buffer, val, start, end) {
|
|
||||||
if (start < 0 || end > buffer.length) {
|
|
||||||
throw new RangeError('Out of range index')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (end <= start) {
|
|
||||||
return buffer
|
|
||||||
}
|
|
||||||
|
|
||||||
start = start >>> 0
|
|
||||||
end = end === undefined ? buffer.length : end >>> 0
|
|
||||||
|
|
||||||
var pos = start
|
|
||||||
var len = val.length
|
|
||||||
while (pos <= (end - len)) {
|
|
||||||
val.copy(buffer, pos)
|
|
||||||
pos += len
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pos !== end) {
|
|
||||||
val.copy(buffer, pos, 0, end - pos)
|
|
||||||
}
|
|
||||||
|
|
||||||
return buffer
|
|
||||||
}
|
|
||||||
|
|
||||||
function fill (buffer, val, start, end, encoding) {
|
|
||||||
if (hasFullSupport) {
|
|
||||||
return buffer.fill(val, start, end, encoding)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof val === 'number') {
|
|
||||||
return fillWithNumber(buffer, val, start, end)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof val === 'string') {
|
|
||||||
if (typeof start === 'string') {
|
|
||||||
encoding = start
|
|
||||||
start = 0
|
|
||||||
end = buffer.length
|
|
||||||
} else if (typeof end === 'string') {
|
|
||||||
encoding = end
|
|
||||||
end = buffer.length
|
|
||||||
}
|
|
||||||
|
|
||||||
if (encoding !== undefined && typeof encoding !== 'string') {
|
|
||||||
throw new TypeError('encoding must be a string')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (encoding === 'latin1') {
|
|
||||||
encoding = 'binary'
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
|
||||||
throw new TypeError('Unknown encoding: ' + encoding)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (val === '') {
|
|
||||||
return fillWithNumber(buffer, 0, start, end)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isSingleByte(val)) {
|
|
||||||
return fillWithNumber(buffer, val.charCodeAt(0), start, end)
|
|
||||||
}
|
|
||||||
|
|
||||||
val = new Buffer(val, encoding)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Buffer.isBuffer(val)) {
|
|
||||||
return fillWithBuffer(buffer, val, start, end)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Other values (e.g. undefined, boolean, object) results in zero-fill
|
|
||||||
return fillWithNumber(buffer, 0, start, end)
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = fill
|
|
@ -1,54 +0,0 @@
|
|||||||
# Buffer Fill
|
|
||||||
|
|
||||||
A [ponyfill](https://ponyfill.com) for `Buffer.fill`.
|
|
||||||
|
|
||||||
Works as Node.js: `v6.4.0` <br>
|
|
||||||
Works on Node.js: `v0.10.0`
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm install --save buffer-fill
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```js
|
|
||||||
const fill = require('buffer-fill')
|
|
||||||
const buf = Buffer.allocUnsafe(5)
|
|
||||||
|
|
||||||
console.log(buf.fill(8))
|
|
||||||
//=> <Buffer 08 08 08 08 08>
|
|
||||||
|
|
||||||
console.log(buf.fill(9, 2, 4))
|
|
||||||
//=> <Buffer 08 08 09 09 08>
|
|
||||||
|
|
||||||
console.log(buf.fill('linus', 'latin1'))
|
|
||||||
//=> <Buffer 6c 69 6e 75 73>
|
|
||||||
|
|
||||||
console.log(buf.fill('\u0222'))
|
|
||||||
//=> <Buffer c8 a2 c8 a2 c8>
|
|
||||||
```
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
### fill(buf, value[, offset[, end]][, encoding])
|
|
||||||
|
|
||||||
- `value` <String> | <Buffer> | <Integer> The value to fill `buf` with
|
|
||||||
- `offset` <Integer> Where to start filling `buf`. **Default:** `0`
|
|
||||||
- `end` <Integer> Where to stop filling `buf` (not inclusive). **Default:** `buf.length`
|
|
||||||
- `encoding` <String> If `value` is a string, this is its encoding. **Default:** `'utf8'`
|
|
||||||
- Return: <Buffer> A reference to `buf`
|
|
||||||
|
|
||||||
Fills `buf` with the specified `value`. If the `offset` and `end` are not given,
|
|
||||||
the entire `buf` will be filled. This is meant to be a small simplification to
|
|
||||||
allow the creation and filling of a `Buffer` to be done on a single line.
|
|
||||||
|
|
||||||
If the final write of a `fill()` operation falls on a multi-byte character, then
|
|
||||||
only the first bytes of that character that fit into `buf` are written.
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [buffer-alloc-unsafe](https://github.com/LinusU/buffer-alloc-unsafe) A ponyfill for `Buffer.allocUnsafe`
|
|
||||||
- [buffer-alloc](https://github.com/LinusU/buffer-alloc) A ponyfill for `Buffer.alloc`
|
|
||||||
- [buffer-from](https://github.com/LinusU/buffer-from) A ponyfill for `Buffer.from`
|
|
@ -1 +0,0 @@
|
|||||||
perf/
|
|
@ -1,8 +0,0 @@
|
|||||||
language: node_js
|
|
||||||
node_js:
|
|
||||||
- '4'
|
|
||||||
sudo: false
|
|
||||||
env:
|
|
||||||
global:
|
|
||||||
- secure: AUsK+8fYSpwIMHcVt8Mu9SpG9RPHp4XDAwCQfpU3d5U65q8OVVC6C+XjvnNmEd2PoEJRHem8ZXEyRVfGM1sttKZLZP70TEKZOpOiRQnZiTQCAJ92TfGsDj/F4LoWSjUZUpfeg9b3iSp8G5dVw3+q9QZPIu6eykASK6bfcg//Cyg=
|
|
||||||
- secure: eQBKJWu7XbhAN4ZvOOhMenC0IPpoYj+wZVVzzsLwUppfJqlrHV0CUW8rJdvZNiaGhYhoyHTnAcynpTE5kZfg3XjevOvF8PGY5wUYCki9BI+rp+pvVPZE/DNUAQpFR2gd2nxMJ4kYv7GVb6i/DfuqJa0h8IuY4zcMuKWwbQd3Az8=
|
|
@ -1,22 +0,0 @@
|
|||||||
ui: tape
|
|
||||||
scripts:
|
|
||||||
- "./test/_polyfill.js"
|
|
||||||
browsers:
|
|
||||||
- name: chrome
|
|
||||||
version: -2..latest
|
|
||||||
- name: firefox
|
|
||||||
version: -2..latest
|
|
||||||
- name: safari
|
|
||||||
version: [6, 7, 8, 9..latest]
|
|
||||||
- name: ie
|
|
||||||
version: 8..latest
|
|
||||||
- name: microsoftedge
|
|
||||||
version: 20..latest
|
|
||||||
- name: opera
|
|
||||||
version: 11..latest
|
|
||||||
- name: iphone
|
|
||||||
version: [5.1, 6.1, 7.1, 8.4, 9.1..latest]
|
|
||||||
- name: ipad
|
|
||||||
version: [5.1, 6.1, 7.1, 8.4, 9.1..latest]
|
|
||||||
- name: android
|
|
||||||
version: 4.0..latest
|
|
@ -1,21 +0,0 @@
|
|||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) Feross Aboukhadijeh, and other contributors.
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
@ -1,364 +0,0 @@
|
|||||||
# buffer [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][npm-url]
|
|
||||||
|
|
||||||
#### The buffer module from [node.js](http://nodejs.org/), for the browser.
|
|
||||||
|
|
||||||
[![saucelabs][saucelabs-image]][saucelabs-url]
|
|
||||||
|
|
||||||
[travis-image]: https://img.shields.io/travis/feross/buffer.svg?style=flat
|
|
||||||
[travis-url]: https://travis-ci.org/feross/buffer
|
|
||||||
[npm-image]: https://img.shields.io/npm/v/buffer.svg?style=flat
|
|
||||||
[npm-url]: https://npmjs.org/package/buffer
|
|
||||||
[downloads-image]: https://img.shields.io/npm/dm/buffer.svg?style=flat
|
|
||||||
[saucelabs-image]: https://saucelabs.com/browser-matrix/buffer.svg
|
|
||||||
[saucelabs-url]: https://saucelabs.com/u/buffer
|
|
||||||
|
|
||||||
With [browserify](http://browserify.org), simply `require('buffer')` or use the `Buffer` global and you will get this module.
|
|
||||||
|
|
||||||
The goal is to provide an API that is 100% identical to
|
|
||||||
[node's Buffer API](http://iojs.org/api/buffer.html). Read the
|
|
||||||
[official docs](http://iojs.org/api/buffer.html) for the full list of properties,
|
|
||||||
instance methods, and class methods that are supported.
|
|
||||||
|
|
||||||
## features
|
|
||||||
|
|
||||||
- Manipulate binary data like a boss, in all browsers -- even IE6!
|
|
||||||
- Super fast. Backed by Typed Arrays (`Uint8Array`/`ArrayBuffer`, not `Object`)
|
|
||||||
- Extremely small bundle size (**5.04KB minified + gzipped**, 35.5KB with comments)
|
|
||||||
- Excellent browser support (IE 6+, Chrome 4+, Firefox 3+, Safari 5.1+, Opera 11+, iOS, etc.)
|
|
||||||
- Preserves Node API exactly, with one important difference (see below)
|
|
||||||
- `.slice()` returns instances of the same type (Buffer)
|
|
||||||
- Square-bracket `buf[4]` notation works, even in old browsers like IE6!
|
|
||||||
- Does not modify any browser prototypes or put anything on `window`
|
|
||||||
- Comprehensive test suite (including all buffer tests from node.js core)
|
|
||||||
|
|
||||||
|
|
||||||
## install
|
|
||||||
|
|
||||||
To use this module directly (without browserify), install it:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm install buffer
|
|
||||||
```
|
|
||||||
|
|
||||||
This module was previously called **native-buffer-browserify**, but please use **buffer**
|
|
||||||
from now on.
|
|
||||||
|
|
||||||
A standalone bundle is available [here](https://wzrd.in/standalone/buffer), for non-browserify users.
|
|
||||||
|
|
||||||
|
|
||||||
## usage
|
|
||||||
|
|
||||||
The module's API is identical to node's `Buffer` API. Read the
|
|
||||||
[official docs](http://iojs.org/api/buffer.html) for the full list of properties,
|
|
||||||
instance methods, and class methods that are supported.
|
|
||||||
|
|
||||||
As mentioned above, `require('buffer')` or use the `Buffer` global with
|
|
||||||
[browserify](http://browserify.org) and this module will automatically be included
|
|
||||||
in your bundle. Almost any npm module will work in the browser, even if it assumes that
|
|
||||||
the node `Buffer` API will be available.
|
|
||||||
|
|
||||||
To depend on this module explicitly (without browserify), require it like this:
|
|
||||||
|
|
||||||
```js
|
|
||||||
var Buffer = require('buffer/').Buffer // note: the trailing slash is important!
|
|
||||||
```
|
|
||||||
|
|
||||||
To require this module explicitly, use `require('buffer/')` which tells the node.js module
|
|
||||||
lookup algorithm (also used by browserify) to use the **npm module** named `buffer`
|
|
||||||
instead of the **node.js core** module named `buffer`!
|
|
||||||
|
|
||||||
|
|
||||||
## how does it work?
|
|
||||||
|
|
||||||
`Buffer` is a subclass of `Uint8Array` augmented with all the `Buffer` API methods.
|
|
||||||
The `Uint8Array` prototype is not modified.
|
|
||||||
|
|
||||||
|
|
||||||
## one minor difference
|
|
||||||
|
|
||||||
#### In old browsers, `buf.slice()` does not modify parent buffer's memory
|
|
||||||
|
|
||||||
If you only support modern browsers (specifically, those with typed array support),
|
|
||||||
then this issue does not affect you. If you support super old browsers, then read on.
|
|
||||||
|
|
||||||
In node, the `slice()` method returns a new `Buffer` that shares underlying memory
|
|
||||||
with the original Buffer. When you modify one buffer, you modify the other.
|
|
||||||
[Read more.](http://iojs.org/api/buffer.html#buffer_buf_slice_start_end)
|
|
||||||
|
|
||||||
In browsers with typed array support, this `Buffer` implementation supports this
|
|
||||||
behavior. In browsers without typed arrays, an alternate buffer implementation is
|
|
||||||
used that is based on `Object` which has no mechanism to point separate
|
|
||||||
`Buffer`s to the same underlying slab of memory.
|
|
||||||
|
|
||||||
You can see which browser versions lack typed array support
|
|
||||||
[here](https://github.com/feross/buffer/blob/master/index.js#L20-L46).
|
|
||||||
|
|
||||||
|
|
||||||
## tracking the latest node api
|
|
||||||
|
|
||||||
This module tracks the Buffer API in the latest (unstable) version of node.js. The Buffer
|
|
||||||
API is considered **stable** in the
|
|
||||||
[node stability index](http://nodejs.org/docs/latest/api/documentation.html#documentation_stability_index),
|
|
||||||
so it is unlikely that there will ever be breaking changes.
|
|
||||||
Nonetheless, when/if the Buffer API changes in node, this module's API will change
|
|
||||||
accordingly.
|
|
||||||
|
|
||||||
## performance
|
|
||||||
|
|
||||||
See perf tests in `/perf`.
|
|
||||||
|
|
||||||
`BrowserBuffer` is the browser `buffer` module (this repo). `Uint8Array` is included as a
|
|
||||||
sanity check (since `BrowserBuffer` uses `Uint8Array` under the hood, `Uint8Array` will
|
|
||||||
always be at least a bit faster). Finally, `NodeBuffer` is the node.js buffer module,
|
|
||||||
which is included to compare against.
|
|
||||||
|
|
||||||
### Chrome 38
|
|
||||||
|
|
||||||
| Method | Operations | Accuracy | Sampled | Fastest |
|
|
||||||
|:-------|:-----------|:---------|:--------|:-------:|
|
|
||||||
| BrowserBuffer#bracket-notation | 11,457,464 ops/sec | ±0.86% | 66 | ✓ |
|
|
||||||
| Uint8Array#bracket-notation | 10,824,332 ops/sec | ±0.74% | 65 | |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#concat | 450,532 ops/sec | ±0.76% | 68 | |
|
|
||||||
| Uint8Array#concat | 1,368,911 ops/sec | ±1.50% | 62 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#copy(16000) | 903,001 ops/sec | ±0.96% | 67 | |
|
|
||||||
| Uint8Array#copy(16000) | 1,422,441 ops/sec | ±1.04% | 66 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#copy(16) | 11,431,358 ops/sec | ±0.46% | 69 | |
|
|
||||||
| Uint8Array#copy(16) | 13,944,163 ops/sec | ±1.12% | 68 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#new(16000) | 106,329 ops/sec | ±6.70% | 44 | |
|
|
||||||
| Uint8Array#new(16000) | 131,001 ops/sec | ±2.85% | 31 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#new(16) | 1,554,491 ops/sec | ±1.60% | 65 | |
|
|
||||||
| Uint8Array#new(16) | 6,623,930 ops/sec | ±1.66% | 65 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#readDoubleBE | 112,830 ops/sec | ±0.51% | 69 | ✓ |
|
|
||||||
| DataView#getFloat64 | 93,500 ops/sec | ±0.57% | 68 | |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#readFloatBE | 146,678 ops/sec | ±0.95% | 68 | ✓ |
|
|
||||||
| DataView#getFloat32 | 99,311 ops/sec | ±0.41% | 67 | |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#readUInt32LE | 843,214 ops/sec | ±0.70% | 69 | ✓ |
|
|
||||||
| DataView#getUint32 | 103,024 ops/sec | ±0.64% | 67 | |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#slice | 1,013,941 ops/sec | ±0.75% | 67 | |
|
|
||||||
| Uint8Array#subarray | 1,903,928 ops/sec | ±0.53% | 67 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#writeFloatBE | 61,387 ops/sec | ±0.90% | 67 | |
|
|
||||||
| DataView#setFloat32 | 141,249 ops/sec | ±0.40% | 66 | ✓ |
|
|
||||||
|
|
||||||
|
|
||||||
### Firefox 33
|
|
||||||
|
|
||||||
| Method | Operations | Accuracy | Sampled | Fastest |
|
|
||||||
|:-------|:-----------|:---------|:--------|:-------:|
|
|
||||||
| BrowserBuffer#bracket-notation | 20,800,421 ops/sec | ±1.84% | 60 | |
|
|
||||||
| Uint8Array#bracket-notation | 20,826,235 ops/sec | ±2.02% | 61 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#concat | 153,076 ops/sec | ±2.32% | 61 | |
|
|
||||||
| Uint8Array#concat | 1,255,674 ops/sec | ±8.65% | 52 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#copy(16000) | 1,105,312 ops/sec | ±1.16% | 63 | |
|
|
||||||
| Uint8Array#copy(16000) | 1,615,911 ops/sec | ±0.55% | 66 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#copy(16) | 16,357,599 ops/sec | ±0.73% | 68 | |
|
|
||||||
| Uint8Array#copy(16) | 31,436,281 ops/sec | ±1.05% | 68 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#new(16000) | 52,995 ops/sec | ±6.01% | 35 | |
|
|
||||||
| Uint8Array#new(16000) | 87,686 ops/sec | ±5.68% | 45 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#new(16) | 252,031 ops/sec | ±1.61% | 66 | |
|
|
||||||
| Uint8Array#new(16) | 8,477,026 ops/sec | ±0.49% | 68 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#readDoubleBE | 99,871 ops/sec | ±0.41% | 69 | |
|
|
||||||
| DataView#getFloat64 | 285,663 ops/sec | ±0.70% | 68 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#readFloatBE | 115,540 ops/sec | ±0.42% | 69 | |
|
|
||||||
| DataView#getFloat32 | 288,722 ops/sec | ±0.82% | 68 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#readUInt32LE | 633,926 ops/sec | ±1.08% | 67 | ✓ |
|
|
||||||
| DataView#getUint32 | 294,808 ops/sec | ±0.79% | 64 | |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#slice | 349,425 ops/sec | ±0.46% | 69 | |
|
|
||||||
| Uint8Array#subarray | 5,965,819 ops/sec | ±0.60% | 65 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#writeFloatBE | 59,980 ops/sec | ±0.41% | 67 | |
|
|
||||||
| DataView#setFloat32 | 317,634 ops/sec | ±0.63% | 68 | ✓ |
|
|
||||||
|
|
||||||
### Safari 8
|
|
||||||
|
|
||||||
| Method | Operations | Accuracy | Sampled | Fastest |
|
|
||||||
|:-------|:-----------|:---------|:--------|:-------:|
|
|
||||||
| BrowserBuffer#bracket-notation | 10,279,729 ops/sec | ±2.25% | 56 | ✓ |
|
|
||||||
| Uint8Array#bracket-notation | 10,030,767 ops/sec | ±2.23% | 59 | |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#concat | 144,138 ops/sec | ±1.38% | 65 | |
|
|
||||||
| Uint8Array#concat | 4,950,764 ops/sec | ±1.70% | 63 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#copy(16000) | 1,058,548 ops/sec | ±1.51% | 64 | |
|
|
||||||
| Uint8Array#copy(16000) | 1,409,666 ops/sec | ±1.17% | 65 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#copy(16) | 6,282,529 ops/sec | ±1.88% | 58 | |
|
|
||||||
| Uint8Array#copy(16) | 11,907,128 ops/sec | ±2.87% | 58 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#new(16000) | 101,663 ops/sec | ±3.89% | 57 | |
|
|
||||||
| Uint8Array#new(16000) | 22,050,818 ops/sec | ±6.51% | 46 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#new(16) | 176,072 ops/sec | ±2.13% | 64 | |
|
|
||||||
| Uint8Array#new(16) | 24,385,731 ops/sec | ±5.01% | 51 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#readDoubleBE | 41,341 ops/sec | ±1.06% | 67 | |
|
|
||||||
| DataView#getFloat64 | 322,280 ops/sec | ±0.84% | 68 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#readFloatBE | 46,141 ops/sec | ±1.06% | 65 | |
|
|
||||||
| DataView#getFloat32 | 337,025 ops/sec | ±0.43% | 69 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#readUInt32LE | 151,551 ops/sec | ±1.02% | 66 | |
|
|
||||||
| DataView#getUint32 | 308,278 ops/sec | ±0.94% | 67 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#slice | 197,365 ops/sec | ±0.95% | 66 | |
|
|
||||||
| Uint8Array#subarray | 9,558,024 ops/sec | ±3.08% | 58 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#writeFloatBE | 17,518 ops/sec | ±1.03% | 63 | |
|
|
||||||
| DataView#setFloat32 | 319,751 ops/sec | ±0.48% | 68 | ✓ |
|
|
||||||
|
|
||||||
|
|
||||||
### Node 0.11.14
|
|
||||||
|
|
||||||
| Method | Operations | Accuracy | Sampled | Fastest |
|
|
||||||
|:-------|:-----------|:---------|:--------|:-------:|
|
|
||||||
| BrowserBuffer#bracket-notation | 10,489,828 ops/sec | ±3.25% | 90 | |
|
|
||||||
| Uint8Array#bracket-notation | 10,534,884 ops/sec | ±0.81% | 92 | ✓ |
|
|
||||||
| NodeBuffer#bracket-notation | 10,389,910 ops/sec | ±0.97% | 87 | |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#concat | 487,830 ops/sec | ±2.58% | 88 | |
|
|
||||||
| Uint8Array#concat | 1,814,327 ops/sec | ±1.28% | 88 | ✓ |
|
|
||||||
| NodeBuffer#concat | 1,636,523 ops/sec | ±1.88% | 73 | |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#copy(16000) | 1,073,665 ops/sec | ±0.77% | 90 | |
|
|
||||||
| Uint8Array#copy(16000) | 1,348,517 ops/sec | ±0.84% | 89 | ✓ |
|
|
||||||
| NodeBuffer#copy(16000) | 1,289,533 ops/sec | ±0.82% | 93 | |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#copy(16) | 12,782,706 ops/sec | ±0.74% | 85 | |
|
|
||||||
| Uint8Array#copy(16) | 14,180,427 ops/sec | ±0.93% | 92 | ✓ |
|
|
||||||
| NodeBuffer#copy(16) | 11,083,134 ops/sec | ±1.06% | 89 | |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#new(16000) | 141,678 ops/sec | ±3.30% | 67 | |
|
|
||||||
| Uint8Array#new(16000) | 161,491 ops/sec | ±2.96% | 60 | |
|
|
||||||
| NodeBuffer#new(16000) | 292,699 ops/sec | ±3.20% | 55 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#new(16) | 1,655,466 ops/sec | ±2.41% | 82 | |
|
|
||||||
| Uint8Array#new(16) | 14,399,926 ops/sec | ±0.91% | 94 | ✓ |
|
|
||||||
| NodeBuffer#new(16) | 3,894,696 ops/sec | ±0.88% | 92 | |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#readDoubleBE | 109,582 ops/sec | ±0.75% | 93 | ✓ |
|
|
||||||
| DataView#getFloat64 | 91,235 ops/sec | ±0.81% | 90 | |
|
|
||||||
| NodeBuffer#readDoubleBE | 88,593 ops/sec | ±0.96% | 81 | |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#readFloatBE | 139,854 ops/sec | ±1.03% | 85 | ✓ |
|
|
||||||
| DataView#getFloat32 | 98,744 ops/sec | ±0.80% | 89 | |
|
|
||||||
| NodeBuffer#readFloatBE | 92,769 ops/sec | ±0.94% | 93 | |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#readUInt32LE | 710,861 ops/sec | ±0.82% | 92 | |
|
|
||||||
| DataView#getUint32 | 117,893 ops/sec | ±0.84% | 91 | |
|
|
||||||
| NodeBuffer#readUInt32LE | 851,412 ops/sec | ±0.72% | 93 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#slice | 1,673,877 ops/sec | ±0.73% | 94 | |
|
|
||||||
| Uint8Array#subarray | 6,919,243 ops/sec | ±0.67% | 90 | ✓ |
|
|
||||||
| NodeBuffer#slice | 4,617,604 ops/sec | ±0.79% | 93 | |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#writeFloatBE | 66,011 ops/sec | ±0.75% | 93 | |
|
|
||||||
| DataView#setFloat32 | 127,760 ops/sec | ±0.72% | 93 | ✓ |
|
|
||||||
| NodeBuffer#writeFloatBE | 103,352 ops/sec | ±0.83% | 93 | |
|
|
||||||
|
|
||||||
### iojs 1.8.1
|
|
||||||
|
|
||||||
| Method | Operations | Accuracy | Sampled | Fastest |
|
|
||||||
|:-------|:-----------|:---------|:--------|:-------:|
|
|
||||||
| BrowserBuffer#bracket-notation | 10,990,488 ops/sec | ±1.11% | 91 | |
|
|
||||||
| Uint8Array#bracket-notation | 11,268,757 ops/sec | ±0.65% | 97 | |
|
|
||||||
| NodeBuffer#bracket-notation | 11,353,260 ops/sec | ±0.83% | 94 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#concat | 378,954 ops/sec | ±0.74% | 94 | |
|
|
||||||
| Uint8Array#concat | 1,358,288 ops/sec | ±0.97% | 87 | |
|
|
||||||
| NodeBuffer#concat | 1,934,050 ops/sec | ±1.11% | 78 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#copy(16000) | 894,538 ops/sec | ±0.56% | 84 | |
|
|
||||||
| Uint8Array#copy(16000) | 1,442,656 ops/sec | ±0.71% | 96 | |
|
|
||||||
| NodeBuffer#copy(16000) | 1,457,898 ops/sec | ±0.53% | 92 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#copy(16) | 12,870,457 ops/sec | ±0.67% | 95 | |
|
|
||||||
| Uint8Array#copy(16) | 16,643,989 ops/sec | ±0.61% | 93 | ✓ |
|
|
||||||
| NodeBuffer#copy(16) | 14,885,848 ops/sec | ±0.74% | 94 | |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#new(16000) | 109,264 ops/sec | ±4.21% | 63 | |
|
|
||||||
| Uint8Array#new(16000) | 138,916 ops/sec | ±1.87% | 61 | |
|
|
||||||
| NodeBuffer#new(16000) | 281,449 ops/sec | ±3.58% | 51 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#new(16) | 1,362,935 ops/sec | ±0.56% | 99 | |
|
|
||||||
| Uint8Array#new(16) | 6,193,090 ops/sec | ±0.64% | 95 | ✓ |
|
|
||||||
| NodeBuffer#new(16) | 4,745,425 ops/sec | ±1.56% | 90 | |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#readDoubleBE | 118,127 ops/sec | ±0.59% | 93 | ✓ |
|
|
||||||
| DataView#getFloat64 | 107,332 ops/sec | ±0.65% | 91 | |
|
|
||||||
| NodeBuffer#readDoubleBE | 116,274 ops/sec | ±0.94% | 95 | |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#readFloatBE | 150,326 ops/sec | ±0.58% | 95 | ✓ |
|
|
||||||
| DataView#getFloat32 | 110,541 ops/sec | ±0.57% | 98 | |
|
|
||||||
| NodeBuffer#readFloatBE | 121,599 ops/sec | ±0.60% | 87 | |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#readUInt32LE | 814,147 ops/sec | ±0.62% | 93 | |
|
|
||||||
| DataView#getUint32 | 137,592 ops/sec | ±0.64% | 90 | |
|
|
||||||
| NodeBuffer#readUInt32LE | 931,650 ops/sec | ±0.71% | 96 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#slice | 878,590 ops/sec | ±0.68% | 93 | |
|
|
||||||
| Uint8Array#subarray | 2,843,308 ops/sec | ±1.02% | 90 | |
|
|
||||||
| NodeBuffer#slice | 4,998,316 ops/sec | ±0.68% | 90 | ✓ |
|
|
||||||
| | | | |
|
|
||||||
| BrowserBuffer#writeFloatBE | 65,927 ops/sec | ±0.74% | 93 | |
|
|
||||||
| DataView#setFloat32 | 139,823 ops/sec | ±0.97% | 89 | ✓ |
|
|
||||||
| NodeBuffer#writeFloatBE | 135,763 ops/sec | ±0.65% | 96 | |
|
|
||||||
| | | | |
|
|
||||||
|
|
||||||
## Testing the project
|
|
||||||
|
|
||||||
First, install the project:
|
|
||||||
|
|
||||||
npm install
|
|
||||||
|
|
||||||
Then, to run tests in Node.js, run:
|
|
||||||
|
|
||||||
npm run test-node
|
|
||||||
|
|
||||||
To test locally in a browser, you can run:
|
|
||||||
|
|
||||||
npm run test-browser-local
|
|
||||||
|
|
||||||
This will print out a URL that you can then open in a browser to run the tests, using [Zuul](https://github.com/defunctzombie/zuul).
|
|
||||||
|
|
||||||
To run automated browser tests using Saucelabs, ensure that your `SAUCE_USERNAME` and `SAUCE_ACCESS_KEY` environment variables are set, then run:
|
|
||||||
|
|
||||||
npm test
|
|
||||||
|
|
||||||
This is what's run in Travis, to check against various browsers. The list of browsers is kept in the `.zuul.yml` file.
|
|
||||||
|
|
||||||
## JavaScript Standard Style
|
|
||||||
|
|
||||||
This module uses [JavaScript Standard Style](https://github.com/feross/standard).
|
|
||||||
|
|
||||||
[![js-standard-style](https://raw.githubusercontent.com/feross/standard/master/badge.png)](https://github.com/feross/standard)
|
|
||||||
|
|
||||||
To test that the code conforms to the style, `npm install` and run:
|
|
||||||
|
|
||||||
./node_modules/.bin/standard
|
|
||||||
|
|
||||||
## credit
|
|
||||||
|
|
||||||
This was originally forked from [buffer-browserify](https://github.com/toots/buffer-browserify).
|
|
||||||
|
|
||||||
|
|
||||||
## license
|
|
||||||
|
|
||||||
MIT. Copyright (C) [Feross Aboukhadijeh](http://feross.org), and other contributors. Originally forked from an MIT-licensed module by Romain Beauxis.
|
|
@ -1,126 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
var concat = require('concat-stream')
|
|
||||||
var fs = require('fs')
|
|
||||||
var hyperquest = require('hyperquest')
|
|
||||||
var cp = require('child_process')
|
|
||||||
var split = require('split')
|
|
||||||
var through = require('through2')
|
|
||||||
|
|
||||||
var url = 'https://api.github.com/repos/nodejs/io.js/contents'
|
|
||||||
var dirs = [
|
|
||||||
'/test/parallel',
|
|
||||||
'/test/pummel'
|
|
||||||
]
|
|
||||||
|
|
||||||
cp.execSync('rm -rf node/*.js', { cwd: __dirname + '/../test' })
|
|
||||||
cp.execSync('rm -rf node-es6/*.js', { cwd: __dirname + '/../test' })
|
|
||||||
|
|
||||||
var httpOpts = {
|
|
||||||
headers: {
|
|
||||||
'User-Agent': null
|
|
||||||
// auth if github rate-limits you...
|
|
||||||
// 'Authorization': 'Basic ' + Buffer('username:password').toString('base64'),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dirs.forEach(function (dir) {
|
|
||||||
var req = hyperquest(url + dir, httpOpts)
|
|
||||||
req.pipe(concat(function (data) {
|
|
||||||
if (req.response.statusCode !== 200) {
|
|
||||||
throw new Error(url + dir + ': ' + data.toString())
|
|
||||||
}
|
|
||||||
downloadBufferTests(dir, JSON.parse(data))
|
|
||||||
}))
|
|
||||||
})
|
|
||||||
|
|
||||||
function downloadBufferTests (dir, files) {
|
|
||||||
files.forEach(function (file) {
|
|
||||||
if (!/test-buffer.*/.test(file.name)) return
|
|
||||||
|
|
||||||
var path
|
|
||||||
if (file.name === 'test-buffer-iterator.js' ||
|
|
||||||
file.name === 'test-buffer-arraybuffer.js') {
|
|
||||||
path = __dirname + '/../test/node-es6/' + file.name
|
|
||||||
} else if (file.name === 'test-buffer-fakes.js') {
|
|
||||||
// These teses only apply to node, where they're calling into C++ and need to
|
|
||||||
// ensure the prototype can't be faked, or else there will be a segfault.
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
path = __dirname + '/../test/node/' + file.name
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(file.download_url)
|
|
||||||
hyperquest(file.download_url, httpOpts)
|
|
||||||
.pipe(split())
|
|
||||||
.pipe(testfixer(file.name))
|
|
||||||
.pipe(fs.createWriteStream(path))
|
|
||||||
.on('finish', function () {
|
|
||||||
console.log('wrote ' + file.name)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function testfixer (filename) {
|
|
||||||
var firstline = true
|
|
||||||
|
|
||||||
return through(function (line, enc, cb) {
|
|
||||||
line = line.toString()
|
|
||||||
|
|
||||||
if (firstline) {
|
|
||||||
// require buffer explicitly
|
|
||||||
var preamble = 'if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false;\n' +
|
|
||||||
'var Buffer = require(\'../../\').Buffer;'
|
|
||||||
if (/use strict/.test(line)) line += '\n' + preamble
|
|
||||||
else line + preamble + '\n' + line
|
|
||||||
firstline = false
|
|
||||||
}
|
|
||||||
|
|
||||||
// use `var` instead of `const`/`let`
|
|
||||||
line = line.replace(/(const|let) /g, 'var ')
|
|
||||||
|
|
||||||
// make `require('common')` work
|
|
||||||
line = line.replace(/(var common = require.*)/g, 'var common = {};')
|
|
||||||
|
|
||||||
// use `Buffer.isBuffer` instead of `instanceof Buffer`
|
|
||||||
line = line.replace(/buf instanceof Buffer/g, 'Buffer.isBuffer(buf)')
|
|
||||||
|
|
||||||
// require browser buffer
|
|
||||||
line = line.replace(/(.*)require\('buffer'\)(.*)/g, '$1require(\'../../\')$2')
|
|
||||||
|
|
||||||
// smalloc is only used for kMaxLength
|
|
||||||
line = line.replace(
|
|
||||||
/require\('smalloc'\)/g,
|
|
||||||
'{ kMaxLength: process.env.OBJECT_IMPL ? 0x3fffffff : 0x7fffffff }'
|
|
||||||
)
|
|
||||||
|
|
||||||
// comment out console logs
|
|
||||||
line = line.replace(/(.*console\..*)/g, '// $1')
|
|
||||||
|
|
||||||
// we can't reliably test typed array max-sizes in the browser
|
|
||||||
if (filename === 'test-buffer-big.js') {
|
|
||||||
line = line.replace(/(.*new Int8Array.*RangeError.*)/, '// $1')
|
|
||||||
line = line.replace(/(.*new ArrayBuffer.*RangeError.*)/, '// $1')
|
|
||||||
line = line.replace(/(.*new Float64Array.*RangeError.*)/, '// $1')
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://github.com/iojs/io.js/blob/v0.12/test/parallel/test-buffer.js#L38
|
|
||||||
// we can't run this because we need to support
|
|
||||||
// browsers that don't have typed arrays
|
|
||||||
if (filename === 'test-buffer.js') {
|
|
||||||
line = line.replace(/b\[0\] = -1;/, 'b[0] = 255;')
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://github.com/iojs/io.js/blob/v0.12/test/parallel/test-buffer.js#L1138
|
|
||||||
// unfortunately we can't run this as it touches
|
|
||||||
// node streams which do an instanceof check
|
|
||||||
// and crypto-browserify doesn't work in old
|
|
||||||
// versions of ie
|
|
||||||
if (filename === 'test-buffer.js') {
|
|
||||||
line = line.replace(/^(\s*)(var crypto = require.*)/, '$1// $2')
|
|
||||||
line = line.replace(/(crypto.createHash.*\))/, '1 /*$1*/')
|
|
||||||
}
|
|
||||||
|
|
||||||
cb(null, line + '\n')
|
|
||||||
})
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
var cp = require('child_process')
|
|
||||||
|
|
||||||
var runBrowserTests = !process.env.TRAVIS_PULL_REQUEST ||
|
|
||||||
process.env.TRAVIS_PULL_REQUEST === 'false'
|
|
||||||
|
|
||||||
var node = cp.spawn('npm', ['run', 'test-node'], { stdio: 'inherit' })
|
|
||||||
node.on('close', function (code) {
|
|
||||||
if (code === 0 && runBrowserTests) {
|
|
||||||
var browser = cp.spawn('npm', ['run', 'test-browser'], { stdio: 'inherit' })
|
|
||||||
browser.on('close', function (code) {
|
|
||||||
process.exit(code)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
process.exit(code)
|
|
||||||
}
|
|
||||||
})
|
|
File diff suppressed because it is too large
Load Diff
@ -1,150 +0,0 @@
|
|||||||
if (!Array.prototype.forEach) {
|
|
||||||
|
|
||||||
Array.prototype.forEach = function(callback, thisArg) {
|
|
||||||
|
|
||||||
var T, k;
|
|
||||||
|
|
||||||
if (this == null) {
|
|
||||||
throw new TypeError(' this is null or not defined');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1. Let O be the result of calling ToObject passing the |this| value as the argument.
|
|
||||||
var O = Object(this);
|
|
||||||
|
|
||||||
// 2. Let lenValue be the result of calling the Get internal method of O with the argument "length".
|
|
||||||
// 3. Let len be ToUint32(lenValue).
|
|
||||||
var len = O.length >>> 0;
|
|
||||||
|
|
||||||
// 4. If IsCallable(callback) is false, throw a TypeError exception.
|
|
||||||
// See: http://es5.github.com/#x9.11
|
|
||||||
if (typeof callback !== "function") {
|
|
||||||
throw new TypeError(callback + ' is not a function');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
|
||||||
if (arguments.length > 1) {
|
|
||||||
T = thisArg;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 6. Let k be 0
|
|
||||||
k = 0;
|
|
||||||
|
|
||||||
// 7. Repeat, while k < len
|
|
||||||
while (k < len) {
|
|
||||||
|
|
||||||
var kValue;
|
|
||||||
|
|
||||||
// a. Let Pk be ToString(k).
|
|
||||||
// This is implicit for LHS operands of the in operator
|
|
||||||
// b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk.
|
|
||||||
// This step can be combined with c
|
|
||||||
// c. If kPresent is true, then
|
|
||||||
if (k in O) {
|
|
||||||
|
|
||||||
// i. Let kValue be the result of calling the Get internal method of O with argument Pk.
|
|
||||||
kValue = O[k];
|
|
||||||
|
|
||||||
// ii. Call the Call internal method of callback with T as the this value and
|
|
||||||
// argument list containing kValue, k, and O.
|
|
||||||
callback.call(T, kValue, k, O);
|
|
||||||
}
|
|
||||||
// d. Increase k by 1.
|
|
||||||
k++;
|
|
||||||
}
|
|
||||||
// 8. return undefined
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Array.isArray) {
|
|
||||||
Array.isArray = function(arg) {
|
|
||||||
return Object.prototype.toString.call(arg) === '[object Array]';
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Array.prototype.map) {
|
|
||||||
|
|
||||||
Array.prototype.map = function(callback, thisArg) {
|
|
||||||
|
|
||||||
var T, A, k;
|
|
||||||
|
|
||||||
if (this == null) {
|
|
||||||
throw new TypeError(' this is null or not defined');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1. Let O be the result of calling ToObject passing the |this|
|
|
||||||
// value as the argument.
|
|
||||||
var O = Object(this);
|
|
||||||
|
|
||||||
// 2. Let lenValue be the result of calling the Get internal
|
|
||||||
// method of O with the argument "length".
|
|
||||||
// 3. Let len be ToUint32(lenValue).
|
|
||||||
var len = O.length >>> 0;
|
|
||||||
|
|
||||||
// 4. If IsCallable(callback) is false, throw a TypeError exception.
|
|
||||||
// See: http://es5.github.com/#x9.11
|
|
||||||
if (typeof callback !== 'function') {
|
|
||||||
throw new TypeError(callback + ' is not a function');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
|
||||||
if (arguments.length > 1) {
|
|
||||||
T = thisArg;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 6. Let A be a new array created as if by the expression new Array(len)
|
|
||||||
// where Array is the standard built-in constructor with that name and
|
|
||||||
// len is the value of len.
|
|
||||||
A = new Array(len);
|
|
||||||
|
|
||||||
// 7. Let k be 0
|
|
||||||
k = 0;
|
|
||||||
|
|
||||||
// 8. Repeat, while k < len
|
|
||||||
while (k < len) {
|
|
||||||
|
|
||||||
var kValue, mappedValue;
|
|
||||||
|
|
||||||
// a. Let Pk be ToString(k).
|
|
||||||
// This is implicit for LHS operands of the in operator
|
|
||||||
// b. Let kPresent be the result of calling the HasProperty internal
|
|
||||||
// method of O with argument Pk.
|
|
||||||
// This step can be combined with c
|
|
||||||
// c. If kPresent is true, then
|
|
||||||
if (k in O) {
|
|
||||||
|
|
||||||
// i. Let kValue be the result of calling the Get internal
|
|
||||||
// method of O with argument Pk.
|
|
||||||
kValue = O[k];
|
|
||||||
|
|
||||||
// ii. Let mappedValue be the result of calling the Call internal
|
|
||||||
// method of callback with T as the this value and argument
|
|
||||||
// list containing kValue, k, and O.
|
|
||||||
mappedValue = callback.call(T, kValue, k, O);
|
|
||||||
|
|
||||||
// iii. Call the DefineOwnProperty internal method of A with arguments
|
|
||||||
// Pk, Property Descriptor
|
|
||||||
// { Value: mappedValue,
|
|
||||||
// Writable: true,
|
|
||||||
// Enumerable: true,
|
|
||||||
// Configurable: true },
|
|
||||||
// and false.
|
|
||||||
|
|
||||||
// In browsers that support Object.defineProperty, use the following:
|
|
||||||
// Object.defineProperty(A, k, {
|
|
||||||
// value: mappedValue,
|
|
||||||
// writable: true,
|
|
||||||
// enumerable: true,
|
|
||||||
// configurable: true
|
|
||||||
// });
|
|
||||||
|
|
||||||
// For best browser support, use the following:
|
|
||||||
A[k] = mappedValue;
|
|
||||||
}
|
|
||||||
// d. Increase k by 1.
|
|
||||||
k++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 9. return A
|
|
||||||
return A;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
|
||||||
var B = require('../').Buffer
|
|
||||||
var test = require('tape')
|
|
||||||
|
|
||||||
test('base64: ignore whitespace', function (t) {
|
|
||||||
var text = '\n YW9ldQ== '
|
|
||||||
var buf = new B(text, 'base64')
|
|
||||||
t.equal(buf.toString(), 'aoeu')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('base64: strings without padding', function (t) {
|
|
||||||
t.equal((new B('YW9ldQ', 'base64').toString()), 'aoeu')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('base64: newline in utf8 -- should not be an issue', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B('LS0tCnRpdGxlOiBUaHJlZSBkYXNoZXMgbWFya3MgdGhlIHNwb3QKdGFnczoK', 'base64').toString('utf8'),
|
|
||||||
'---\ntitle: Three dashes marks the spot\ntags:\n'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('base64: newline in base64 -- should get stripped', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B('LS0tCnRpdGxlOiBUaHJlZSBkYXNoZXMgbWFya3MgdGhlIHNwb3QKdGFnczoK\nICAtIHlhbWwKICAtIGZyb250LW1hdHRlcgogIC0gZGFzaGVzCmV4cGFuZWQt', 'base64').toString('utf8'),
|
|
||||||
'---\ntitle: Three dashes marks the spot\ntags:\n - yaml\n - front-matter\n - dashes\nexpaned-'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('base64: tab characters in base64 - should get stripped', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B('LS0tCnRpdGxlOiBUaHJlZSBkYXNoZXMgbWFya3MgdGhlIHNwb3QKdGFnczoK\t\t\t\tICAtIHlhbWwKICAtIGZyb250LW1hdHRlcgogIC0gZGFzaGVzCmV4cGFuZWQt', 'base64').toString('utf8'),
|
|
||||||
'---\ntitle: Three dashes marks the spot\ntags:\n - yaml\n - front-matter\n - dashes\nexpaned-'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('base64: invalid non-alphanumeric characters -- should be stripped', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B('!"#$%&\'()*,.:;<=>?@[\\]^`{|}~', 'base64').toString('utf8'),
|
|
||||||
''
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
@ -1,91 +0,0 @@
|
|||||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
|
||||||
var B = require('../').Buffer
|
|
||||||
var test = require('tape')
|
|
||||||
|
|
||||||
test('buf.constructor is Buffer', function (t) {
|
|
||||||
var buf = new B([1, 2])
|
|
||||||
t.strictEqual(buf.constructor, B)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('instanceof Buffer', function (t) {
|
|
||||||
var buf = new B([1, 2])
|
|
||||||
t.ok(buf instanceof B)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('convert to Uint8Array in modern browsers', function (t) {
|
|
||||||
if (B.TYPED_ARRAY_SUPPORT) {
|
|
||||||
var buf = new B([1, 2])
|
|
||||||
var uint8array = new Uint8Array(buf.buffer)
|
|
||||||
t.ok(uint8array instanceof Uint8Array)
|
|
||||||
t.equal(uint8array[0], 1)
|
|
||||||
t.equal(uint8array[1], 2)
|
|
||||||
} else {
|
|
||||||
t.pass('object impl: skipping test')
|
|
||||||
}
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('indexes from a string', function (t) {
|
|
||||||
var buf = new B('abc')
|
|
||||||
t.equal(buf[0], 97)
|
|
||||||
t.equal(buf[1], 98)
|
|
||||||
t.equal(buf[2], 99)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('indexes from an array', function (t) {
|
|
||||||
var buf = new B([ 97, 98, 99 ])
|
|
||||||
t.equal(buf[0], 97)
|
|
||||||
t.equal(buf[1], 98)
|
|
||||||
t.equal(buf[2], 99)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('setting index value should modify buffer contents', function (t) {
|
|
||||||
var buf = new B([ 97, 98, 99 ])
|
|
||||||
t.equal(buf[2], 99)
|
|
||||||
t.equal(buf.toString(), 'abc')
|
|
||||||
|
|
||||||
buf[2] += 10
|
|
||||||
t.equal(buf[2], 109)
|
|
||||||
t.equal(buf.toString(), 'abm')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('storing negative number should cast to unsigned', function (t) {
|
|
||||||
var buf = new B(1)
|
|
||||||
|
|
||||||
if (B.TYPED_ARRAY_SUPPORT) {
|
|
||||||
// This does not work with the object implementation -- nothing we can do!
|
|
||||||
buf[0] = -3
|
|
||||||
t.equal(buf[0], 253)
|
|
||||||
}
|
|
||||||
|
|
||||||
buf = new B(1)
|
|
||||||
buf.writeInt8(-3, 0)
|
|
||||||
t.equal(buf[0], 253)
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('test that memory is copied from array-like', function (t) {
|
|
||||||
if (B.TYPED_ARRAY_SUPPORT) {
|
|
||||||
var u = new Uint8Array(4)
|
|
||||||
var b = new B(u)
|
|
||||||
b[0] = 1
|
|
||||||
b[1] = 2
|
|
||||||
b[2] = 3
|
|
||||||
b[3] = 4
|
|
||||||
|
|
||||||
t.equal(u[0], 0)
|
|
||||||
t.equal(u[1], 0)
|
|
||||||
t.equal(u[2], 0)
|
|
||||||
t.equal(u[3], 0)
|
|
||||||
} else {
|
|
||||||
t.pass('object impl: skipping test')
|
|
||||||
}
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
@ -1,59 +0,0 @@
|
|||||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
|
||||||
var B = require('../').Buffer
|
|
||||||
var test = require('tape')
|
|
||||||
|
|
||||||
test('buffer.compare', function (t) {
|
|
||||||
var b = new B(1).fill('a')
|
|
||||||
var c = new B(1).fill('c')
|
|
||||||
var d = new B(2).fill('aa')
|
|
||||||
|
|
||||||
t.equal(b.compare(c), -1)
|
|
||||||
t.equal(c.compare(d), 1)
|
|
||||||
t.equal(d.compare(b), 1)
|
|
||||||
t.equal(b.compare(d), -1)
|
|
||||||
|
|
||||||
// static method
|
|
||||||
t.equal(B.compare(b, c), -1)
|
|
||||||
t.equal(B.compare(c, d), 1)
|
|
||||||
t.equal(B.compare(d, b), 1)
|
|
||||||
t.equal(B.compare(b, d), -1)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('buffer.compare argument validation', function (t) {
|
|
||||||
t.throws(function () {
|
|
||||||
var b = new B(1)
|
|
||||||
B.compare(b, 'abc')
|
|
||||||
})
|
|
||||||
|
|
||||||
t.throws(function () {
|
|
||||||
var b = new B(1)
|
|
||||||
B.compare('abc', b)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.throws(function () {
|
|
||||||
var b = new B(1)
|
|
||||||
b.compare('abc')
|
|
||||||
})
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('buffer.equals', function (t) {
|
|
||||||
var b = new B(5).fill('abcdf')
|
|
||||||
var c = new B(5).fill('abcdf')
|
|
||||||
var d = new B(5).fill('abcde')
|
|
||||||
var e = new B(6).fill('abcdef')
|
|
||||||
|
|
||||||
t.ok(b.equals(c))
|
|
||||||
t.ok(!c.equals(d))
|
|
||||||
t.ok(!d.equals(e))
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('buffer.equals argument validation', function (t) {
|
|
||||||
t.throws(function () {
|
|
||||||
var b = new B(1)
|
|
||||||
b.equals('abc')
|
|
||||||
})
|
|
||||||
t.end()
|
|
||||||
})
|
|
@ -1,154 +0,0 @@
|
|||||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
|
||||||
var B = require('../').Buffer
|
|
||||||
var test = require('tape')
|
|
||||||
|
|
||||||
test('new buffer from array', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B([1, 2, 3]).toString(),
|
|
||||||
'\u0001\u0002\u0003'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('new buffer from array w/ negatives', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B([-1, -2, -3]).toString('hex'),
|
|
||||||
'fffefd'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('new buffer from array with mixed signed input', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B([-255, 255, -128, 128, 512, -512, 511, -511]).toString('hex'),
|
|
||||||
'01ff80800000ff01'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('new buffer from string', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B('hey', 'utf8').toString(),
|
|
||||||
'hey'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('new buffer from buffer', function (t) {
|
|
||||||
var b1 = new B('asdf')
|
|
||||||
var b2 = new B(b1)
|
|
||||||
t.equal(b1.toString('hex'), b2.toString('hex'))
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('new buffer from Uint8Array', function (t) {
|
|
||||||
if (typeof Uint8Array !== 'undefined') {
|
|
||||||
var b1 = new Uint8Array([0, 1, 2, 3])
|
|
||||||
var b2 = new B(b1)
|
|
||||||
t.equal(b1.length, b2.length)
|
|
||||||
t.equal(b1[0], 0)
|
|
||||||
t.equal(b1[1], 1)
|
|
||||||
t.equal(b1[2], 2)
|
|
||||||
t.equal(b1[3], 3)
|
|
||||||
t.equal(b1[4], undefined)
|
|
||||||
}
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('new buffer from Uint16Array', function (t) {
|
|
||||||
if (typeof Uint16Array !== 'undefined') {
|
|
||||||
var b1 = new Uint16Array([0, 1, 2, 3])
|
|
||||||
var b2 = new B(b1)
|
|
||||||
t.equal(b1.length, b2.length)
|
|
||||||
t.equal(b1[0], 0)
|
|
||||||
t.equal(b1[1], 1)
|
|
||||||
t.equal(b1[2], 2)
|
|
||||||
t.equal(b1[3], 3)
|
|
||||||
t.equal(b1[4], undefined)
|
|
||||||
}
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('new buffer from Uint32Array', function (t) {
|
|
||||||
if (typeof Uint32Array !== 'undefined') {
|
|
||||||
var b1 = new Uint32Array([0, 1, 2, 3])
|
|
||||||
var b2 = new B(b1)
|
|
||||||
t.equal(b1.length, b2.length)
|
|
||||||
t.equal(b1[0], 0)
|
|
||||||
t.equal(b1[1], 1)
|
|
||||||
t.equal(b1[2], 2)
|
|
||||||
t.equal(b1[3], 3)
|
|
||||||
t.equal(b1[4], undefined)
|
|
||||||
}
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('new buffer from Int16Array', function (t) {
|
|
||||||
if (typeof Int16Array !== 'undefined') {
|
|
||||||
var b1 = new Int16Array([0, 1, 2, 3])
|
|
||||||
var b2 = new B(b1)
|
|
||||||
t.equal(b1.length, b2.length)
|
|
||||||
t.equal(b1[0], 0)
|
|
||||||
t.equal(b1[1], 1)
|
|
||||||
t.equal(b1[2], 2)
|
|
||||||
t.equal(b1[3], 3)
|
|
||||||
t.equal(b1[4], undefined)
|
|
||||||
}
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('new buffer from Int32Array', function (t) {
|
|
||||||
if (typeof Int32Array !== 'undefined') {
|
|
||||||
var b1 = new Int32Array([0, 1, 2, 3])
|
|
||||||
var b2 = new B(b1)
|
|
||||||
t.equal(b1.length, b2.length)
|
|
||||||
t.equal(b1[0], 0)
|
|
||||||
t.equal(b1[1], 1)
|
|
||||||
t.equal(b1[2], 2)
|
|
||||||
t.equal(b1[3], 3)
|
|
||||||
t.equal(b1[4], undefined)
|
|
||||||
}
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('new buffer from Float32Array', function (t) {
|
|
||||||
if (typeof Float32Array !== 'undefined') {
|
|
||||||
var b1 = new Float32Array([0, 1, 2, 3])
|
|
||||||
var b2 = new B(b1)
|
|
||||||
t.equal(b1.length, b2.length)
|
|
||||||
t.equal(b1[0], 0)
|
|
||||||
t.equal(b1[1], 1)
|
|
||||||
t.equal(b1[2], 2)
|
|
||||||
t.equal(b1[3], 3)
|
|
||||||
t.equal(b1[4], undefined)
|
|
||||||
}
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('new buffer from Float64Array', function (t) {
|
|
||||||
if (typeof Float64Array !== 'undefined') {
|
|
||||||
var b1 = new Float64Array([0, 1, 2, 3])
|
|
||||||
var b2 = new B(b1)
|
|
||||||
t.equal(b1.length, b2.length)
|
|
||||||
t.equal(b1[0], 0)
|
|
||||||
t.equal(b1[1], 1)
|
|
||||||
t.equal(b1[2], 2)
|
|
||||||
t.equal(b1[3], 3)
|
|
||||||
t.equal(b1[4], undefined)
|
|
||||||
}
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('new buffer from buffer.toJSON() output', function (t) {
|
|
||||||
if (typeof JSON === 'undefined') {
|
|
||||||
// ie6, ie7 lack support
|
|
||||||
t.end()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var buf = new B('test')
|
|
||||||
var json = JSON.stringify(buf)
|
|
||||||
var obj = JSON.parse(json)
|
|
||||||
var copy = new B(obj)
|
|
||||||
t.ok(buf.equals(copy))
|
|
||||||
t.end()
|
|
||||||
})
|
|
@ -1,19 +0,0 @@
|
|||||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
|
||||||
var B = require('../').Buffer
|
|
||||||
var test = require('tape')
|
|
||||||
|
|
||||||
test('.get (deprecated)', function (t) {
|
|
||||||
var b = new B([7, 42])
|
|
||||||
t.equal(b.get(0), 7)
|
|
||||||
t.equal(b.get(1), 42)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('.set (deprecated)', function (t) {
|
|
||||||
var b = new B(2)
|
|
||||||
b.set(7, 0)
|
|
||||||
b.set(42, 1)
|
|
||||||
t.equal(b[0], 7)
|
|
||||||
t.equal(b[1], 42)
|
|
||||||
t.end()
|
|
||||||
})
|
|
@ -1,132 +0,0 @@
|
|||||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
|
||||||
var B = require('../').Buffer
|
|
||||||
var test = require('tape')
|
|
||||||
|
|
||||||
test('detect utf16 surrogate pairs', function (t) {
|
|
||||||
var text = '\uD83D\uDE38' + '\uD83D\uDCAD' + '\uD83D\uDC4D'
|
|
||||||
var buf = new B(text)
|
|
||||||
t.equal(text, buf.toString())
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('detect utf16 surrogate pairs over U+20000 until U+10FFFF', function (t) {
|
|
||||||
var text = '\uD842\uDFB7' + '\uD93D\uDCAD' + '\uDBFF\uDFFF'
|
|
||||||
var buf = new B(text)
|
|
||||||
t.equal(text, buf.toString())
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('replace orphaned utf16 surrogate lead code point', function (t) {
|
|
||||||
var text = '\uD83D\uDE38' + '\uD83D' + '\uD83D\uDC4D'
|
|
||||||
var buf = new B(text)
|
|
||||||
t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0xef, 0xbf, 0xbd, 0xf0, 0x9f, 0x91, 0x8d ]))
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('replace orphaned utf16 surrogate trail code point', function (t) {
|
|
||||||
var text = '\uD83D\uDE38' + '\uDCAD' + '\uD83D\uDC4D'
|
|
||||||
var buf = new B(text)
|
|
||||||
t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0xef, 0xbf, 0xbd, 0xf0, 0x9f, 0x91, 0x8d ]))
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('do not write partial utf16 code units', function (t) {
|
|
||||||
var f = new B([0, 0, 0, 0, 0])
|
|
||||||
t.equal(f.length, 5)
|
|
||||||
var size = f.write('あいうえお', 'utf16le')
|
|
||||||
t.equal(size, 4)
|
|
||||||
t.deepEqual(f, new B([0x42, 0x30, 0x44, 0x30, 0x00]))
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('handle partial utf16 code points when encoding to utf8 the way node does', function (t) {
|
|
||||||
var text = '\uD83D\uDE38' + '\uD83D\uDC4D'
|
|
||||||
|
|
||||||
var buf = new B(8)
|
|
||||||
buf.fill(0)
|
|
||||||
buf.write(text)
|
|
||||||
t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0xf0, 0x9f, 0x91, 0x8d ]))
|
|
||||||
|
|
||||||
buf = new B(7)
|
|
||||||
buf.fill(0)
|
|
||||||
buf.write(text)
|
|
||||||
t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0x00, 0x00, 0x00 ]))
|
|
||||||
|
|
||||||
buf = new B(6)
|
|
||||||
buf.fill(0)
|
|
||||||
buf.write(text)
|
|
||||||
t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0x00, 0x00 ]))
|
|
||||||
|
|
||||||
buf = new B(5)
|
|
||||||
buf.fill(0)
|
|
||||||
buf.write(text)
|
|
||||||
t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0x00 ]))
|
|
||||||
|
|
||||||
buf = new B(4)
|
|
||||||
buf.fill(0)
|
|
||||||
buf.write(text)
|
|
||||||
t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8 ]))
|
|
||||||
|
|
||||||
buf = new B(3)
|
|
||||||
buf.fill(0)
|
|
||||||
buf.write(text)
|
|
||||||
t.deepEqual(buf, new B([ 0x00, 0x00, 0x00 ]))
|
|
||||||
|
|
||||||
buf = new B(2)
|
|
||||||
buf.fill(0)
|
|
||||||
buf.write(text)
|
|
||||||
t.deepEqual(buf, new B([ 0x00, 0x00 ]))
|
|
||||||
|
|
||||||
buf = new B(1)
|
|
||||||
buf.fill(0)
|
|
||||||
buf.write(text)
|
|
||||||
t.deepEqual(buf, new B([ 0x00 ]))
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('handle invalid utf16 code points when encoding to utf8 the way node does', function (t) {
|
|
||||||
var text = 'a' + '\uDE38\uD83D' + 'b'
|
|
||||||
|
|
||||||
var buf = new B(8)
|
|
||||||
buf.fill(0)
|
|
||||||
buf.write(text)
|
|
||||||
t.deepEqual(buf, new B([ 0x61, 0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd, 0x62 ]))
|
|
||||||
|
|
||||||
buf = new B(7)
|
|
||||||
buf.fill(0)
|
|
||||||
buf.write(text)
|
|
||||||
t.deepEqual(buf, new B([ 0x61, 0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd ]))
|
|
||||||
|
|
||||||
buf = new B(6)
|
|
||||||
buf.fill(0)
|
|
||||||
buf.write(text)
|
|
||||||
t.deepEqual(buf, new B([ 0x61, 0xef, 0xbf, 0xbd, 0x00, 0x00 ]))
|
|
||||||
|
|
||||||
buf = new B(5)
|
|
||||||
buf.fill(0)
|
|
||||||
buf.write(text)
|
|
||||||
t.deepEqual(buf, new B([ 0x61, 0xef, 0xbf, 0xbd, 0x00 ]))
|
|
||||||
|
|
||||||
buf = new B(4)
|
|
||||||
buf.fill(0)
|
|
||||||
buf.write(text)
|
|
||||||
t.deepEqual(buf, new B([ 0x61, 0xef, 0xbf, 0xbd ]))
|
|
||||||
|
|
||||||
buf = new B(3)
|
|
||||||
buf.fill(0)
|
|
||||||
buf.write(text)
|
|
||||||
t.deepEqual(buf, new B([ 0x61, 0x00, 0x00 ]))
|
|
||||||
|
|
||||||
buf = new B(2)
|
|
||||||
buf.fill(0)
|
|
||||||
buf.write(text)
|
|
||||||
t.deepEqual(buf, new B([ 0x61, 0x00 ]))
|
|
||||||
|
|
||||||
buf = new B(1)
|
|
||||||
buf.fill(0)
|
|
||||||
buf.write(text)
|
|
||||||
t.deepEqual(buf, new B([ 0x61 ]))
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
@ -1,127 +0,0 @@
|
|||||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
|
||||||
var B = require('../').Buffer
|
|
||||||
var test = require('tape')
|
|
||||||
|
|
||||||
test('buffer.toJSON', function (t) {
|
|
||||||
var data = [1, 2, 3, 4]
|
|
||||||
t.deepEqual(
|
|
||||||
new B(data).toJSON(),
|
|
||||||
{ type: 'Buffer', data: [ 1, 2, 3, 4 ] }
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('buffer.copy', function (t) {
|
|
||||||
// copied from nodejs.org example
|
|
||||||
var buf1 = new B(26)
|
|
||||||
var buf2 = new B(26)
|
|
||||||
|
|
||||||
for (var i = 0; i < 26; i++) {
|
|
||||||
buf1[i] = i + 97 // 97 is ASCII a
|
|
||||||
buf2[i] = 33 // ASCII !
|
|
||||||
}
|
|
||||||
|
|
||||||
buf1.copy(buf2, 8, 16, 20)
|
|
||||||
|
|
||||||
t.equal(
|
|
||||||
buf2.toString('ascii', 0, 25),
|
|
||||||
'!!!!!!!!qrst!!!!!!!!!!!!!'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('test offset returns are correct', function (t) {
|
|
||||||
var b = new B(16)
|
|
||||||
t.equal(4, b.writeUInt32LE(0, 0))
|
|
||||||
t.equal(6, b.writeUInt16LE(0, 4))
|
|
||||||
t.equal(7, b.writeUInt8(0, 6))
|
|
||||||
t.equal(8, b.writeInt8(0, 7))
|
|
||||||
t.equal(16, b.writeDoubleLE(0, 8))
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('concat() a varying number of buffers', function (t) {
|
|
||||||
var zero = []
|
|
||||||
var one = [ new B('asdf') ]
|
|
||||||
var long = []
|
|
||||||
for (var i = 0; i < 10; i++) {
|
|
||||||
long.push(new B('asdf'))
|
|
||||||
}
|
|
||||||
|
|
||||||
var flatZero = B.concat(zero)
|
|
||||||
var flatOne = B.concat(one)
|
|
||||||
var flatLong = B.concat(long)
|
|
||||||
var flatLongLen = B.concat(long, 40)
|
|
||||||
|
|
||||||
t.equal(flatZero.length, 0)
|
|
||||||
t.equal(flatOne.toString(), 'asdf')
|
|
||||||
t.deepEqual(flatOne, one[0])
|
|
||||||
t.equal(flatLong.toString(), (new Array(10 + 1).join('asdf')))
|
|
||||||
t.equal(flatLongLen.toString(), (new Array(10 + 1).join('asdf')))
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('fill', function (t) {
|
|
||||||
var b = new B(10)
|
|
||||||
b.fill(2)
|
|
||||||
t.equal(b.toString('hex'), '02020202020202020202')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('fill (string)', function (t) {
|
|
||||||
var b = new B(10)
|
|
||||||
b.fill('abc')
|
|
||||||
t.equal(b.toString(), 'abcabcabca')
|
|
||||||
b.fill('է')
|
|
||||||
t.equal(b.toString(), 'էէէէէ')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('copy() empty buffer with sourceEnd=0', function (t) {
|
|
||||||
var source = new B([42])
|
|
||||||
var destination = new B([43])
|
|
||||||
source.copy(destination, 0, 0, 0)
|
|
||||||
t.equal(destination.readUInt8(0), 43)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('copy() after slice()', function (t) {
|
|
||||||
var source = new B(200)
|
|
||||||
var dest = new B(200)
|
|
||||||
var expected = new B(200)
|
|
||||||
for (var i = 0; i < 200; i++) {
|
|
||||||
source[i] = i
|
|
||||||
dest[i] = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
source.slice(2).copy(dest)
|
|
||||||
source.copy(expected, 0, 2)
|
|
||||||
t.deepEqual(dest, expected)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('copy() ascending', function (t) {
|
|
||||||
var b = new B('abcdefghij')
|
|
||||||
b.copy(b, 0, 3, 10)
|
|
||||||
t.equal(b.toString(), 'defghijhij')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('copy() descending', function (t) {
|
|
||||||
var b = new B('abcdefghij')
|
|
||||||
b.copy(b, 3, 0, 7)
|
|
||||||
t.equal(b.toString(), 'abcabcdefg')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('buffer.slice sets indexes', function (t) {
|
|
||||||
t.equal((new B('hallo')).slice(0, 5).toString(), 'hallo')
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('buffer.slice out of range', function (t) {
|
|
||||||
t.plan(2)
|
|
||||||
t.equal((new B('hallo')).slice(0, 10).toString(), 'hallo')
|
|
||||||
t.equal((new B('hallo')).slice(10, 2).toString(), '')
|
|
||||||
t.end()
|
|
||||||
})
|
|
@ -1 +0,0 @@
|
|||||||
node buffer tests that require ES6 (e.g. "for..of" construct)
|
|
@ -1,49 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false;
|
|
||||||
var Buffer = require('../../').Buffer;
|
|
||||||
|
|
||||||
var common = {};
|
|
||||||
var assert = require('assert');
|
|
||||||
|
|
||||||
var Buffer = require('../../').Buffer;
|
|
||||||
var LENGTH = 16;
|
|
||||||
|
|
||||||
var ab = new ArrayBuffer(LENGTH);
|
|
||||||
var dv = new DataView(ab);
|
|
||||||
var ui = new Uint8Array(ab);
|
|
||||||
var buf = new Buffer(ab);
|
|
||||||
|
|
||||||
|
|
||||||
assert.ok(Buffer.isBuffer(buf));
|
|
||||||
// For backwards compatibility of old .parent property test that if buf is not
|
|
||||||
// a slice then .parent should be undefined.
|
|
||||||
assert.equal(buf.parent, undefined);
|
|
||||||
assert.equal(buf.buffer, ab);
|
|
||||||
assert.equal(buf.length, ab.byteLength);
|
|
||||||
|
|
||||||
|
|
||||||
buf.fill(0xC);
|
|
||||||
for (var i = 0; i < LENGTH; i++) {
|
|
||||||
assert.equal(ui[i], 0xC);
|
|
||||||
ui[i] = 0xF;
|
|
||||||
assert.equal(buf[i], 0xF);
|
|
||||||
}
|
|
||||||
|
|
||||||
buf.writeUInt32LE(0xF00, 0);
|
|
||||||
buf.writeUInt32BE(0xB47, 4);
|
|
||||||
buf.writeDoubleLE(3.1415, 8);
|
|
||||||
|
|
||||||
assert.equal(dv.getUint32(0, true), 0xF00);
|
|
||||||
assert.equal(dv.getUint32(4), 0xB47);
|
|
||||||
assert.equal(dv.getFloat64(8, true), 3.1415);
|
|
||||||
|
|
||||||
|
|
||||||
// Now test protecting users from doing stupid things
|
|
||||||
|
|
||||||
assert.throws(function() {
|
|
||||||
function AB() { }
|
|
||||||
AB.__proto__ = ArrayBuffer;
|
|
||||||
AB.prototype.__proto__ = ArrayBuffer.prototype;
|
|
||||||
new Buffer(new AB());
|
|
||||||
}, TypeError);
|
|
||||||
|
|
@ -1,65 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false;
|
|
||||||
var Buffer = require('../../').Buffer;
|
|
||||||
var common = {};
|
|
||||||
var assert = require('assert');
|
|
||||||
|
|
||||||
var buffer = new Buffer([1, 2, 3, 4, 5]);
|
|
||||||
var arr;
|
|
||||||
var b;
|
|
||||||
|
|
||||||
// buffers should be iterable
|
|
||||||
|
|
||||||
arr = [];
|
|
||||||
|
|
||||||
for (b of buffer)
|
|
||||||
arr.push(b);
|
|
||||||
|
|
||||||
assert.deepEqual(arr, [1, 2, 3, 4, 5]);
|
|
||||||
|
|
||||||
|
|
||||||
// buffer iterators should be iterable
|
|
||||||
|
|
||||||
arr = [];
|
|
||||||
|
|
||||||
for (b of buffer[Symbol.iterator]())
|
|
||||||
arr.push(b);
|
|
||||||
|
|
||||||
assert.deepEqual(arr, [1, 2, 3, 4, 5]);
|
|
||||||
|
|
||||||
|
|
||||||
// buffer#values() should return iterator for values
|
|
||||||
|
|
||||||
arr = [];
|
|
||||||
|
|
||||||
for (b of buffer.values())
|
|
||||||
arr.push(b);
|
|
||||||
|
|
||||||
assert.deepEqual(arr, [1, 2, 3, 4, 5]);
|
|
||||||
|
|
||||||
|
|
||||||
// buffer#keys() should return iterator for keys
|
|
||||||
|
|
||||||
arr = [];
|
|
||||||
|
|
||||||
for (b of buffer.keys())
|
|
||||||
arr.push(b);
|
|
||||||
|
|
||||||
assert.deepEqual(arr, [0, 1, 2, 3, 4]);
|
|
||||||
|
|
||||||
|
|
||||||
// buffer#entries() should return iterator for entries
|
|
||||||
|
|
||||||
arr = [];
|
|
||||||
|
|
||||||
for (var b of buffer.entries())
|
|
||||||
arr.push(b);
|
|
||||||
|
|
||||||
assert.deepEqual(arr, [
|
|
||||||
[0, 1],
|
|
||||||
[1, 2],
|
|
||||||
[2, 3],
|
|
||||||
[3, 4],
|
|
||||||
[4, 5]
|
|
||||||
]);
|
|
||||||
|
|
@ -1 +0,0 @@
|
|||||||
node core buffer tests
|
|
@ -1,49 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false;
|
|
||||||
var Buffer = require('../../').Buffer;
|
|
||||||
|
|
||||||
var common = {};
|
|
||||||
var assert = require('assert');
|
|
||||||
var Buffer = require('../../').Buffer;
|
|
||||||
|
|
||||||
// coerce values to string
|
|
||||||
assert.equal(Buffer.byteLength(32, 'raw'), 2);
|
|
||||||
assert.equal(Buffer.byteLength(NaN, 'utf8'), 3);
|
|
||||||
assert.equal(Buffer.byteLength({}, 'raws'), 15);
|
|
||||||
assert.equal(Buffer.byteLength(), 9);
|
|
||||||
|
|
||||||
// special case: zero length string
|
|
||||||
assert.equal(Buffer.byteLength('', 'ascii'), 0);
|
|
||||||
assert.equal(Buffer.byteLength('', 'HeX'), 0);
|
|
||||||
|
|
||||||
// utf8
|
|
||||||
assert.equal(Buffer.byteLength('∑éllö wørl∂!', 'utf-8'), 19);
|
|
||||||
assert.equal(Buffer.byteLength('κλμνξο', 'utf8'), 12);
|
|
||||||
assert.equal(Buffer.byteLength('挵挶挷挸挹', 'utf-8'), 15);
|
|
||||||
assert.equal(Buffer.byteLength('𠝹𠱓𠱸', 'UTF8'), 12);
|
|
||||||
// without an encoding, utf8 should be assumed
|
|
||||||
assert.equal(Buffer.byteLength('hey there'), 9);
|
|
||||||
assert.equal(Buffer.byteLength('𠱸挶νξ#xx :)'), 17);
|
|
||||||
assert.equal(Buffer.byteLength('hello world', ''), 11);
|
|
||||||
// it should also be assumed with unrecognized encoding
|
|
||||||
assert.equal(Buffer.byteLength('hello world', 'abc'), 11);
|
|
||||||
assert.equal(Buffer.byteLength('ßœ∑≈', 'unkn0wn enc0ding'), 10);
|
|
||||||
|
|
||||||
// base64
|
|
||||||
assert.equal(Buffer.byteLength('aGVsbG8gd29ybGQ=', 'base64'), 11);
|
|
||||||
assert.equal(Buffer.byteLength('bm9kZS5qcyByb2NrcyE=', 'base64'), 14);
|
|
||||||
assert.equal(Buffer.byteLength('aGkk', 'base64'), 3);
|
|
||||||
assert.equal(Buffer.byteLength('bHNrZGZsa3NqZmtsc2xrZmFqc2RsZmtqcw==',
|
|
||||||
'base64'), 25);
|
|
||||||
// special padding
|
|
||||||
assert.equal(Buffer.byteLength('aaa=', 'base64'), 2);
|
|
||||||
assert.equal(Buffer.byteLength('aaaa==', 'base64'), 3);
|
|
||||||
|
|
||||||
assert.equal(Buffer.byteLength('Il était tué'), 14);
|
|
||||||
assert.equal(Buffer.byteLength('Il était tué', 'utf8'), 14);
|
|
||||||
assert.equal(Buffer.byteLength('Il était tué', 'ascii'), 12);
|
|
||||||
assert.equal(Buffer.byteLength('Il était tué', 'binary'), 12);
|
|
||||||
['ucs2', 'ucs-2', 'utf16le', 'utf-16le'].forEach(function(encoding) {
|
|
||||||
assert.equal(24, Buffer.byteLength('Il était tué', encoding));
|
|
||||||
});
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false;
|
|
||||||
var Buffer = require('../../').Buffer;
|
|
||||||
var common = {};
|
|
||||||
var assert = require('assert');
|
|
||||||
|
|
||||||
var zero = [];
|
|
||||||
var one = [ new Buffer('asdf') ];
|
|
||||||
var long = [];
|
|
||||||
for (var i = 0; i < 10; i++) long.push(new Buffer('asdf'));
|
|
||||||
|
|
||||||
var flatZero = Buffer.concat(zero);
|
|
||||||
var flatOne = Buffer.concat(one);
|
|
||||||
var flatLong = Buffer.concat(long);
|
|
||||||
var flatLongLen = Buffer.concat(long, 40);
|
|
||||||
|
|
||||||
assert(flatZero.length === 0);
|
|
||||||
assert(flatOne.toString() === 'asdf');
|
|
||||||
// A special case where concat used to return the first item,
|
|
||||||
// if the length is one. This check is to make sure that we don't do that.
|
|
||||||
assert(flatOne !== one[0]);
|
|
||||||
assert(flatLong.toString() === (new Array(10 + 1).join('asdf')));
|
|
||||||
assert(flatLongLen.toString() === (new Array(10 + 1).join('asdf')));
|
|
||||||
|
|
||||||
assert.throws(function() {
|
|
||||||
Buffer.concat([42]);
|
|
||||||
}, TypeError);
|
|
||||||
|
|
||||||
// console.log('ok');
|
|
||||||
|
|
@ -1,79 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false;
|
|
||||||
var Buffer = require('../../').Buffer;
|
|
||||||
var common = {};
|
|
||||||
var assert = require('assert');
|
|
||||||
|
|
||||||
var Buffer = require('../../').Buffer;
|
|
||||||
|
|
||||||
var b = new Buffer('abcdef');
|
|
||||||
var buf_a = new Buffer('a');
|
|
||||||
var buf_bc = new Buffer('bc');
|
|
||||||
var buf_f = new Buffer('f');
|
|
||||||
var buf_z = new Buffer('z');
|
|
||||||
var buf_empty = new Buffer('');
|
|
||||||
|
|
||||||
assert.equal(b.indexOf('a'), 0);
|
|
||||||
assert.equal(b.indexOf('a', 1), -1);
|
|
||||||
assert.equal(b.indexOf('a', -1), -1);
|
|
||||||
assert.equal(b.indexOf('a', -4), -1);
|
|
||||||
assert.equal(b.indexOf('a', -b.length), 0);
|
|
||||||
assert.equal(b.indexOf('a', NaN), 0);
|
|
||||||
assert.equal(b.indexOf('a', -Infinity), 0);
|
|
||||||
assert.equal(b.indexOf('a', Infinity), -1);
|
|
||||||
assert.equal(b.indexOf('bc'), 1);
|
|
||||||
assert.equal(b.indexOf('bc', 2), -1);
|
|
||||||
assert.equal(b.indexOf('bc', -1), -1);
|
|
||||||
assert.equal(b.indexOf('bc', -3), -1);
|
|
||||||
assert.equal(b.indexOf('bc', -5), 1);
|
|
||||||
assert.equal(b.indexOf('bc', NaN), 1);
|
|
||||||
assert.equal(b.indexOf('bc', -Infinity), 1);
|
|
||||||
assert.equal(b.indexOf('bc', Infinity), -1);
|
|
||||||
assert.equal(b.indexOf('f'), b.length - 1);
|
|
||||||
assert.equal(b.indexOf('z'), -1);
|
|
||||||
assert.equal(b.indexOf(''), -1);
|
|
||||||
assert.equal(b.indexOf('', 1), -1);
|
|
||||||
assert.equal(b.indexOf('', b.length + 1), -1);
|
|
||||||
assert.equal(b.indexOf('', Infinity), -1);
|
|
||||||
assert.equal(b.indexOf(buf_a), 0);
|
|
||||||
assert.equal(b.indexOf(buf_a, 1), -1);
|
|
||||||
assert.equal(b.indexOf(buf_a, -1), -1);
|
|
||||||
assert.equal(b.indexOf(buf_a, -4), -1);
|
|
||||||
assert.equal(b.indexOf(buf_a, -b.length), 0);
|
|
||||||
assert.equal(b.indexOf(buf_a, NaN), 0);
|
|
||||||
assert.equal(b.indexOf(buf_a, -Infinity), 0);
|
|
||||||
assert.equal(b.indexOf(buf_a, Infinity), -1);
|
|
||||||
assert.equal(b.indexOf(buf_bc), 1);
|
|
||||||
assert.equal(b.indexOf(buf_bc, 2), -1);
|
|
||||||
assert.equal(b.indexOf(buf_bc, -1), -1);
|
|
||||||
assert.equal(b.indexOf(buf_bc, -3), -1);
|
|
||||||
assert.equal(b.indexOf(buf_bc, -5), 1);
|
|
||||||
assert.equal(b.indexOf(buf_bc, NaN), 1);
|
|
||||||
assert.equal(b.indexOf(buf_bc, -Infinity), 1);
|
|
||||||
assert.equal(b.indexOf(buf_bc, Infinity), -1);
|
|
||||||
assert.equal(b.indexOf(buf_f), b.length - 1);
|
|
||||||
assert.equal(b.indexOf(buf_z), -1);
|
|
||||||
assert.equal(b.indexOf(buf_empty), -1);
|
|
||||||
assert.equal(b.indexOf(buf_empty, 1), -1);
|
|
||||||
assert.equal(b.indexOf(buf_empty, b.length + 1), -1);
|
|
||||||
assert.equal(b.indexOf(buf_empty, Infinity), -1);
|
|
||||||
assert.equal(b.indexOf(0x61), 0);
|
|
||||||
assert.equal(b.indexOf(0x61, 1), -1);
|
|
||||||
assert.equal(b.indexOf(0x61, -1), -1);
|
|
||||||
assert.equal(b.indexOf(0x61, -4), -1);
|
|
||||||
assert.equal(b.indexOf(0x61, -b.length), 0);
|
|
||||||
assert.equal(b.indexOf(0x61, NaN), 0);
|
|
||||||
assert.equal(b.indexOf(0x61, -Infinity), 0);
|
|
||||||
assert.equal(b.indexOf(0x61, Infinity), -1);
|
|
||||||
assert.equal(b.indexOf(0x0), -1);
|
|
||||||
|
|
||||||
assert.throws(function() {
|
|
||||||
b.indexOf(function() { });
|
|
||||||
});
|
|
||||||
assert.throws(function() {
|
|
||||||
b.indexOf({});
|
|
||||||
});
|
|
||||||
assert.throws(function() {
|
|
||||||
b.indexOf([]);
|
|
||||||
});
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false;
|
|
||||||
var Buffer = require('../../').Buffer;
|
|
||||||
var common = {};
|
|
||||||
var assert = require('assert');
|
|
||||||
|
|
||||||
var util = require('util');
|
|
||||||
|
|
||||||
var buffer = require('../../');
|
|
||||||
|
|
||||||
buffer.INSPECT_MAX_BYTES = 2;
|
|
||||||
|
|
||||||
var b = new Buffer(4);
|
|
||||||
b.fill('1234');
|
|
||||||
|
|
||||||
var s = new buffer.SlowBuffer(4);
|
|
||||||
s.fill('1234');
|
|
||||||
|
|
||||||
var expected = '<Buffer 31 32 ... >';
|
|
||||||
|
|
||||||
assert.strictEqual(util.inspect(b), expected);
|
|
||||||
assert.strictEqual(util.inspect(s), expected);
|
|
||||||
|
|
||||||
b = new Buffer(2);
|
|
||||||
b.fill('12');
|
|
||||||
|
|
||||||
s = new buffer.SlowBuffer(2);
|
|
||||||
s.fill('12');
|
|
||||||
|
|
||||||
expected = '<Buffer 31 32>';
|
|
||||||
|
|
||||||
assert.strictEqual(util.inspect(b), expected);
|
|
||||||
assert.strictEqual(util.inspect(s), expected);
|
|
||||||
|
|
||||||
buffer.INSPECT_MAX_BYTES = Infinity;
|
|
||||||
|
|
||||||
assert.doesNotThrow(function() {
|
|
||||||
assert.strictEqual(util.inspect(b), expected);
|
|
||||||
assert.strictEqual(util.inspect(s), expected);
|
|
||||||
});
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
@ -1,37 +0,0 @@
|
|||||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
|
||||||
var B = require('../').Buffer
|
|
||||||
var test = require('tape')
|
|
||||||
|
|
||||||
test('modifying buffer created by .slice() modifies original memory', function (t) {
|
|
||||||
if (!B.TYPED_ARRAY_SUPPORT) return t.end()
|
|
||||||
|
|
||||||
var buf1 = new B(26)
|
|
||||||
for (var i = 0; i < 26; i++) {
|
|
||||||
buf1[i] = i + 97 // 97 is ASCII a
|
|
||||||
}
|
|
||||||
|
|
||||||
var buf2 = buf1.slice(0, 3)
|
|
||||||
t.equal(buf2.toString('ascii', 0, buf2.length), 'abc')
|
|
||||||
|
|
||||||
buf2[0] = '!'.charCodeAt(0)
|
|
||||||
t.equal(buf1.toString('ascii', 0, buf2.length), '!bc')
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('modifying parent buffer modifies .slice() buffer\'s memory', function (t) {
|
|
||||||
if (!B.TYPED_ARRAY_SUPPORT) return t.end()
|
|
||||||
|
|
||||||
var buf1 = new B(26)
|
|
||||||
for (var i = 0; i < 26; i++) {
|
|
||||||
buf1[i] = i + 97 // 97 is ASCII a
|
|
||||||
}
|
|
||||||
|
|
||||||
var buf2 = buf1.slice(0, 3)
|
|
||||||
t.equal(buf2.toString('ascii', 0, buf2.length), 'abc')
|
|
||||||
|
|
||||||
buf1[0] = '!'.charCodeAt(0)
|
|
||||||
t.equal(buf2.toString('ascii', 0, buf2.length), '!bc')
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
@ -1,31 +0,0 @@
|
|||||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
|
||||||
var B = require('../').Buffer
|
|
||||||
var test = require('tape')
|
|
||||||
|
|
||||||
test('Buffer.isEncoding', function (t) {
|
|
||||||
t.equal(B.isEncoding('HEX'), true)
|
|
||||||
t.equal(B.isEncoding('hex'), true)
|
|
||||||
t.equal(B.isEncoding('bad'), false)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('Buffer.isBuffer', function (t) {
|
|
||||||
t.equal(B.isBuffer(new B('hey', 'utf8')), true)
|
|
||||||
t.equal(B.isBuffer(new B([1, 2, 3], 'utf8')), true)
|
|
||||||
t.equal(B.isBuffer('hey'), false)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('Buffer.toArrayBuffer', function (t) {
|
|
||||||
var data = [1, 2, 3, 4, 5, 6, 7, 8]
|
|
||||||
if (typeof Uint8Array !== 'undefined') {
|
|
||||||
var result = new B(data).toArrayBuffer()
|
|
||||||
var expected = new Uint8Array(data).buffer
|
|
||||||
for (var i = 0; i < expected.byteLength; i++) {
|
|
||||||
t.equal(result[i], expected[i])
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
t.pass('No toArrayBuffer() method provided in old browsers')
|
|
||||||
}
|
|
||||||
t.end()
|
|
||||||
})
|
|
@ -1,233 +0,0 @@
|
|||||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
|
||||||
var B = require('../').Buffer
|
|
||||||
var test = require('tape')
|
|
||||||
|
|
||||||
test('utf8 buffer to base64', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B('Ձאab', 'utf8').toString('base64'),
|
|
||||||
'1YHXkGFi'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('utf8 buffer to hex', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B('Ձאab', 'utf8').toString('hex'),
|
|
||||||
'd581d7906162'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('utf8 to utf8', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B('öäüõÖÄÜÕ', 'utf8').toString('utf8'),
|
|
||||||
'öäüõÖÄÜÕ'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('utf16le to utf16', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B(new B('abcd', 'utf8').toString('utf16le'), 'utf16le').toString('utf8'),
|
|
||||||
'abcd'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('utf16le to hex', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B('abcd', 'utf16le').toString('hex'),
|
|
||||||
'6100620063006400'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('ascii buffer to base64', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B('123456!@#$%^', 'ascii').toString('base64'),
|
|
||||||
'MTIzNDU2IUAjJCVe'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('ascii buffer to hex', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B('123456!@#$%^', 'ascii').toString('hex'),
|
|
||||||
'31323334353621402324255e'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('base64 buffer to utf8', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B('1YHXkGFi', 'base64').toString('utf8'),
|
|
||||||
'Ձאab'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('hex buffer to utf8', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B('d581d7906162', 'hex').toString('utf8'),
|
|
||||||
'Ձאab'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('base64 buffer to ascii', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B('MTIzNDU2IUAjJCVe', 'base64').toString('ascii'),
|
|
||||||
'123456!@#$%^'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('hex buffer to ascii', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B('31323334353621402324255e', 'hex').toString('ascii'),
|
|
||||||
'123456!@#$%^'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('base64 buffer to binary', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B('MTIzNDU2IUAjJCVe', 'base64').toString('binary'),
|
|
||||||
'123456!@#$%^'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('hex buffer to binary', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B('31323334353621402324255e', 'hex').toString('binary'),
|
|
||||||
'123456!@#$%^'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('utf8 to binary', function (t) {
|
|
||||||
/* jshint -W100 */
|
|
||||||
t.equal(
|
|
||||||
new B('öäüõÖÄÜÕ', 'utf8').toString('binary'),
|
|
||||||
'öäüõÃÃÃÃ'
|
|
||||||
)
|
|
||||||
/* jshint +W100 */
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('utf8 replacement chars (1 byte sequence)', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B([ 0x80 ]).toString(),
|
|
||||||
'\uFFFD'
|
|
||||||
)
|
|
||||||
t.equal(
|
|
||||||
new B([ 0x7F ]).toString(),
|
|
||||||
'\u007F'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('utf8 replacement chars (2 byte sequences)', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B([ 0xC7 ]).toString(),
|
|
||||||
'\uFFFD'
|
|
||||||
)
|
|
||||||
t.equal(
|
|
||||||
new B([ 0xC7, 0xB1 ]).toString(),
|
|
||||||
'\u01F1'
|
|
||||||
)
|
|
||||||
t.equal(
|
|
||||||
new B([ 0xC0, 0xB1 ]).toString(),
|
|
||||||
'\uFFFD\uFFFD'
|
|
||||||
)
|
|
||||||
t.equal(
|
|
||||||
new B([ 0xC1, 0xB1 ]).toString(),
|
|
||||||
'\uFFFD\uFFFD'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('utf8 replacement chars (3 byte sequences)', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B([ 0xE0 ]).toString(),
|
|
||||||
'\uFFFD'
|
|
||||||
)
|
|
||||||
t.equal(
|
|
||||||
new B([ 0xE0, 0xAC ]).toString(),
|
|
||||||
'\uFFFD\uFFFD'
|
|
||||||
)
|
|
||||||
t.equal(
|
|
||||||
new B([ 0xE0, 0xAC, 0xB9 ]).toString(),
|
|
||||||
'\u0B39'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('utf8 replacement chars (4 byte sequences)', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B([ 0xF4 ]).toString(),
|
|
||||||
'\uFFFD'
|
|
||||||
)
|
|
||||||
t.equal(
|
|
||||||
new B([ 0xF4, 0x8F ]).toString(),
|
|
||||||
'\uFFFD\uFFFD'
|
|
||||||
)
|
|
||||||
t.equal(
|
|
||||||
new B([ 0xF4, 0x8F, 0x80 ]).toString(),
|
|
||||||
'\uFFFD\uFFFD\uFFFD'
|
|
||||||
)
|
|
||||||
t.equal(
|
|
||||||
new B([ 0xF4, 0x8F, 0x80, 0x84 ]).toString(),
|
|
||||||
'\uDBFC\uDC04'
|
|
||||||
)
|
|
||||||
t.equal(
|
|
||||||
new B([ 0xFF ]).toString(),
|
|
||||||
'\uFFFD'
|
|
||||||
)
|
|
||||||
t.equal(
|
|
||||||
new B([ 0xFF, 0x8F, 0x80, 0x84 ]).toString(),
|
|
||||||
'\uFFFD\uFFFD\uFFFD\uFFFD'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('utf8 replacement chars on 256 random bytes', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B([ 152, 130, 206, 23, 243, 238, 197, 44, 27, 86, 208, 36, 163, 184, 164, 21, 94, 242, 178, 46, 25, 26, 253, 178, 72, 147, 207, 112, 236, 68, 179, 190, 29, 83, 239, 147, 125, 55, 143, 19, 157, 68, 157, 58, 212, 224, 150, 39, 128, 24, 94, 225, 120, 121, 75, 192, 112, 19, 184, 142, 203, 36, 43, 85, 26, 147, 227, 139, 242, 186, 57, 78, 11, 102, 136, 117, 180, 210, 241, 92, 3, 215, 54, 167, 249, 1, 44, 225, 146, 86, 2, 42, 68, 21, 47, 238, 204, 153, 216, 252, 183, 66, 222, 255, 15, 202, 16, 51, 134, 1, 17, 19, 209, 76, 238, 38, 76, 19, 7, 103, 249, 5, 107, 137, 64, 62, 170, 57, 16, 85, 179, 193, 97, 86, 166, 196, 36, 148, 138, 193, 210, 69, 187, 38, 242, 97, 195, 219, 252, 244, 38, 1, 197, 18, 31, 246, 53, 47, 134, 52, 105, 72, 43, 239, 128, 203, 73, 93, 199, 75, 222, 220, 166, 34, 63, 236, 11, 212, 76, 243, 171, 110, 78, 39, 205, 204, 6, 177, 233, 212, 243, 0, 33, 41, 122, 118, 92, 252, 0, 157, 108, 120, 70, 137, 100, 223, 243, 171, 232, 66, 126, 111, 142, 33, 3, 39, 117, 27, 107, 54, 1, 217, 227, 132, 13, 166, 3, 73, 53, 127, 225, 236, 134, 219, 98, 214, 125, 148, 24, 64, 142, 111, 231, 194, 42, 150, 185, 10, 182, 163, 244, 19, 4, 59, 135, 16 ]).toString(),
|
|
||||||
'\uFFFD\uFFFD\uFFFD\u0017\uFFFD\uFFFD\uFFFD\u002C\u001B\u0056\uFFFD\u0024\uFFFD\uFFFD\uFFFD\u0015\u005E\uFFFD\uFFFD\u002E\u0019\u001A\uFFFD\uFFFD\u0048\uFFFD\uFFFD\u0070\uFFFD\u0044\uFFFD\uFFFD\u001D\u0053\uFFFD\uFFFD\u007D\u0037\uFFFD\u0013\uFFFD\u0044\uFFFD\u003A\uFFFD\uFFFD\uFFFD\u0027\uFFFD\u0018\u005E\uFFFD\u0078\u0079\u004B\uFFFD\u0070\u0013\uFFFD\uFFFD\uFFFD\u0024\u002B\u0055\u001A\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u0039\u004E\u000B\u0066\uFFFD\u0075\uFFFD\uFFFD\uFFFD\u005C\u0003\uFFFD\u0036\uFFFD\uFFFD\u0001\u002C\uFFFD\uFFFD\u0056\u0002\u002A\u0044\u0015\u002F\uFFFD\u0319\uFFFD\uFFFD\uFFFD\u0042\uFFFD\uFFFD\u000F\uFFFD\u0010\u0033\uFFFD\u0001\u0011\u0013\uFFFD\u004C\uFFFD\u0026\u004C\u0013\u0007\u0067\uFFFD\u0005\u006B\uFFFD\u0040\u003E\uFFFD\u0039\u0010\u0055\uFFFD\uFFFD\u0061\u0056\uFFFD\uFFFD\u0024\uFFFD\uFFFD\uFFFD\uFFFD\u0045\uFFFD\u0026\uFFFD\u0061\uFFFD\uFFFD\uFFFD\uFFFD\u0026\u0001\uFFFD\u0012\u001F\uFFFD\u0035\u002F\uFFFD\u0034\u0069\u0048\u002B\uFFFD\uFFFD\uFFFD\u0049\u005D\uFFFD\u004B\uFFFD\u0726\u0022\u003F\uFFFD\u000B\uFFFD\u004C\uFFFD\uFFFD\u006E\u004E\u0027\uFFFD\uFFFD\u0006\uFFFD\uFFFD\uFFFD\uFFFD\u0000\u0021\u0029\u007A\u0076\u005C\uFFFD\u0000\uFFFD\u006C\u0078\u0046\uFFFD\u0064\uFFFD\uFFFD\uFFFD\uFFFD\u0042\u007E\u006F\uFFFD\u0021\u0003\u0027\u0075\u001B\u006B\u0036\u0001\uFFFD\uFFFD\uFFFD\u000D\uFFFD\u0003\u0049\u0035\u007F\uFFFD\uFFFD\uFFFD\uFFFD\u0062\uFFFD\u007D\uFFFD\u0018\u0040\uFFFD\u006F\uFFFD\uFFFD\u002A\uFFFD\uFFFD\u000A\uFFFD\uFFFD\uFFFD\u0013\u0004\u003B\uFFFD\u0010'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('utf8 replacement chars for anything in the surrogate pair range', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B([ 0xED, 0x9F, 0xBF ]).toString(),
|
|
||||||
'\uD7FF'
|
|
||||||
)
|
|
||||||
t.equal(
|
|
||||||
new B([ 0xED, 0xA0, 0x80 ]).toString(),
|
|
||||||
'\uFFFD\uFFFD\uFFFD'
|
|
||||||
)
|
|
||||||
t.equal(
|
|
||||||
new B([ 0xED, 0xBE, 0x8B ]).toString(),
|
|
||||||
'\uFFFD\uFFFD\uFFFD'
|
|
||||||
)
|
|
||||||
t.equal(
|
|
||||||
new B([ 0xED, 0xBF, 0xBF ]).toString(),
|
|
||||||
'\uFFFD\uFFFD\uFFFD'
|
|
||||||
)
|
|
||||||
t.equal(
|
|
||||||
new B([ 0xEE, 0x80, 0x80 ]).toString(),
|
|
||||||
'\uE000'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('utf8 don\'t replace the replacement char', function (t) {
|
|
||||||
t.equal(
|
|
||||||
new B('\uFFFD').toString(),
|
|
||||||
'\uFFFD'
|
|
||||||
)
|
|
||||||
t.end()
|
|
||||||
})
|
|
@ -1,131 +0,0 @@
|
|||||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
|
||||||
var B = require('../').Buffer
|
|
||||||
var test = require('tape')
|
|
||||||
var isnan = require('is-nan')
|
|
||||||
|
|
||||||
test('buffer.write string should get parsed as number', function (t) {
|
|
||||||
var b = new B(64)
|
|
||||||
b.writeUInt16LE('1003', 0)
|
|
||||||
t.equal(b.readUInt16LE(0), 1003)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('buffer.writeUInt8 a fractional number will get Math.floored', function (t) {
|
|
||||||
// Some extra work is necessary to make this test pass with the Object implementation
|
|
||||||
|
|
||||||
var b = new B(1)
|
|
||||||
b.writeInt8(5.5, 0)
|
|
||||||
t.equal(b[0], 5)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('writeUint8 with a negative number throws', function (t) {
|
|
||||||
var buf = new B(1)
|
|
||||||
|
|
||||||
t.throws(function () {
|
|
||||||
buf.writeUInt8(-3, 0)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('hex of write{Uint,Int}{8,16,32}{LE,BE}', function (t) {
|
|
||||||
t.plan(2 * (2 * 2 * 2 + 2))
|
|
||||||
var hex = [
|
|
||||||
'03', '0300', '0003', '03000000', '00000003',
|
|
||||||
'fd', 'fdff', 'fffd', 'fdffffff', 'fffffffd'
|
|
||||||
]
|
|
||||||
var reads = [ 3, 3, 3, 3, 3, -3, -3, -3, -3, -3 ]
|
|
||||||
var xs = ['UInt', 'Int']
|
|
||||||
var ys = [8, 16, 32]
|
|
||||||
for (var i = 0; i < xs.length; i++) {
|
|
||||||
var x = xs[i]
|
|
||||||
for (var j = 0; j < ys.length; j++) {
|
|
||||||
var y = ys[j]
|
|
||||||
var endianesses = (y === 8) ? [''] : ['LE', 'BE']
|
|
||||||
for (var k = 0; k < endianesses.length; k++) {
|
|
||||||
var z = endianesses[k]
|
|
||||||
|
|
||||||
var v1 = new B(y / 8)
|
|
||||||
var writefn = 'write' + x + y + z
|
|
||||||
var val = (x === 'Int') ? -3 : 3
|
|
||||||
v1[writefn](val, 0)
|
|
||||||
t.equal(
|
|
||||||
v1.toString('hex'),
|
|
||||||
hex.shift()
|
|
||||||
)
|
|
||||||
var readfn = 'read' + x + y + z
|
|
||||||
t.equal(
|
|
||||||
v1[readfn](0),
|
|
||||||
reads.shift()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('hex of write{Uint,Int}{8,16,32}{LE,BE} with overflow', function (t) {
|
|
||||||
if (!B.TYPED_ARRAY_SUPPORT) {
|
|
||||||
t.pass('object impl: skipping overflow test')
|
|
||||||
t.end()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
t.plan(3 * (2 * 2 * 2 + 2))
|
|
||||||
var hex = [
|
|
||||||
'', '03', '00', '030000', '000000',
|
|
||||||
'', 'fd', 'ff', 'fdffff', 'ffffff'
|
|
||||||
]
|
|
||||||
var reads = [
|
|
||||||
undefined, 3, 0, NaN, 0,
|
|
||||||
undefined, 253, -256, 16777213, -256
|
|
||||||
]
|
|
||||||
var xs = ['UInt', 'Int']
|
|
||||||
var ys = [8, 16, 32]
|
|
||||||
for (var i = 0; i < xs.length; i++) {
|
|
||||||
var x = xs[i]
|
|
||||||
for (var j = 0; j < ys.length; j++) {
|
|
||||||
var y = ys[j]
|
|
||||||
var endianesses = (y === 8) ? [''] : ['LE', 'BE']
|
|
||||||
for (var k = 0; k < endianesses.length; k++) {
|
|
||||||
var z = endianesses[k]
|
|
||||||
|
|
||||||
var v1 = new B(y / 8 - 1)
|
|
||||||
var next = new B(4)
|
|
||||||
next.writeUInt32BE(0, 0)
|
|
||||||
var writefn = 'write' + x + y + z
|
|
||||||
var val = (x === 'Int') ? -3 : 3
|
|
||||||
v1[writefn](val, 0, true)
|
|
||||||
t.equal(
|
|
||||||
v1.toString('hex'),
|
|
||||||
hex.shift()
|
|
||||||
)
|
|
||||||
// check that nothing leaked to next buffer.
|
|
||||||
t.equal(next.readUInt32BE(0), 0)
|
|
||||||
// check that no bytes are read from next buffer.
|
|
||||||
next.writeInt32BE(~0, 0)
|
|
||||||
var readfn = 'read' + x + y + z
|
|
||||||
var r = reads.shift()
|
|
||||||
if (isnan(r)) t.pass('equal')
|
|
||||||
else t.equal(v1[readfn](0, true), r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
test('large values do not imporoperly roll over (ref #80)', function (t) {
|
|
||||||
var nums = [-25589992, -633756690, -898146932]
|
|
||||||
var out = new B(12)
|
|
||||||
out.fill(0)
|
|
||||||
out.writeInt32BE(nums[0], 0)
|
|
||||||
var newNum = out.readInt32BE(0)
|
|
||||||
t.equal(nums[0], newNum)
|
|
||||||
out.writeInt32BE(nums[1], 4)
|
|
||||||
newNum = out.readInt32BE(4)
|
|
||||||
t.equal(nums[1], newNum)
|
|
||||||
out.writeInt32BE(nums[2], 8)
|
|
||||||
newNum = out.readInt32BE(8)
|
|
||||||
t.equal(nums[2], newNum)
|
|
||||||
t.end()
|
|
||||||
})
|
|
@ -1,22 +0,0 @@
|
|||||||
(The MIT License)
|
|
||||||
|
|
||||||
Copyright (c) 2011 TJ Holowaychuk <tj@vision-media.ca>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
a copy of this software and associated documentation files (the
|
|
||||||
'Software'), to deal in the Software without restriction, including
|
|
||||||
without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be
|
|
||||||
included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
||||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
||||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
||||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
||||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
File diff suppressed because it is too large
Load Diff
@ -1,309 +0,0 @@
|
|||||||
// Type definitions for commander 2.11
|
|
||||||
// Project: https://github.com/visionmedia/commander.js
|
|
||||||
// Definitions by: Alan Agius <https://github.com/alan-agius4>, Marcelo Dezem <https://github.com/mdezem>, vvakame <https://github.com/vvakame>, Jules Randolph <https://github.com/sveinburne>
|
|
||||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
||||||
|
|
||||||
declare namespace local {
|
|
||||||
|
|
||||||
class Option {
|
|
||||||
flags: string;
|
|
||||||
required: boolean;
|
|
||||||
optional: boolean;
|
|
||||||
bool: boolean;
|
|
||||||
short?: string;
|
|
||||||
long: string;
|
|
||||||
description: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize a new `Option` with the given `flags` and `description`.
|
|
||||||
*
|
|
||||||
* @param {string} flags
|
|
||||||
* @param {string} [description]
|
|
||||||
*/
|
|
||||||
constructor(flags: string, description?: string);
|
|
||||||
}
|
|
||||||
|
|
||||||
class Command extends NodeJS.EventEmitter {
|
|
||||||
[key: string]: any;
|
|
||||||
|
|
||||||
args: string[];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize a new `Command`.
|
|
||||||
*
|
|
||||||
* @param {string} [name]
|
|
||||||
*/
|
|
||||||
constructor(name?: string);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the program version to `str`.
|
|
||||||
*
|
|
||||||
* This method auto-registers the "-V, --version" flag
|
|
||||||
* which will print the version number when passed.
|
|
||||||
*
|
|
||||||
* @param {string} str
|
|
||||||
* @param {string} [flags]
|
|
||||||
* @returns {Command} for chaining
|
|
||||||
*/
|
|
||||||
version(str: string, flags?: string): Command;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add command `name`.
|
|
||||||
*
|
|
||||||
* The `.action()` callback is invoked when the
|
|
||||||
* command `name` is specified via __ARGV__,
|
|
||||||
* and the remaining arguments are applied to the
|
|
||||||
* function for access.
|
|
||||||
*
|
|
||||||
* When the `name` is "*" an un-matched command
|
|
||||||
* will be passed as the first arg, followed by
|
|
||||||
* the rest of __ARGV__ remaining.
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* program
|
|
||||||
* .version('0.0.1')
|
|
||||||
* .option('-C, --chdir <path>', 'change the working directory')
|
|
||||||
* .option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')
|
|
||||||
* .option('-T, --no-tests', 'ignore test hook')
|
|
||||||
*
|
|
||||||
* program
|
|
||||||
* .command('setup')
|
|
||||||
* .description('run remote setup commands')
|
|
||||||
* .action(function() {
|
|
||||||
* console.log('setup');
|
|
||||||
* });
|
|
||||||
*
|
|
||||||
* program
|
|
||||||
* .command('exec <cmd>')
|
|
||||||
* .description('run the given remote command')
|
|
||||||
* .action(function(cmd) {
|
|
||||||
* console.log('exec "%s"', cmd);
|
|
||||||
* });
|
|
||||||
*
|
|
||||||
* program
|
|
||||||
* .command('teardown <dir> [otherDirs...]')
|
|
||||||
* .description('run teardown commands')
|
|
||||||
* .action(function(dir, otherDirs) {
|
|
||||||
* console.log('dir "%s"', dir);
|
|
||||||
* if (otherDirs) {
|
|
||||||
* otherDirs.forEach(function (oDir) {
|
|
||||||
* console.log('dir "%s"', oDir);
|
|
||||||
* });
|
|
||||||
* }
|
|
||||||
* });
|
|
||||||
*
|
|
||||||
* program
|
|
||||||
* .command('*')
|
|
||||||
* .description('deploy the given env')
|
|
||||||
* .action(function(env) {
|
|
||||||
* console.log('deploying "%s"', env);
|
|
||||||
* });
|
|
||||||
*
|
|
||||||
* program.parse(process.argv);
|
|
||||||
*
|
|
||||||
* @param {string} name
|
|
||||||
* @param {string} [desc] for git-style sub-commands
|
|
||||||
* @param {CommandOptions} [opts] command options
|
|
||||||
* @returns {Command} the new command
|
|
||||||
*/
|
|
||||||
command(name: string, desc?: string, opts?: commander.CommandOptions): Command;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define argument syntax for the top-level command.
|
|
||||||
*
|
|
||||||
* @param {string} desc
|
|
||||||
* @returns {Command} for chaining
|
|
||||||
*/
|
|
||||||
arguments(desc: string): Command;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse expected `args`.
|
|
||||||
*
|
|
||||||
* For example `["[type]"]` becomes `[{ required: false, name: 'type' }]`.
|
|
||||||
*
|
|
||||||
* @param {string[]} args
|
|
||||||
* @returns {Command} for chaining
|
|
||||||
*/
|
|
||||||
parseExpectedArgs(args: string[]): Command;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register callback `fn` for the command.
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* program
|
|
||||||
* .command('help')
|
|
||||||
* .description('display verbose help')
|
|
||||||
* .action(function() {
|
|
||||||
* // output help here
|
|
||||||
* });
|
|
||||||
*
|
|
||||||
* @param {(...args: any[]) => void} fn
|
|
||||||
* @returns {Command} for chaining
|
|
||||||
*/
|
|
||||||
action(fn: (...args: any[]) => void): Command;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define option with `flags`, `description` and optional
|
|
||||||
* coercion `fn`.
|
|
||||||
*
|
|
||||||
* The `flags` string should contain both the short and long flags,
|
|
||||||
* separated by comma, a pipe or space. The following are all valid
|
|
||||||
* all will output this way when `--help` is used.
|
|
||||||
*
|
|
||||||
* "-p, --pepper"
|
|
||||||
* "-p|--pepper"
|
|
||||||
* "-p --pepper"
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* // simple boolean defaulting to false
|
|
||||||
* program.option('-p, --pepper', 'add pepper');
|
|
||||||
*
|
|
||||||
* --pepper
|
|
||||||
* program.pepper
|
|
||||||
* // => Boolean
|
|
||||||
*
|
|
||||||
* // simple boolean defaulting to true
|
|
||||||
* program.option('-C, --no-cheese', 'remove cheese');
|
|
||||||
*
|
|
||||||
* program.cheese
|
|
||||||
* // => true
|
|
||||||
*
|
|
||||||
* --no-cheese
|
|
||||||
* program.cheese
|
|
||||||
* // => false
|
|
||||||
*
|
|
||||||
* // required argument
|
|
||||||
* program.option('-C, --chdir <path>', 'change the working directory');
|
|
||||||
*
|
|
||||||
* --chdir /tmp
|
|
||||||
* program.chdir
|
|
||||||
* // => "/tmp"
|
|
||||||
*
|
|
||||||
* // optional argument
|
|
||||||
* program.option('-c, --cheese [type]', 'add cheese [marble]');
|
|
||||||
*
|
|
||||||
* @param {string} flags
|
|
||||||
* @param {string} [description]
|
|
||||||
* @param {((arg1: any, arg2: any) => void) | RegExp} [fn] function or default
|
|
||||||
* @param {*} [defaultValue]
|
|
||||||
* @returns {Command} for chaining
|
|
||||||
*/
|
|
||||||
option(flags: string, description?: string, fn?: ((arg1: any, arg2: any) => void) | RegExp, defaultValue?: any): Command;
|
|
||||||
option(flags: string, description?: string, defaultValue?: any): Command;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allow unknown options on the command line.
|
|
||||||
*
|
|
||||||
* @param {boolean} [arg] if `true` or omitted, no error will be thrown for unknown options.
|
|
||||||
* @returns {Command} for chaining
|
|
||||||
*/
|
|
||||||
allowUnknownOption(arg?: boolean): Command;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse `argv`, settings options and invoking commands when defined.
|
|
||||||
*
|
|
||||||
* @param {string[]} argv
|
|
||||||
* @returns {Command} for chaining
|
|
||||||
*/
|
|
||||||
parse(argv: string[]): Command;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse options from `argv` returning `argv` void of these options.
|
|
||||||
*
|
|
||||||
* @param {string[]} argv
|
|
||||||
* @returns {ParseOptionsResult}
|
|
||||||
*/
|
|
||||||
parseOptions(argv: string[]): commander.ParseOptionsResult;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an object containing options as key-value pairs
|
|
||||||
*
|
|
||||||
* @returns {{[key: string]: any}}
|
|
||||||
*/
|
|
||||||
opts(): { [key: string]: any };
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the description to `str`.
|
|
||||||
*
|
|
||||||
* @param {string} str
|
|
||||||
* @return {(Command | string)}
|
|
||||||
*/
|
|
||||||
description(str: string): Command;
|
|
||||||
description(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set an alias for the command.
|
|
||||||
*
|
|
||||||
* @param {string} alias
|
|
||||||
* @return {(Command | string)}
|
|
||||||
*/
|
|
||||||
alias(alias: string): Command;
|
|
||||||
alias(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set or get the command usage.
|
|
||||||
*
|
|
||||||
* @param {string} str
|
|
||||||
* @return {(Command | string)}
|
|
||||||
*/
|
|
||||||
usage(str: string): Command;
|
|
||||||
usage(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the name of the command.
|
|
||||||
*
|
|
||||||
* @param {string} str
|
|
||||||
* @return {Command}
|
|
||||||
*/
|
|
||||||
name(str: string): Command;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the name of the command.
|
|
||||||
*
|
|
||||||
* @return {string}
|
|
||||||
*/
|
|
||||||
name(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Output help information for this command.
|
|
||||||
*
|
|
||||||
* @param {(str: string) => string} [cb]
|
|
||||||
*/
|
|
||||||
outputHelp(cb?: (str: string) => string): void;
|
|
||||||
|
|
||||||
/** Output help information and exit.
|
|
||||||
*
|
|
||||||
* @param {(str: string) => string} [cb]
|
|
||||||
*/
|
|
||||||
help(cb?: (str: string) => string): never;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
declare namespace commander {
|
|
||||||
|
|
||||||
type Command = local.Command
|
|
||||||
|
|
||||||
type Option = local.Option
|
|
||||||
|
|
||||||
interface CommandOptions {
|
|
||||||
noHelp?: boolean;
|
|
||||||
isDefault?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ParseOptionsResult {
|
|
||||||
args: string[];
|
|
||||||
unknown: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CommanderStatic extends Command {
|
|
||||||
Command: typeof local.Command;
|
|
||||||
Option: typeof local.Option;
|
|
||||||
CommandOptions: CommandOptions;
|
|
||||||
ParseOptionsResult: ParseOptionsResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
declare const commander: commander.CommanderStatic;
|
|
||||||
export = commander;
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,3 +0,0 @@
|
|||||||
import _default from './TemplateTag';
|
|
||||||
export { _default as default };
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9UZW1wbGF0ZVRhZy9pbmRleC5qcyJdLCJuYW1lcyI6WyJkZWZhdWx0Il0sIm1hcHBpbmdzIjoicUJBQW9CLGU7cUJBQWJBLE8iLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZGVmYXVsdCBmcm9tICcuL1RlbXBsYXRlVGFnJztcbiJdfQ==
|
|
@ -1,3 +0,0 @@
|
|||||||
import _default from '../html';
|
|
||||||
export { _default as default };
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb2RlQmxvY2svaW5kZXguanMiXSwibmFtZXMiOlsiZGVmYXVsdCJdLCJtYXBwaW5ncyI6InFCQUFvQixTO3FCQUFiQSxPIiwiZmlsZSI6ImluZGV4LmpzIiwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGRlZmF1bHQgZnJvbSAnLi4vaHRtbCc7XG4iXX0=
|
|
@ -1,9 +0,0 @@
|
|||||||
import TemplateTag from '../TemplateTag';
|
|
||||||
import stripIndentTransformer from '../stripIndentTransformer';
|
|
||||||
import inlineArrayTransformer from '../inlineArrayTransformer';
|
|
||||||
import trimResultTransformer from '../trimResultTransformer';
|
|
||||||
|
|
||||||
var commaLists = new TemplateTag(inlineArrayTransformer({ separator: ',' }), stripIndentTransformer, trimResultTransformer);
|
|
||||||
|
|
||||||
export default commaLists;
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb21tYUxpc3RzL2NvbW1hTGlzdHMuanMiXSwibmFtZXMiOlsiVGVtcGxhdGVUYWciLCJzdHJpcEluZGVudFRyYW5zZm9ybWVyIiwiaW5saW5lQXJyYXlUcmFuc2Zvcm1lciIsInRyaW1SZXN1bHRUcmFuc2Zvcm1lciIsImNvbW1hTGlzdHMiLCJzZXBhcmF0b3IiXSwibWFwcGluZ3MiOiJBQUFBLE9BQU9BLFdBQVAsTUFBd0IsZ0JBQXhCO0FBQ0EsT0FBT0Msc0JBQVAsTUFBbUMsMkJBQW5DO0FBQ0EsT0FBT0Msc0JBQVAsTUFBbUMsMkJBQW5DO0FBQ0EsT0FBT0MscUJBQVAsTUFBa0MsMEJBQWxDOztBQUVBLElBQU1DLGFBQWEsSUFBSUosV0FBSixDQUNqQkUsdUJBQXVCLEVBQUVHLFdBQVcsR0FBYixFQUF2QixDQURpQixFQUVqQkosc0JBRmlCLEVBR2pCRSxxQkFIaUIsQ0FBbkI7O0FBTUEsZUFBZUMsVUFBZiIsImZpbGUiOiJjb21tYUxpc3RzLmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFRlbXBsYXRlVGFnIGZyb20gJy4uL1RlbXBsYXRlVGFnJztcbmltcG9ydCBzdHJpcEluZGVudFRyYW5zZm9ybWVyIGZyb20gJy4uL3N0cmlwSW5kZW50VHJhbnNmb3JtZXInO1xuaW1wb3J0IGlubGluZUFycmF5VHJhbnNmb3JtZXIgZnJvbSAnLi4vaW5saW5lQXJyYXlUcmFuc2Zvcm1lcic7XG5pbXBvcnQgdHJpbVJlc3VsdFRyYW5zZm9ybWVyIGZyb20gJy4uL3RyaW1SZXN1bHRUcmFuc2Zvcm1lcic7XG5cbmNvbnN0IGNvbW1hTGlzdHMgPSBuZXcgVGVtcGxhdGVUYWcoXG4gIGlubGluZUFycmF5VHJhbnNmb3JtZXIoeyBzZXBhcmF0b3I6ICcsJyB9KSxcbiAgc3RyaXBJbmRlbnRUcmFuc2Zvcm1lcixcbiAgdHJpbVJlc3VsdFRyYW5zZm9ybWVyLFxuKTtcblxuZXhwb3J0IGRlZmF1bHQgY29tbWFMaXN0cztcbiJdfQ==
|
|
@ -1,3 +0,0 @@
|
|||||||
import _default from './commaLists';
|
|
||||||
export { _default as default };
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb21tYUxpc3RzL2luZGV4LmpzIl0sIm5hbWVzIjpbImRlZmF1bHQiXSwibWFwcGluZ3MiOiJxQkFBb0IsYztxQkFBYkEsTyIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBkZWZhdWx0IGZyb20gJy4vY29tbWFMaXN0cyc7XG4iXX0=
|
|
@ -1,9 +0,0 @@
|
|||||||
import TemplateTag from '../TemplateTag';
|
|
||||||
import stripIndentTransformer from '../stripIndentTransformer';
|
|
||||||
import inlineArrayTransformer from '../inlineArrayTransformer';
|
|
||||||
import trimResultTransformer from '../trimResultTransformer';
|
|
||||||
|
|
||||||
var commaListsAnd = new TemplateTag(inlineArrayTransformer({ separator: ',', conjunction: 'and' }), stripIndentTransformer, trimResultTransformer);
|
|
||||||
|
|
||||||
export default commaListsAnd;
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb21tYUxpc3RzQW5kL2NvbW1hTGlzdHNBbmQuanMiXSwibmFtZXMiOlsiVGVtcGxhdGVUYWciLCJzdHJpcEluZGVudFRyYW5zZm9ybWVyIiwiaW5saW5lQXJyYXlUcmFuc2Zvcm1lciIsInRyaW1SZXN1bHRUcmFuc2Zvcm1lciIsImNvbW1hTGlzdHNBbmQiLCJzZXBhcmF0b3IiLCJjb25qdW5jdGlvbiJdLCJtYXBwaW5ncyI6IkFBQUEsT0FBT0EsV0FBUCxNQUF3QixnQkFBeEI7QUFDQSxPQUFPQyxzQkFBUCxNQUFtQywyQkFBbkM7QUFDQSxPQUFPQyxzQkFBUCxNQUFtQywyQkFBbkM7QUFDQSxPQUFPQyxxQkFBUCxNQUFrQywwQkFBbEM7O0FBRUEsSUFBTUMsZ0JBQWdCLElBQUlKLFdBQUosQ0FDcEJFLHVCQUF1QixFQUFFRyxXQUFXLEdBQWIsRUFBa0JDLGFBQWEsS0FBL0IsRUFBdkIsQ0FEb0IsRUFFcEJMLHNCQUZvQixFQUdwQkUscUJBSG9CLENBQXRCOztBQU1BLGVBQWVDLGFBQWYiLCJmaWxlIjoiY29tbWFMaXN0c0FuZC5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBUZW1wbGF0ZVRhZyBmcm9tICcuLi9UZW1wbGF0ZVRhZyc7XG5pbXBvcnQgc3RyaXBJbmRlbnRUcmFuc2Zvcm1lciBmcm9tICcuLi9zdHJpcEluZGVudFRyYW5zZm9ybWVyJztcbmltcG9ydCBpbmxpbmVBcnJheVRyYW5zZm9ybWVyIGZyb20gJy4uL2lubGluZUFycmF5VHJhbnNmb3JtZXInO1xuaW1wb3J0IHRyaW1SZXN1bHRUcmFuc2Zvcm1lciBmcm9tICcuLi90cmltUmVzdWx0VHJhbnNmb3JtZXInO1xuXG5jb25zdCBjb21tYUxpc3RzQW5kID0gbmV3IFRlbXBsYXRlVGFnKFxuICBpbmxpbmVBcnJheVRyYW5zZm9ybWVyKHsgc2VwYXJhdG9yOiAnLCcsIGNvbmp1bmN0aW9uOiAnYW5kJyB9KSxcbiAgc3RyaXBJbmRlbnRUcmFuc2Zvcm1lcixcbiAgdHJpbVJlc3VsdFRyYW5zZm9ybWVyLFxuKTtcblxuZXhwb3J0IGRlZmF1bHQgY29tbWFMaXN0c0FuZDtcbiJdfQ==
|
|
@ -1,3 +0,0 @@
|
|||||||
import _default from './commaListsAnd';
|
|
||||||
export { _default as default };
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb21tYUxpc3RzQW5kL2luZGV4LmpzIl0sIm5hbWVzIjpbImRlZmF1bHQiXSwibWFwcGluZ3MiOiJxQkFBb0IsaUI7cUJBQWJBLE8iLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZGVmYXVsdCBmcm9tICcuL2NvbW1hTGlzdHNBbmQnO1xuIl19
|
|
@ -1,9 +0,0 @@
|
|||||||
import TemplateTag from '../TemplateTag';
|
|
||||||
import stripIndentTransformer from '../stripIndentTransformer';
|
|
||||||
import inlineArrayTransformer from '../inlineArrayTransformer';
|
|
||||||
import trimResultTransformer from '../trimResultTransformer';
|
|
||||||
|
|
||||||
var commaListsOr = new TemplateTag(inlineArrayTransformer({ separator: ',', conjunction: 'or' }), stripIndentTransformer, trimResultTransformer);
|
|
||||||
|
|
||||||
export default commaListsOr;
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb21tYUxpc3RzT3IvY29tbWFMaXN0c09yLmpzIl0sIm5hbWVzIjpbIlRlbXBsYXRlVGFnIiwic3RyaXBJbmRlbnRUcmFuc2Zvcm1lciIsImlubGluZUFycmF5VHJhbnNmb3JtZXIiLCJ0cmltUmVzdWx0VHJhbnNmb3JtZXIiLCJjb21tYUxpc3RzT3IiLCJzZXBhcmF0b3IiLCJjb25qdW5jdGlvbiJdLCJtYXBwaW5ncyI6IkFBQUEsT0FBT0EsV0FBUCxNQUF3QixnQkFBeEI7QUFDQSxPQUFPQyxzQkFBUCxNQUFtQywyQkFBbkM7QUFDQSxPQUFPQyxzQkFBUCxNQUFtQywyQkFBbkM7QUFDQSxPQUFPQyxxQkFBUCxNQUFrQywwQkFBbEM7O0FBRUEsSUFBTUMsZUFBZSxJQUFJSixXQUFKLENBQ25CRSx1QkFBdUIsRUFBRUcsV0FBVyxHQUFiLEVBQWtCQyxhQUFhLElBQS9CLEVBQXZCLENBRG1CLEVBRW5CTCxzQkFGbUIsRUFHbkJFLHFCQUhtQixDQUFyQjs7QUFNQSxlQUFlQyxZQUFmIiwiZmlsZSI6ImNvbW1hTGlzdHNPci5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBUZW1wbGF0ZVRhZyBmcm9tICcuLi9UZW1wbGF0ZVRhZyc7XG5pbXBvcnQgc3RyaXBJbmRlbnRUcmFuc2Zvcm1lciBmcm9tICcuLi9zdHJpcEluZGVudFRyYW5zZm9ybWVyJztcbmltcG9ydCBpbmxpbmVBcnJheVRyYW5zZm9ybWVyIGZyb20gJy4uL2lubGluZUFycmF5VHJhbnNmb3JtZXInO1xuaW1wb3J0IHRyaW1SZXN1bHRUcmFuc2Zvcm1lciBmcm9tICcuLi90cmltUmVzdWx0VHJhbnNmb3JtZXInO1xuXG5jb25zdCBjb21tYUxpc3RzT3IgPSBuZXcgVGVtcGxhdGVUYWcoXG4gIGlubGluZUFycmF5VHJhbnNmb3JtZXIoeyBzZXBhcmF0b3I6ICcsJywgY29uanVuY3Rpb246ICdvcicgfSksXG4gIHN0cmlwSW5kZW50VHJhbnNmb3JtZXIsXG4gIHRyaW1SZXN1bHRUcmFuc2Zvcm1lcixcbik7XG5cbmV4cG9ydCBkZWZhdWx0IGNvbW1hTGlzdHNPcjtcbiJdfQ==
|
|
@ -1,3 +0,0 @@
|
|||||||
import _default from './commaListsOr';
|
|
||||||
export { _default as default };
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb21tYUxpc3RzT3IvaW5kZXguanMiXSwibmFtZXMiOlsiZGVmYXVsdCJdLCJtYXBwaW5ncyI6InFCQUFvQixnQjtxQkFBYkEsTyIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBkZWZhdWx0IGZyb20gJy4vY29tbWFMaXN0c09yJztcbiJdfQ==
|
|
@ -1,11 +0,0 @@
|
|||||||
import TemplateTag from '../TemplateTag';
|
|
||||||
import stripIndentTransformer from '../stripIndentTransformer';
|
|
||||||
import inlineArrayTransformer from '../inlineArrayTransformer';
|
|
||||||
import trimResultTransformer from '../trimResultTransformer';
|
|
||||||
import splitStringTransformer from '../splitStringTransformer';
|
|
||||||
import removeNonPrintingValuesTransformer from '../removeNonPrintingValuesTransformer';
|
|
||||||
|
|
||||||
var html = new TemplateTag(splitStringTransformer('\n'), removeNonPrintingValuesTransformer, inlineArrayTransformer, stripIndentTransformer, trimResultTransformer);
|
|
||||||
|
|
||||||
export default html;
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9odG1sL2h0bWwuanMiXSwibmFtZXMiOlsiVGVtcGxhdGVUYWciLCJzdHJpcEluZGVudFRyYW5zZm9ybWVyIiwiaW5saW5lQXJyYXlUcmFuc2Zvcm1lciIsInRyaW1SZXN1bHRUcmFuc2Zvcm1lciIsInNwbGl0U3RyaW5nVHJhbnNmb3JtZXIiLCJyZW1vdmVOb25QcmludGluZ1ZhbHVlc1RyYW5zZm9ybWVyIiwiaHRtbCJdLCJtYXBwaW5ncyI6IkFBQUEsT0FBT0EsV0FBUCxNQUF3QixnQkFBeEI7QUFDQSxPQUFPQyxzQkFBUCxNQUFtQywyQkFBbkM7QUFDQSxPQUFPQyxzQkFBUCxNQUFtQywyQkFBbkM7QUFDQSxPQUFPQyxxQkFBUCxNQUFrQywwQkFBbEM7QUFDQSxPQUFPQyxzQkFBUCxNQUFtQywyQkFBbkM7QUFDQSxPQUFPQyxrQ0FBUCxNQUErQyx1Q0FBL0M7O0FBRUEsSUFBTUMsT0FBTyxJQUFJTixXQUFKLENBQ1hJLHVCQUF1QixJQUF2QixDQURXLEVBRVhDLGtDQUZXLEVBR1hILHNCQUhXLEVBSVhELHNCQUpXLEVBS1hFLHFCQUxXLENBQWI7O0FBUUEsZUFBZUcsSUFBZiIsImZpbGUiOiJodG1sLmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFRlbXBsYXRlVGFnIGZyb20gJy4uL1RlbXBsYXRlVGFnJztcbmltcG9ydCBzdHJpcEluZGVudFRyYW5zZm9ybWVyIGZyb20gJy4uL3N0cmlwSW5kZW50VHJhbnNmb3JtZXInO1xuaW1wb3J0IGlubGluZUFycmF5VHJhbnNmb3JtZXIgZnJvbSAnLi4vaW5saW5lQXJyYXlUcmFuc2Zvcm1lcic7XG5pbXBvcnQgdHJpbVJlc3VsdFRyYW5zZm9ybWVyIGZyb20gJy4uL3RyaW1SZXN1bHRUcmFuc2Zvcm1lcic7XG5pbXBvcnQgc3BsaXRTdHJpbmdUcmFuc2Zvcm1lciBmcm9tICcuLi9zcGxpdFN0cmluZ1RyYW5zZm9ybWVyJztcbmltcG9ydCByZW1vdmVOb25QcmludGluZ1ZhbHVlc1RyYW5zZm9ybWVyIGZyb20gJy4uL3JlbW92ZU5vblByaW50aW5nVmFsdWVzVHJhbnNmb3JtZXInO1xuXG5jb25zdCBodG1sID0gbmV3IFRlbXBsYXRlVGFnKFxuICBzcGxpdFN0cmluZ1RyYW5zZm9ybWVyKCdcXG4nKSxcbiAgcmVtb3ZlTm9uUHJpbnRpbmdWYWx1ZXNUcmFuc2Zvcm1lcixcbiAgaW5saW5lQXJyYXlUcmFuc2Zvcm1lcixcbiAgc3RyaXBJbmRlbnRUcmFuc2Zvcm1lcixcbiAgdHJpbVJlc3VsdFRyYW5zZm9ybWVyLFxuKTtcblxuZXhwb3J0IGRlZmF1bHQgaHRtbDtcbiJdfQ==
|
|
@ -1,3 +0,0 @@
|
|||||||
import _default from './html';
|
|
||||||
export { _default as default };
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9odG1sL2luZGV4LmpzIl0sIm5hbWVzIjpbImRlZmF1bHQiXSwibWFwcGluZ3MiOiJxQkFBb0IsUTtxQkFBYkEsTyIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBkZWZhdWx0IGZyb20gJy4vaHRtbCc7XG4iXX0=
|
|
@ -1,58 +0,0 @@
|
|||||||
// core
|
|
||||||
import _TemplateTag from './TemplateTag';
|
|
||||||
export { _TemplateTag as TemplateTag };
|
|
||||||
|
|
||||||
// transformers
|
|
||||||
|
|
||||||
import _trimResultTransformer from './trimResultTransformer';
|
|
||||||
export { _trimResultTransformer as trimResultTransformer };
|
|
||||||
import _stripIndentTransformer from './stripIndentTransformer';
|
|
||||||
export { _stripIndentTransformer as stripIndentTransformer };
|
|
||||||
import _replaceResultTransformer from './replaceResultTransformer';
|
|
||||||
export { _replaceResultTransformer as replaceResultTransformer };
|
|
||||||
import _replaceSubstitutionTransformer from './replaceSubstitutionTransformer';
|
|
||||||
export { _replaceSubstitutionTransformer as replaceSubstitutionTransformer };
|
|
||||||
import _replaceStringTransformer from './replaceStringTransformer';
|
|
||||||
export { _replaceStringTransformer as replaceStringTransformer };
|
|
||||||
import _inlineArrayTransformer from './inlineArrayTransformer';
|
|
||||||
export { _inlineArrayTransformer as inlineArrayTransformer };
|
|
||||||
import _splitStringTransformer from './splitStringTransformer';
|
|
||||||
export { _splitStringTransformer as splitStringTransformer };
|
|
||||||
import _removeNonPrintingValuesTransformer from './removeNonPrintingValuesTransformer';
|
|
||||||
export { _removeNonPrintingValuesTransformer as removeNonPrintingValuesTransformer };
|
|
||||||
|
|
||||||
// tags
|
|
||||||
|
|
||||||
import _commaLists from './commaLists';
|
|
||||||
export { _commaLists as commaLists };
|
|
||||||
import _commaListsAnd from './commaListsAnd';
|
|
||||||
export { _commaListsAnd as commaListsAnd };
|
|
||||||
import _commaListsOr from './commaListsOr';
|
|
||||||
export { _commaListsOr as commaListsOr };
|
|
||||||
import _html from './html';
|
|
||||||
export { _html as html };
|
|
||||||
import _codeBlock from './codeBlock';
|
|
||||||
export { _codeBlock as codeBlock };
|
|
||||||
import _source from './source';
|
|
||||||
export { _source as source };
|
|
||||||
import _safeHtml from './safeHtml';
|
|
||||||
export { _safeHtml as safeHtml };
|
|
||||||
import _oneLine from './oneLine';
|
|
||||||
export { _oneLine as oneLine };
|
|
||||||
import _oneLineTrim from './oneLineTrim';
|
|
||||||
export { _oneLineTrim as oneLineTrim };
|
|
||||||
import _oneLineCommaLists from './oneLineCommaLists';
|
|
||||||
export { _oneLineCommaLists as oneLineCommaLists };
|
|
||||||
import _oneLineCommaListsOr from './oneLineCommaListsOr';
|
|
||||||
export { _oneLineCommaListsOr as oneLineCommaListsOr };
|
|
||||||
import _oneLineCommaListsAnd from './oneLineCommaListsAnd';
|
|
||||||
export { _oneLineCommaListsAnd as oneLineCommaListsAnd };
|
|
||||||
import _inlineLists from './inlineLists';
|
|
||||||
export { _inlineLists as inlineLists };
|
|
||||||
import _oneLineInlineLists from './oneLineInlineLists';
|
|
||||||
export { _oneLineInlineLists as oneLineInlineLists };
|
|
||||||
import _stripIndent from './stripIndent';
|
|
||||||
export { _stripIndent as stripIndent };
|
|
||||||
import _stripIndents from './stripIndents';
|
|
||||||
export { _stripIndents as stripIndents };
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC5qcyJdLCJuYW1lcyI6WyJUZW1wbGF0ZVRhZyIsInRyaW1SZXN1bHRUcmFuc2Zvcm1lciIsInN0cmlwSW5kZW50VHJhbnNmb3JtZXIiLCJyZXBsYWNlUmVzdWx0VHJhbnNmb3JtZXIiLCJyZXBsYWNlU3Vic3RpdHV0aW9uVHJhbnNmb3JtZXIiLCJyZXBsYWNlU3RyaW5nVHJhbnNmb3JtZXIiLCJpbmxpbmVBcnJheVRyYW5zZm9ybWVyIiwic3BsaXRTdHJpbmdUcmFuc2Zvcm1lciIsInJlbW92ZU5vblByaW50aW5nVmFsdWVzVHJhbnNmb3JtZXIiLCJjb21tYUxpc3RzIiwiY29tbWFMaXN0c0FuZCIsImNvbW1hTGlzdHNPciIsImh0bWwiLCJjb2RlQmxvY2siLCJzb3VyY2UiLCJzYWZlSHRtbCIsIm9uZUxpbmUiLCJvbmVMaW5lVHJpbSIsIm9uZUxpbmVDb21tYUxpc3RzIiwib25lTGluZUNvbW1hTGlzdHNPciIsIm9uZUxpbmVDb21tYUxpc3RzQW5kIiwiaW5saW5lTGlzdHMiLCJvbmVMaW5lSW5saW5lTGlzdHMiLCJzdHJpcEluZGVudCIsInN0cmlwSW5kZW50cyJdLCJtYXBwaW5ncyI6IkFBQUE7eUJBQ3dCLGU7eUJBQWpCQSxXOztBQUVQOzttQ0FDa0MseUI7bUNBQTNCQyxxQjtvQ0FDNEIsMEI7b0NBQTVCQyxzQjtzQ0FDOEIsNEI7c0NBQTlCQyx3Qjs0Q0FDb0Msa0M7NENBQXBDQyw4QjtzQ0FDOEIsNEI7c0NBQTlCQyx3QjtvQ0FDNEIsMEI7b0NBQTVCQyxzQjtvQ0FDNEIsMEI7b0NBQTVCQyxzQjtnREFDd0Msc0M7Z0RBQXhDQyxrQzs7QUFFUDs7d0JBQ3VCLGM7d0JBQWhCQyxVOzJCQUNtQixpQjsyQkFBbkJDLGE7MEJBQ2tCLGdCOzBCQUFsQkMsWTtrQkFDVSxRO2tCQUFWQyxJO3VCQUNlLGE7dUJBQWZDLFM7b0JBQ1ksVTtvQkFBWkMsTTtzQkFDYyxZO3NCQUFkQyxRO3FCQUNhLFc7cUJBQWJDLE87eUJBQ2lCLGU7eUJBQWpCQyxXOytCQUN1QixxQjsrQkFBdkJDLGlCO2lDQUN5Qix1QjtpQ0FBekJDLG1CO2tDQUMwQix3QjtrQ0FBMUJDLG9CO3lCQUNpQixlO3lCQUFqQkMsVztnQ0FDd0Isc0I7Z0NBQXhCQyxrQjt5QkFDaUIsZTt5QkFBakJDLFc7MEJBQ2tCLGdCOzBCQUFsQkMsWSIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vIGNvcmVcbmV4cG9ydCBUZW1wbGF0ZVRhZyBmcm9tICcuL1RlbXBsYXRlVGFnJztcblxuLy8gdHJhbnNmb3JtZXJzXG5leHBvcnQgdHJpbVJlc3VsdFRyYW5zZm9ybWVyIGZyb20gJy4vdHJpbVJlc3VsdFRyYW5zZm9ybWVyJztcbmV4cG9ydCBzdHJpcEluZGVudFRyYW5zZm9ybWVyIGZyb20gJy4vc3RyaXBJbmRlbnRUcmFuc2Zvcm1lcic7XG5leHBvcnQgcmVwbGFjZVJlc3VsdFRyYW5zZm9ybWVyIGZyb20gJy4vcmVwbGFjZVJlc3VsdFRyYW5zZm9ybWVyJztcbmV4cG9ydCByZXBsYWNlU3Vic3RpdHV0aW9uVHJhbnNmb3JtZXIgZnJvbSAnLi9yZXBsYWNlU3Vic3RpdHV0aW9uVHJhbnNmb3JtZXInO1xuZXhwb3J0IHJlcGxhY2VTdHJpbmdUcmFuc2Zvcm1lciBmcm9tICcuL3JlcGxhY2VTdHJpbmdUcmFuc2Zvcm1lcic7XG5leHBvcnQgaW5saW5lQXJyYXlUcmFuc2Zvcm1lciBmcm9tICcuL2lubGluZUFycmF5VHJhbnNmb3JtZXInO1xuZXhwb3J0IHNwbGl0U3RyaW5nVHJhbnNmb3JtZXIgZnJvbSAnLi9zcGxpdFN0cmluZ1RyYW5zZm9ybWVyJztcbmV4cG9ydCByZW1vdmVOb25QcmludGluZ1ZhbHVlc1RyYW5zZm9ybWVyIGZyb20gJy4vcmVtb3ZlTm9uUHJpbnRpbmdWYWx1ZXNUcmFuc2Zvcm1lcic7XG5cbi8vIHRhZ3NcbmV4cG9ydCBjb21tYUxpc3RzIGZyb20gJy4vY29tbWFMaXN0cyc7XG5leHBvcnQgY29tbWFMaXN0c0FuZCBmcm9tICcuL2NvbW1hTGlzdHNBbmQnO1xuZXhwb3J0IGNvbW1hTGlzdHNPciBmcm9tICcuL2NvbW1hTGlzdHNPcic7XG5leHBvcnQgaHRtbCBmcm9tICcuL2h0bWwnO1xuZXhwb3J0IGNvZGVCbG9jayBmcm9tICcuL2NvZGVCbG9jayc7XG5leHBvcnQgc291cmNlIGZyb20gJy4vc291cmNlJztcbmV4cG9ydCBzYWZlSHRtbCBmcm9tICcuL3NhZmVIdG1sJztcbmV4cG9ydCBvbmVMaW5lIGZyb20gJy4vb25lTGluZSc7XG5leHBvcnQgb25lTGluZVRyaW0gZnJvbSAnLi9vbmVMaW5lVHJpbSc7XG5leHBvcnQgb25lTGluZUNvbW1hTGlzdHMgZnJvbSAnLi9vbmVMaW5lQ29tbWFMaXN0cyc7XG5leHBvcnQgb25lTGluZUNvbW1hTGlzdHNPciBmcm9tICcuL29uZUxpbmVDb21tYUxpc3RzT3InO1xuZXhwb3J0IG9uZUxpbmVDb21tYUxpc3RzQW5kIGZyb20gJy4vb25lTGluZUNvbW1hTGlzdHNBbmQnO1xuZXhwb3J0IGlubGluZUxpc3RzIGZyb20gJy4vaW5saW5lTGlzdHMnO1xuZXhwb3J0IG9uZUxpbmVJbmxpbmVMaXN0cyBmcm9tICcuL29uZUxpbmVJbmxpbmVMaXN0cyc7XG5leHBvcnQgc3RyaXBJbmRlbnQgZnJvbSAnLi9zdHJpcEluZGVudCc7XG5leHBvcnQgc3RyaXBJbmRlbnRzIGZyb20gJy4vc3RyaXBJbmRlbnRzJztcbiJdfQ==
|
|
@ -1,3 +0,0 @@
|
|||||||
import _default from './inlineArrayTransformer';
|
|
||||||
export { _default as default };
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9pbmxpbmVBcnJheVRyYW5zZm9ybWVyL2luZGV4LmpzIl0sIm5hbWVzIjpbImRlZmF1bHQiXSwibWFwcGluZ3MiOiJxQkFBb0IsMEI7cUJBQWJBLE8iLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZGVmYXVsdCBmcm9tICcuL2lubGluZUFycmF5VHJhbnNmb3JtZXInO1xuIl19
|
|
@ -1,45 +0,0 @@
|
|||||||
var defaults = {
|
|
||||||
separator: '',
|
|
||||||
conjunction: '',
|
|
||||||
serial: false
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts an array substitution to a string containing a list
|
|
||||||
* @param {String} [opts.separator = ''] - the character that separates each item
|
|
||||||
* @param {String} [opts.conjunction = ''] - replace the last separator with this
|
|
||||||
* @param {Boolean} [opts.serial = false] - include the separator before the conjunction? (Oxford comma use-case)
|
|
||||||
*
|
|
||||||
* @return {Object} - a TemplateTag transformer
|
|
||||||
*/
|
|
||||||
var inlineArrayTransformer = function inlineArrayTransformer() {
|
|
||||||
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaults;
|
|
||||||
return {
|
|
||||||
onSubstitution: function onSubstitution(substitution, resultSoFar) {
|
|
||||||
// only operate on arrays
|
|
||||||
if (Array.isArray(substitution)) {
|
|
||||||
var arrayLength = substitution.length;
|
|
||||||
var separator = opts.separator;
|
|
||||||
var conjunction = opts.conjunction;
|
|
||||||
var serial = opts.serial;
|
|
||||||
// join each item in the array into a string where each item is separated by separator
|
|
||||||
// be sure to maintain indentation
|
|
||||||
var indent = resultSoFar.match(/(\n?[^\S\n]+)$/);
|
|
||||||
if (indent) {
|
|
||||||
substitution = substitution.join(separator + indent[1]);
|
|
||||||
} else {
|
|
||||||
substitution = substitution.join(separator + ' ');
|
|
||||||
}
|
|
||||||
// if conjunction is set, replace the last separator with conjunction, but only if there is more than one substitution
|
|
||||||
if (conjunction && arrayLength > 1) {
|
|
||||||
var separatorIndex = substitution.lastIndexOf(separator);
|
|
||||||
substitution = substitution.slice(0, separatorIndex) + (serial ? separator : '') + ' ' + conjunction + substitution.slice(separatorIndex + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return substitution;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export default inlineArrayTransformer;
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9pbmxpbmVBcnJheVRyYW5zZm9ybWVyL2lubGluZUFycmF5VHJhbnNmb3JtZXIuanMiXSwibmFtZXMiOlsiZGVmYXVsdHMiLCJzZXBhcmF0b3IiLCJjb25qdW5jdGlvbiIsInNlcmlhbCIsImlubGluZUFycmF5VHJhbnNmb3JtZXIiLCJvcHRzIiwib25TdWJzdGl0dXRpb24iLCJzdWJzdGl0dXRpb24iLCJyZXN1bHRTb0ZhciIsIkFycmF5IiwiaXNBcnJheSIsImFycmF5TGVuZ3RoIiwibGVuZ3RoIiwiaW5kZW50IiwibWF0Y2giLCJqb2luIiwic2VwYXJhdG9ySW5kZXgiLCJsYXN0SW5kZXhPZiIsInNsaWNlIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFNQSxXQUFXO0FBQ2ZDLGFBQVcsRUFESTtBQUVmQyxlQUFhLEVBRkU7QUFHZkMsVUFBUTtBQUhPLENBQWpCOztBQU1BOzs7Ozs7OztBQVFBLElBQU1DLHlCQUF5QixTQUF6QkEsc0JBQXlCO0FBQUEsTUFBQ0MsSUFBRCx1RUFBUUwsUUFBUjtBQUFBLFNBQXNCO0FBQ25ETSxrQkFEbUQsMEJBQ3BDQyxZQURvQyxFQUN0QkMsV0FEc0IsRUFDVDtBQUN4QztBQUNBLFVBQUlDLE1BQU1DLE9BQU4sQ0FBY0gsWUFBZCxDQUFKLEVBQWlDO0FBQy9CLFlBQU1JLGNBQWNKLGFBQWFLLE1BQWpDO0FBQ0EsWUFBTVgsWUFBWUksS0FBS0osU0FBdkI7QUFDQSxZQUFNQyxjQUFjRyxLQUFLSCxXQUF6QjtBQUNBLFlBQU1DLFNBQVNFLEtBQUtGLE1BQXBCO0FBQ0E7QUFDQTtBQUNBLFlBQU1VLFNBQVNMLFlBQVlNLEtBQVosQ0FBa0IsZ0JBQWxCLENBQWY7QUFDQSxZQUFJRCxNQUFKLEVBQVk7QUFDVk4seUJBQWVBLGFBQWFRLElBQWIsQ0FBa0JkLFlBQVlZLE9BQU8sQ0FBUCxDQUE5QixDQUFmO0FBQ0QsU0FGRCxNQUVPO0FBQ0xOLHlCQUFlQSxhQUFhUSxJQUFiLENBQWtCZCxZQUFZLEdBQTlCLENBQWY7QUFDRDtBQUNEO0FBQ0EsWUFBSUMsZUFBZVMsY0FBYyxDQUFqQyxFQUFvQztBQUNsQyxjQUFNSyxpQkFBaUJULGFBQWFVLFdBQWIsQ0FBeUJoQixTQUF6QixDQUF2QjtBQUNBTSx5QkFDRUEsYUFBYVcsS0FBYixDQUFtQixDQUFuQixFQUFzQkYsY0FBdEIsS0FDQ2IsU0FBU0YsU0FBVCxHQUFxQixFQUR0QixJQUVBLEdBRkEsR0FHQUMsV0FIQSxHQUlBSyxhQUFhVyxLQUFiLENBQW1CRixpQkFBaUIsQ0FBcEMsQ0FMRjtBQU1EO0FBQ0Y7QUFDRCxhQUFPVCxZQUFQO0FBQ0Q7QUE1QmtELEdBQXRCO0FBQUEsQ0FBL0I7O0FBK0JBLGVBQWVILHNCQUFmIiwiZmlsZSI6ImlubGluZUFycmF5VHJhbnNmb3JtZXIuanMiLCJzb3VyY2VzQ29udGVudCI6WyJjb25zdCBkZWZhdWx0cyA9IHtcbiAgc2VwYXJhdG9yOiAnJyxcbiAgY29uanVuY3Rpb246ICcnLFxuICBzZXJpYWw6IGZhbHNlLFxufTtcblxuLyoqXG4gKiBDb252ZXJ0cyBhbiBhcnJheSBzdWJzdGl0dXRpb24gdG8gYSBzdHJpbmcgY29udGFpbmluZyBhIGxpc3RcbiAqIEBwYXJhbSAge1N0cmluZ30gW29wdHMuc2VwYXJhdG9yID0gJyddIC0gdGhlIGNoYXJhY3RlciB0aGF0IHNlcGFyYXRlcyBlYWNoIGl0ZW1cbiAqIEBwYXJhbSAge1N0cmluZ30gW29wdHMuY29uanVuY3Rpb24gPSAnJ10gIC0gcmVwbGFjZSB0aGUgbGFzdCBzZXBhcmF0b3Igd2l0aCB0aGlzXG4gKiBAcGFyYW0gIHtCb29sZWFufSBbb3B0cy5zZXJpYWwgPSBmYWxzZV0gLSBpbmNsdWRlIHRoZSBzZXBhcmF0b3IgYmVmb3JlIHRoZSBjb25qdW5jdGlvbj8gKE94Zm9yZCBjb21tYSB1c2UtY2FzZSlcbiAqXG4gKiBAcmV0dXJuIHtPYmplY3R9ICAgICAgICAgICAgICAgICAgICAgLSBhIFRlbXBsYXRlVGFnIHRyYW5zZm9ybWVyXG4gKi9cbmNvbnN0IGlubGluZUFycmF5VHJhbnNmb3JtZXIgPSAob3B0cyA9IGRlZmF1bHRzKSA9PiAoe1xuICBvblN1YnN0aXR1dGlvbihzdWJzdGl0dXRpb24sIHJlc3VsdFNvRmFyKSB7XG4gICAgLy8gb25seSBvcGVyYXRlIG9uIGFycmF5c1xuICAgIGlmIChBcnJheS5pc0FycmF5KHN1YnN0aXR1dGlvbikpIHtcbiAgICAgIGNvbnN0IGFycmF5TGVuZ3RoID0gc3Vic3RpdHV0aW9uLmxlbmd0aDtcbiAgICAgIGNvbnN0IHNlcGFyYXRvciA9IG9wdHMuc2VwYXJhdG9yO1xuICAgICAgY29uc3QgY29uanVuY3Rpb24gPSBvcHRzLmNvbmp1bmN0aW9uO1xuICAgICAgY29uc3Qgc2VyaWFsID0gb3B0cy5zZXJpYWw7XG4gICAgICAvLyBqb2luIGVhY2ggaXRlbSBpbiB0aGUgYXJyYXkgaW50byBhIHN0cmluZyB3aGVyZSBlYWNoIGl0ZW0gaXMgc2VwYXJhdGVkIGJ5IHNlcGFyYXRvclxuICAgICAgLy8gYmUgc3VyZSB0byBtYWludGFpbiBpbmRlbnRhdGlvblxuICAgICAgY29uc3QgaW5kZW50ID0gcmVzdWx0U29GYXIubWF0Y2goLyhcXG4/W15cXFNcXG5dKykkLyk7XG4gICAgICBpZiAoaW5kZW50KSB7XG4gICAgICAgIHN1YnN0aXR1dGlvbiA9IHN1YnN0aXR1dGlvbi5qb2luKHNlcGFyYXRvciArIGluZGVudFsxXSk7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICBzdWJzdGl0dXRpb24gPSBzdWJzdGl0dXRpb24uam9pbihzZXBhcmF0b3IgKyAnICcpO1xuICAgICAgfVxuICAgICAgLy8gaWYgY29uanVuY3Rpb24gaXMgc2V0LCByZXBsYWNlIHRoZSBsYXN0IHNlcGFyYXRvciB3aXRoIGNvbmp1bmN0aW9uLCBidXQgb25seSBpZiB0aGVyZSBpcyBtb3JlIHRoYW4gb25lIHN1YnN0aXR1dGlvblxuICAgICAgaWYgKGNvbmp1bmN0aW9uICYmIGFycmF5TGVuZ3RoID4gMSkge1xuICAgICAgICBjb25zdCBzZXBhcmF0b3JJbmRleCA9IHN1YnN0aXR1dGlvbi5sYXN0SW5kZXhPZihzZXBhcmF0b3IpO1xuICAgICAgICBzdWJzdGl0dXRpb24gPVxuICAgICAgICAgIHN1YnN0aXR1dGlvbi5zbGljZSgwLCBzZXBhcmF0b3JJbmRleCkgK1xuICAgICAgICAgIChzZXJpYWwgPyBzZXBhcmF0b3IgOiAnJykgK1xuICAgICAgICAgICcgJyArXG4gICAgICAgICAgY29uanVuY3Rpb24gK1xuICAgICAgICAgIHN1YnN0aXR1dGlvbi5zbGljZShzZXBhcmF0b3JJbmRleCArIDEpO1xuICAgICAgfVxuICAgIH1cbiAgICByZXR1cm4gc3Vic3RpdHV0aW9uO1xuICB9LFxufSk7XG5cbmV4cG9ydCBkZWZhdWx0IGlubGluZUFycmF5VHJhbnNmb3JtZXI7XG4iXX0=
|
|
@ -1,3 +0,0 @@
|
|||||||
import _default from './inlineLists';
|
|
||||||
export { _default as default };
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9pbmxpbmVMaXN0cy9pbmRleC5qcyJdLCJuYW1lcyI6WyJkZWZhdWx0Il0sIm1hcHBpbmdzIjoicUJBQW9CLGU7cUJBQWJBLE8iLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZGVmYXVsdCBmcm9tICcuL2lubGluZUxpc3RzJztcbiJdfQ==
|
|
@ -1,9 +0,0 @@
|
|||||||
import TemplateTag from '../TemplateTag';
|
|
||||||
import stripIndentTransformer from '../stripIndentTransformer';
|
|
||||||
import inlineArrayTransformer from '../inlineArrayTransformer';
|
|
||||||
import trimResultTransformer from '../trimResultTransformer';
|
|
||||||
|
|
||||||
var inlineLists = new TemplateTag(inlineArrayTransformer, stripIndentTransformer, trimResultTransformer);
|
|
||||||
|
|
||||||
export default inlineLists;
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9pbmxpbmVMaXN0cy9pbmxpbmVMaXN0cy5qcyJdLCJuYW1lcyI6WyJUZW1wbGF0ZVRhZyIsInN0cmlwSW5kZW50VHJhbnNmb3JtZXIiLCJpbmxpbmVBcnJheVRyYW5zZm9ybWVyIiwidHJpbVJlc3VsdFRyYW5zZm9ybWVyIiwiaW5saW5lTGlzdHMiXSwibWFwcGluZ3MiOiJBQUFBLE9BQU9BLFdBQVAsTUFBd0IsZ0JBQXhCO0FBQ0EsT0FBT0Msc0JBQVAsTUFBbUMsMkJBQW5DO0FBQ0EsT0FBT0Msc0JBQVAsTUFBbUMsMkJBQW5DO0FBQ0EsT0FBT0MscUJBQVAsTUFBa0MsMEJBQWxDOztBQUVBLElBQU1DLGNBQWMsSUFBSUosV0FBSixDQUNsQkUsc0JBRGtCLEVBRWxCRCxzQkFGa0IsRUFHbEJFLHFCQUhrQixDQUFwQjs7QUFNQSxlQUFlQyxXQUFmIiwiZmlsZSI6ImlubGluZUxpc3RzLmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFRlbXBsYXRlVGFnIGZyb20gJy4uL1RlbXBsYXRlVGFnJztcbmltcG9ydCBzdHJpcEluZGVudFRyYW5zZm9ybWVyIGZyb20gJy4uL3N0cmlwSW5kZW50VHJhbnNmb3JtZXInO1xuaW1wb3J0IGlubGluZUFycmF5VHJhbnNmb3JtZXIgZnJvbSAnLi4vaW5saW5lQXJyYXlUcmFuc2Zvcm1lcic7XG5pbXBvcnQgdHJpbVJlc3VsdFRyYW5zZm9ybWVyIGZyb20gJy4uL3RyaW1SZXN1bHRUcmFuc2Zvcm1lcic7XG5cbmNvbnN0IGlubGluZUxpc3RzID0gbmV3IFRlbXBsYXRlVGFnKFxuICBpbmxpbmVBcnJheVRyYW5zZm9ybWVyLFxuICBzdHJpcEluZGVudFRyYW5zZm9ybWVyLFxuICB0cmltUmVzdWx0VHJhbnNmb3JtZXIsXG4pO1xuXG5leHBvcnQgZGVmYXVsdCBpbmxpbmVMaXN0cztcbiJdfQ==
|
|
@ -1,3 +0,0 @@
|
|||||||
import _default from './oneLine';
|
|
||||||
export { _default as default };
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9vbmVMaW5lL2luZGV4LmpzIl0sIm5hbWVzIjpbImRlZmF1bHQiXSwibWFwcGluZ3MiOiJxQkFBb0IsVztxQkFBYkEsTyIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBkZWZhdWx0IGZyb20gJy4vb25lTGluZSc7XG4iXX0=
|
|
@ -1,8 +0,0 @@
|
|||||||
import TemplateTag from '../TemplateTag';
|
|
||||||
import trimResultTransformer from '../trimResultTransformer';
|
|
||||||
import replaceResultTransformer from '../replaceResultTransformer';
|
|
||||||
|
|
||||||
var oneLine = new TemplateTag(replaceResultTransformer(/(?:\n(?:\s*))+/g, ' '), trimResultTransformer);
|
|
||||||
|
|
||||||
export default oneLine;
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9vbmVMaW5lL29uZUxpbmUuanMiXSwibmFtZXMiOlsiVGVtcGxhdGVUYWciLCJ0cmltUmVzdWx0VHJhbnNmb3JtZXIiLCJyZXBsYWNlUmVzdWx0VHJhbnNmb3JtZXIiLCJvbmVMaW5lIl0sIm1hcHBpbmdzIjoiQUFBQSxPQUFPQSxXQUFQLE1BQXdCLGdCQUF4QjtBQUNBLE9BQU9DLHFCQUFQLE1BQWtDLDBCQUFsQztBQUNBLE9BQU9DLHdCQUFQLE1BQXFDLDZCQUFyQzs7QUFFQSxJQUFNQyxVQUFVLElBQUlILFdBQUosQ0FDZEUseUJBQXlCLGlCQUF6QixFQUE0QyxHQUE1QyxDQURjLEVBRWRELHFCQUZjLENBQWhCOztBQUtBLGVBQWVFLE9BQWYiLCJmaWxlIjoib25lTGluZS5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBUZW1wbGF0ZVRhZyBmcm9tICcuLi9UZW1wbGF0ZVRhZyc7XG5pbXBvcnQgdHJpbVJlc3VsdFRyYW5zZm9ybWVyIGZyb20gJy4uL3RyaW1SZXN1bHRUcmFuc2Zvcm1lcic7XG5pbXBvcnQgcmVwbGFjZVJlc3VsdFRyYW5zZm9ybWVyIGZyb20gJy4uL3JlcGxhY2VSZXN1bHRUcmFuc2Zvcm1lcic7XG5cbmNvbnN0IG9uZUxpbmUgPSBuZXcgVGVtcGxhdGVUYWcoXG4gIHJlcGxhY2VSZXN1bHRUcmFuc2Zvcm1lcigvKD86XFxuKD86XFxzKikpKy9nLCAnICcpLFxuICB0cmltUmVzdWx0VHJhbnNmb3JtZXIsXG4pO1xuXG5leHBvcnQgZGVmYXVsdCBvbmVMaW5lO1xuIl19
|
|
@ -1,3 +0,0 @@
|
|||||||
import _default from './oneLineCommaLists';
|
|
||||||
export { _default as default };
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9vbmVMaW5lQ29tbWFMaXN0cy9pbmRleC5qcyJdLCJuYW1lcyI6WyJkZWZhdWx0Il0sIm1hcHBpbmdzIjoicUJBQW9CLHFCO3FCQUFiQSxPIiwiZmlsZSI6ImluZGV4LmpzIiwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGRlZmF1bHQgZnJvbSAnLi9vbmVMaW5lQ29tbWFMaXN0cyc7XG4iXX0=
|
|
@ -1,9 +0,0 @@
|
|||||||
import TemplateTag from '../TemplateTag';
|
|
||||||
import inlineArrayTransformer from '../inlineArrayTransformer';
|
|
||||||
import trimResultTransformer from '../trimResultTransformer';
|
|
||||||
import replaceResultTransformer from '../replaceResultTransformer';
|
|
||||||
|
|
||||||
var oneLineCommaLists = new TemplateTag(inlineArrayTransformer({ separator: ',' }), replaceResultTransformer(/(?:\s+)/g, ' '), trimResultTransformer);
|
|
||||||
|
|
||||||
export default oneLineCommaLists;
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9vbmVMaW5lQ29tbWFMaXN0cy9vbmVMaW5lQ29tbWFMaXN0cy5qcyJdLCJuYW1lcyI6WyJUZW1wbGF0ZVRhZyIsImlubGluZUFycmF5VHJhbnNmb3JtZXIiLCJ0cmltUmVzdWx0VHJhbnNmb3JtZXIiLCJyZXBsYWNlUmVzdWx0VHJhbnNmb3JtZXIiLCJvbmVMaW5lQ29tbWFMaXN0cyIsInNlcGFyYXRvciJdLCJtYXBwaW5ncyI6IkFBQUEsT0FBT0EsV0FBUCxNQUF3QixnQkFBeEI7QUFDQSxPQUFPQyxzQkFBUCxNQUFtQywyQkFBbkM7QUFDQSxPQUFPQyxxQkFBUCxNQUFrQywwQkFBbEM7QUFDQSxPQUFPQyx3QkFBUCxNQUFxQyw2QkFBckM7O0FBRUEsSUFBTUMsb0JBQW9CLElBQUlKLFdBQUosQ0FDeEJDLHVCQUF1QixFQUFFSSxXQUFXLEdBQWIsRUFBdkIsQ0FEd0IsRUFFeEJGLHlCQUF5QixVQUF6QixFQUFxQyxHQUFyQyxDQUZ3QixFQUd4QkQscUJBSHdCLENBQTFCOztBQU1BLGVBQWVFLGlCQUFmIiwiZmlsZSI6Im9uZUxpbmVDb21tYUxpc3RzLmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFRlbXBsYXRlVGFnIGZyb20gJy4uL1RlbXBsYXRlVGFnJztcbmltcG9ydCBpbmxpbmVBcnJheVRyYW5zZm9ybWVyIGZyb20gJy4uL2lubGluZUFycmF5VHJhbnNmb3JtZXInO1xuaW1wb3J0IHRyaW1SZXN1bHRUcmFuc2Zvcm1lciBmcm9tICcuLi90cmltUmVzdWx0VHJhbnNmb3JtZXInO1xuaW1wb3J0IHJlcGxhY2VSZXN1bHRUcmFuc2Zvcm1lciBmcm9tICcuLi9yZXBsYWNlUmVzdWx0VHJhbnNmb3JtZXInO1xuXG5jb25zdCBvbmVMaW5lQ29tbWFMaXN0cyA9IG5ldyBUZW1wbGF0ZVRhZyhcbiAgaW5saW5lQXJyYXlUcmFuc2Zvcm1lcih7IHNlcGFyYXRvcjogJywnIH0pLFxuICByZXBsYWNlUmVzdWx0VHJhbnNmb3JtZXIoLyg/OlxccyspL2csICcgJyksXG4gIHRyaW1SZXN1bHRUcmFuc2Zvcm1lcixcbik7XG5cbmV4cG9ydCBkZWZhdWx0IG9uZUxpbmVDb21tYUxpc3RzO1xuIl19
|
|
@ -1,3 +0,0 @@
|
|||||||
import _default from './oneLineCommaListsAnd';
|
|
||||||
export { _default as default };
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9vbmVMaW5lQ29tbWFMaXN0c0FuZC9pbmRleC5qcyJdLCJuYW1lcyI6WyJkZWZhdWx0Il0sIm1hcHBpbmdzIjoicUJBQW9CLHdCO3FCQUFiQSxPIiwiZmlsZSI6ImluZGV4LmpzIiwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGRlZmF1bHQgZnJvbSAnLi9vbmVMaW5lQ29tbWFMaXN0c0FuZCc7XG4iXX0=
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue