forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode-buffer-concat.ts
More file actions
28 lines (25 loc) · 971 Bytes
/
node-buffer-concat.ts
File metadata and controls
28 lines (25 loc) · 971 Bytes
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
import assert from '../../harness/wrapped-assert';
export default function() {
var zero: Buffer[] = [];
var one = [ new Buffer('asdf') ];
var _long: Buffer[] = [];
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(<any> [42]);
}, TypeError);
// BFS: Adding for good measure.
assert.throws(function() {
Buffer.concat(<any> [42], 10);
}, TypeError);
};