1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | exports.BufferType = void 0;
|
8 | const tslib_1 = require("tslib");
|
9 | const util_1 = tslib_1.__importDefault(require("util"));
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | class BufferType {
|
15 | constructor() {
|
16 | this.name = 'buffer';
|
17 | }
|
18 | isInstance(value) {
|
19 | return value == null || Buffer.isBuffer(value);
|
20 | }
|
21 | defaultValue() {
|
22 | return Buffer.from([]);
|
23 | }
|
24 | isCoercible(value) {
|
25 | if (value == null)
|
26 | return true;
|
27 | if (typeof value === 'string')
|
28 | return true;
|
29 | if (Buffer.isBuffer(value))
|
30 | return true;
|
31 | if (Array.isArray(value))
|
32 | return true;
|
33 | return false;
|
34 | }
|
35 | coerce(value, options) {
|
36 | if (value == null)
|
37 | return value;
|
38 | if (Buffer.isBuffer(value))
|
39 | return value;
|
40 | if (typeof value === 'string') {
|
41 | options = options !== null && options !== void 0 ? options : {};
|
42 | const encoding = options.encoding || 'utf-8';
|
43 | return Buffer.from(value, encoding);
|
44 | }
|
45 | else if (Array.isArray(value)) {
|
46 | return Buffer.from(value);
|
47 | }
|
48 | const msg = util_1.default.format('Invalid %s: %j', this.name, value);
|
49 | throw new TypeError(msg);
|
50 | }
|
51 | serialize(value, options) {
|
52 | if (value == null)
|
53 | return value;
|
54 | const encoding = (options === null || options === void 0 ? void 0 : options.encoding) || 'base64';
|
55 | return value.toString(encoding);
|
56 | }
|
57 | }
|
58 | exports.BufferType = BufferType;
|
59 |
|
\ | No newline at end of file |