rochars /
byte-data
| 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
Unused Code
introduced
by
Loading history...
|
|||
| 12 | let reader = require('./src/read-bytes'); |
||
|
0 ignored issues
–
show
|
|||
| 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.stringFromBytes(bytes.slice(i, i + chunk.length)); |
||
| 24 | if (found == chunk) { |
||
| 25 | return i; |
||
| 26 | } |
||
| 27 | } |
||
| 28 | return -1; |
||
| 29 | } |
||
| 30 | |||
| 31 | module.exports.packBooleans = bitPacker.packBooleans; |
||
| 32 | module.exports.unpackBooleans = bitPacker.unpackBooleans; |
||
| 33 | module.exports.packCrumbs = bitPacker.packCrumbs; |
||
| 34 | module.exports.unpackCrumbs = bitPacker.unpackCrumbs; |
||
| 35 | module.exports.packNibbles = bitPacker.packNibbles; |
||
| 36 | module.exports.unpackNibbles = bitPacker.unpackNibbles; |
||
| 37 | |||
| 38 | module.exports.findString = findString; |
||
| 39 | module.exports.stringToBytes = toBytes.stringToBytes; |
||
| 40 | module.exports.stringFromBytes = fromBytes.stringFromBytes; |
||
| 41 | |||
| 42 | module.exports.doubleTo8Bytes = toBytes.floatTo8Bytes; |
||
| 43 | module.exports.floatTo8Bytes = toBytes.floatTo8Bytes; |
||
| 44 | module.exports.floatTo4Bytes = toBytes.floatTo4Bytes; |
||
| 45 | module.exports.intTo6Bytes = toBytes.intTo6Bytes; |
||
| 46 | module.exports.intTo5Bytes = toBytes.intTo5Bytes; |
||
| 47 | module.exports.intTo4Bytes = toBytes.intTo4Bytes; |
||
| 48 | module.exports.intTo3Bytes = toBytes.intTo3Bytes; |
||
| 49 | module.exports.intTo2Bytes = toBytes.intTo2Bytes; |
||
| 50 | module.exports.floatTo2Bytes = toBytes.floatTo2Bytes; |
||
| 51 | module.exports.intTo1Byte = toBytes.intTo1Byte; |
||
| 52 | module.exports.intToNibble = toBytes.intToNibble; |
||
| 53 | module.exports.toCrumb = toBytes.toCrumb; |
||
| 54 | module.exports.toBoolean = toBytes.toBoolean; |
||
| 55 | |||
| 56 | module.exports.floatFrom8Bytes = fromBytes.floatFrom8Bytes; |
||
| 57 | module.exports.doubleFrom8Bytes = fromBytes.floatFrom8Bytes; |
||
| 58 | module.exports.intFrom6Bytes = fromBytes.intFrom6Bytes; |
||
| 59 | module.exports.uIntFrom6Bytes = fromBytes.uIntFrom6Bytes; |
||
| 60 | module.exports.intFrom5Bytes = fromBytes.intFrom5Bytes; |
||
| 61 | module.exports.uIntFrom5Bytes = fromBytes.uIntFrom5Bytes; |
||
| 62 | module.exports.intFrom4Bytes = fromBytes.intFrom4Bytes; |
||
| 63 | module.exports.uIntFrom4Bytes = fromBytes.uIntFrom4Bytes; |
||
| 64 | module.exports.floatFrom4Bytes = fromBytes.floatFrom4Bytes; |
||
| 65 | module.exports.intFrom3Bytes = fromBytes.intFrom3Bytes; |
||
| 66 | module.exports.uIntFrom3Bytes = fromBytes.uIntFrom3Bytes; |
||
| 67 | module.exports.floatFrom2Bytes = fromBytes.floatFrom2Bytes; |
||
| 68 | module.exports.intFrom2Bytes = fromBytes.intFrom2Bytes; |
||
| 69 | module.exports.uIntFrom2Bytes = fromBytes.uIntFrom2Bytes; |
||
| 70 | module.exports.intFrom1Byte = fromBytes.intFrom1Byte; |
||
| 71 | module.exports.uIntFrom1Byte = fromBytes.uIntFrom1Byte; |
||
| 72 | module.exports.intFromNibble = fromBytes.intFromNibble; |
||
| 73 | module.exports.uIntFromNibble = fromBytes.uIntFromNibble; |
||
| 74 | module.exports.intFromCrumb = fromBytes.intFromCrumb; |
||
| 75 | module.exports.uIntFromCrumb = fromBytes.uIntFromCrumb; |
||
| 76 | module.exports.fromBoolean = fromBytes.fromBoolean; |
||
| 77 |