1 | /** global: aesCrypt */ |
||
2 | |||
3 | /** |
||
4 | * binary array stream object |
||
5 | * |
||
6 | * |
||
7 | * @return The BinaryStream object. |
||
8 | * |
||
9 | * @static |
||
10 | * |
||
11 | * @example |
||
12 | * var BinaryStream = BinaryStream([1,2,3]); |
||
13 | * BinaryStream.appendBytes([4,5,6]); |
||
14 | * BinaryStream.appendBytes("\x07\x08\x09"); |
||
15 | * console.log(BinaryStream.finalize()) // returns Uint8Array [1,2,3,4,5,6,7,8,9] |
||
16 | * |
||
17 | * @param arr origin array |
||
18 | */ |
||
19 | |||
20 | (function () { |
||
21 | let LIB = aesCrypt; |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
22 | aesCrypt.BinaryStream = function(arr = []) { |
||
23 | let _data = new Uint8Array(arr); |
||
24 | |||
25 | function appendBytes(input) { |
||
26 | let tmp = []; |
||
27 | |||
28 | if (typeof (input) == "number") { |
||
29 | let hex = input.toString(16); |
||
30 | tmp = hex.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)); |
||
31 | } else if (typeof (input) == "string") { |
||
32 | for (let i = 0; i < input.length; i ++) { |
||
33 | tmp.push(input.charCodeAt(i)); |
||
34 | } |
||
35 | } else { |
||
36 | tmp = input; |
||
37 | } |
||
38 | |||
39 | tmp = new Uint8Array(tmp); |
||
40 | |||
41 | let tmpArr = new Uint8Array(_data.length + tmp.length); |
||
42 | |||
43 | tmpArr.set(_data); |
||
44 | tmpArr.set(tmp, _data.length); |
||
45 | |||
46 | _data = tmpArr; |
||
47 | } |
||
48 | |||
49 | function finalize() { |
||
50 | return _data; |
||
51 | } |
||
52 | |||
53 | function getLength() { |
||
54 | return _data.length; |
||
55 | } |
||
56 | |||
57 | return { |
||
58 | appendBytes, |
||
59 | finalize, |
||
60 | getLength, |
||
61 | }; |
||
62 | }; |
||
63 | }()); |