diff options
Diffstat (limited to '')
-rw-r--r-- | llparse-builder/src/utils.ts | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/llparse-builder/src/utils.ts b/llparse-builder/src/utils.ts new file mode 100644 index 0000000..3521b20 --- /dev/null +++ b/llparse-builder/src/utils.ts @@ -0,0 +1,19 @@ +import * as assert from 'assert'; +import { Buffer } from 'buffer'; + +/** + * Internal + */ +export function toBuffer(value: number | string | Buffer): Buffer { + let res: Buffer; + if (Buffer.isBuffer(value)) { + res = value; + } else if (typeof value === 'string') { + res = Buffer.from(value); + } else { + assert(0 <= value && value <= 0xff, 'Invalid byte value'); + res = Buffer.from([ value ]); + } + assert(res.length >= 1, 'Invalid key length'); + return res; +} |