Passed
Push — master ( ed6a26...4f5e17 )
by Rafael S.
01:43
created
Severity
1
/*!
2
 * byte-data
3
 * Readable data to and from bytes.
4
 * Copyright (c) 2017 Rafael da Silva Rocha.
5
 * https://github.com/rochars/byte-data
6
 */
7
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');
0 ignored issues
show
The variable writer seems to be never used. Consider removing it.
Loading history...
12
let reader = require('./src/read-bytes');
0 ignored issues
show
The variable reader seems to be never used. Consider removing it.
Loading history...
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