Total Complexity | 3 |
Complexity/F | 3 |
Lines of Code | 35 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 6 | ||
Bugs | 0 | Features | 0 |
1 | /*! |
||
8 | let toBytes = require('./src/to-bytes'); |
||
9 | let fromBytes = require('./src/from-bytes'); |
||
10 | let bitPacker = require('./src/bit-packer'); |
||
11 | let writer = require('./src/write-bytes'); |
||
|
|||
12 | let reader = require('./src/read-bytes'); |
||
13 | |||
14 | /** |
||
15 | * Find and return the start offset of some string. |
||
16 | * @param {!Array<number>|Uint8Array} bytes Array of bytes. |
||
17 | * @param {string} chunk Some string to look for. |
||
18 | * @return {number} The start offset of the first occurrence found. |
||
19 | */ |
||
20 | function findString(bytes, chunk) { |
||
21 | let found = ""; |
||
22 | for (let i = 0; i < bytes.length; i++) { |
||
23 | found = fromBytes.fromBytes(bytes.slice(i, i + chunk.length), |
||
24 | 8, {"char": true}); |
||
25 | if (found == chunk) { |
||
26 | return i; |
||
27 | } |
||
28 | } |
||
29 | return -1; |
||
30 | } |
||
31 | |||
32 | module.exports.packBooleans = bitPacker.packBooleans; |
||
33 | module.exports.unpackBooleans = bitPacker.unpackBooleans; |
||
34 | module.exports.packCrumbs = bitPacker.packCrumbs; |
||
35 | module.exports.unpackCrumbs = bitPacker.unpackCrumbs; |
||
36 | module.exports.packNibbles = bitPacker.packNibbles; |
||
37 | module.exports.unpackNibbles = bitPacker.unpackNibbles; |
||
38 | |||
39 | module.exports.findString = findString; |
||
40 | |||
41 | module.exports.toBytes = toBytes.toBytes; |
||
42 | module.exports.fromBytes = fromBytes.fromBytes; |
||
43 |