@netlify/plugin-nextjs 4.40.0 → 4.40.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/lib/helpers/edge.js +4 -2
  2. package/lib/templates/getHandler.js +1 -2
  3. package/lib/templates/handlerUtils.js +14 -1
  4. package/lib/templates/server.js +9 -8
  5. package/lib/templates/vendor.js +20 -0
  6. package/package.json +7 -4
  7. package/src/templates/edge/next-dev.js +3 -3
  8. package/src/templates/edge/shims.js +6 -6
  9. package/src/templates/edge-shared/next-utils.ts +3 -3
  10. package/src/templates/edge-shared/utils.ts +1 -1
  11. package/src/templates/vendor/deno.land/std@0.134.0/fmt/colors.ts +536 -0
  12. package/src/templates/vendor/deno.land/std@0.134.0/testing/_diff.ts +360 -0
  13. package/src/templates/vendor/deno.land/std@0.134.0/testing/asserts.ts +866 -0
  14. package/src/templates/vendor/deno.land/std@0.175.0/_util/asserts.ts +25 -0
  15. package/src/templates/vendor/deno.land/std@0.175.0/_util/os.ts +23 -0
  16. package/src/templates/vendor/deno.land/std@0.175.0/async/abortable.ts +149 -0
  17. package/src/templates/vendor/deno.land/std@0.175.0/async/deadline.ts +30 -0
  18. package/src/templates/vendor/deno.land/std@0.175.0/async/debounce.ts +79 -0
  19. package/src/templates/vendor/deno.land/std@0.175.0/async/deferred.ts +48 -0
  20. package/src/templates/vendor/deno.land/std@0.175.0/async/delay.ts +67 -0
  21. package/src/templates/vendor/deno.land/std@0.175.0/async/mod.ts +18 -0
  22. package/src/templates/vendor/deno.land/std@0.175.0/async/mux_async_iterator.ts +97 -0
  23. package/src/templates/vendor/deno.land/std@0.175.0/async/pool.ts +95 -0
  24. package/src/templates/vendor/deno.land/std@0.175.0/async/retry.ts +81 -0
  25. package/src/templates/vendor/deno.land/std@0.175.0/async/tee.ts +100 -0
  26. package/src/templates/vendor/deno.land/std@0.175.0/bytes/index_of_needle.ts +49 -0
  27. package/src/templates/vendor/deno.land/std@0.175.0/crypto/timing_safe_equal.ts +29 -0
  28. package/src/templates/vendor/deno.land/std@0.175.0/datetime/to_imf.ts +45 -0
  29. package/src/templates/vendor/deno.land/std@0.175.0/encoding/base64.ts +144 -0
  30. package/src/templates/vendor/deno.land/std@0.175.0/encoding/base64url.ts +70 -0
  31. package/src/templates/vendor/deno.land/std@0.175.0/flags/mod.ts +785 -0
  32. package/src/templates/vendor/deno.land/std@0.175.0/fmt/colors.ts +569 -0
  33. package/src/templates/vendor/deno.land/std@0.175.0/fmt/printf.ts +939 -0
  34. package/src/templates/vendor/deno.land/std@0.175.0/http/cookie.ts +403 -0
  35. package/src/templates/vendor/deno.land/std@0.175.0/node/_core.ts +77 -0
  36. package/src/templates/vendor/deno.land/std@0.175.0/node/_events.d.ts +848 -0
  37. package/src/templates/vendor/deno.land/std@0.175.0/node/_events.mjs +1033 -0
  38. package/src/templates/vendor/deno.land/std@0.175.0/node/_global.d.ts +66 -0
  39. package/src/templates/vendor/deno.land/std@0.175.0/node/_next_tick.ts +173 -0
  40. package/src/templates/vendor/deno.land/std@0.175.0/node/_process/exiting.ts +4 -0
  41. package/src/templates/vendor/deno.land/std@0.175.0/node/_process/process.ts +131 -0
  42. package/src/templates/vendor/deno.land/std@0.175.0/node/_process/stdio.mjs +7 -0
  43. package/src/templates/vendor/deno.land/std@0.175.0/node/_process/streams.mjs +146 -0
  44. package/src/templates/vendor/deno.land/std@0.175.0/node/_stream.d.ts +1488 -0
  45. package/src/templates/vendor/deno.land/std@0.175.0/node/_stream.mjs +746 -0
  46. package/src/templates/vendor/deno.land/std@0.175.0/node/_util/_util_callbackify.ts +129 -0
  47. package/src/templates/vendor/deno.land/std@0.175.0/node/_utils.ts +206 -0
  48. package/src/templates/vendor/deno.land/std@0.175.0/node/assert.ts +940 -0
  49. package/src/templates/vendor/deno.land/std@0.175.0/node/assertion_error.ts +579 -0
  50. package/src/templates/vendor/deno.land/std@0.175.0/node/async_hooks.ts +331 -0
  51. package/src/templates/vendor/deno.land/std@0.175.0/node/buffer.ts +13 -0
  52. package/src/templates/vendor/deno.land/std@0.175.0/node/events.ts +14 -0
  53. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/buffer.d.ts +2074 -0
  54. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/buffer.mjs +2607 -0
  55. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/crypto/_keys.ts +16 -0
  56. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/crypto/constants.ts +5 -0
  57. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/error_codes.ts +7 -0
  58. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/errors.ts +2867 -0
  59. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/fixed_queue.ts +123 -0
  60. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/hide_stack_frames.ts +16 -0
  61. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/net.ts +95 -0
  62. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/normalize_encoding.mjs +72 -0
  63. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/options.ts +45 -0
  64. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/primordials.mjs +30 -0
  65. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/process/per_thread.mjs +272 -0
  66. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/readline/callbacks.mjs +137 -0
  67. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/readline/utils.mjs +580 -0
  68. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/destroy.mjs +320 -0
  69. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/end-of-stream.mjs +229 -0
  70. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/utils.mjs +242 -0
  71. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/comparisons.ts +669 -0
  72. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/debuglog.ts +118 -0
  73. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/inspect.mjs +2237 -0
  74. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/types.ts +113 -0
  75. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util.mjs +143 -0
  76. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/validators.mjs +317 -0
  77. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_libuv_winerror.ts +229 -0
  78. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_listen.ts +16 -0
  79. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_node.ts +18 -0
  80. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_timingSafeEqual.ts +12 -0
  81. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_utils.ts +86 -0
  82. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_winerror.ts +16873 -0
  83. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/ares.ts +66 -0
  84. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/async_wrap.ts +152 -0
  85. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/buffer.ts +130 -0
  86. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/cares_wrap.ts +541 -0
  87. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/config.ts +3 -0
  88. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/connection_wrap.ts +80 -0
  89. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/constants.ts +900 -0
  90. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/contextify.ts +3 -0
  91. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/credentials.ts +3 -0
  92. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/crypto.ts +14 -0
  93. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/errors.ts +3 -0
  94. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs.ts +3 -0
  95. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs_dir.ts +3 -0
  96. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs_event_wrap.ts +3 -0
  97. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/handle_wrap.ts +50 -0
  98. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/heap_utils.ts +3 -0
  99. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/http_parser.ts +3 -0
  100. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/icu.ts +3 -0
  101. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/inspector.ts +3 -0
  102. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/js_stream.ts +3 -0
  103. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/messaging.ts +3 -0
  104. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/mod.ts +108 -0
  105. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/module_wrap.ts +3 -0
  106. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/native_module.ts +3 -0
  107. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/natives.ts +3 -0
  108. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/node_file.ts +84 -0
  109. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/node_options.ts +39 -0
  110. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/options.ts +3 -0
  111. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/os.ts +3 -0
  112. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/performance.ts +3 -0
  113. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/pipe_wrap.ts +392 -0
  114. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/process_methods.ts +3 -0
  115. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/report.ts +3 -0
  116. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/serdes.ts +3 -0
  117. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/signal_wrap.ts +3 -0
  118. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/spawn_sync.ts +3 -0
  119. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/stream_wrap.ts +354 -0
  120. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/string_decoder.ts +15 -0
  121. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/symbols.ts +27 -0
  122. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/task_queue.ts +3 -0
  123. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tcp_wrap.ts +488 -0
  124. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/timers.ts +3 -0
  125. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tls_wrap.ts +3 -0
  126. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/trace_events.ts +3 -0
  127. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tty_wrap.ts +3 -0
  128. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/types.ts +186 -0
  129. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/udp_wrap.ts +496 -0
  130. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/url.ts +3 -0
  131. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/util.ts +126 -0
  132. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/uv.ts +437 -0
  133. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/v8.ts +3 -0
  134. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/worker.ts +3 -0
  135. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/zlib.ts +3 -0
  136. package/src/templates/vendor/deno.land/std@0.175.0/node/process.ts +705 -0
  137. package/src/templates/vendor/deno.land/std@0.175.0/node/stream.ts +37 -0
  138. package/src/templates/vendor/deno.land/std@0.175.0/node/string_decoder.ts +337 -0
  139. package/src/templates/vendor/deno.land/std@0.175.0/node/util/types.ts +4 -0
  140. package/src/templates/vendor/deno.land/std@0.175.0/node/util.ts +289 -0
  141. package/src/templates/vendor/deno.land/std@0.175.0/path/_constants.ts +49 -0
  142. package/src/templates/vendor/deno.land/std@0.175.0/path/_interface.ts +30 -0
  143. package/src/templates/vendor/deno.land/std@0.175.0/path/_util.ts +194 -0
  144. package/src/templates/vendor/deno.land/std@0.175.0/path/common.ts +40 -0
  145. package/src/templates/vendor/deno.land/std@0.175.0/path/glob.ts +418 -0
  146. package/src/templates/vendor/deno.land/std@0.175.0/path/mod.ts +53 -0
  147. package/src/templates/vendor/deno.land/std@0.175.0/path/posix.ts +487 -0
  148. package/src/templates/vendor/deno.land/std@0.175.0/path/separator.ts +7 -0
  149. package/src/templates/vendor/deno.land/std@0.175.0/path/win32.ts +962 -0
  150. package/src/templates/vendor/deno.land/std@0.175.0/streams/write_all.ts +64 -0
  151. package/src/templates/vendor/deno.land/std@0.175.0/testing/_diff.ts +440 -0
  152. package/src/templates/vendor/deno.land/std@0.175.0/testing/_format.ts +23 -0
  153. package/src/templates/vendor/deno.land/std@0.175.0/testing/asserts.ts +906 -0
  154. package/src/templates/vendor/deno.land/std@0.175.0/types.d.ts +89 -0
  155. package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/index.ts +133 -0
  156. package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/asyncify.js +112 -0
  157. package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.d.ts +88 -0
  158. package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.js +974 -0
  159. package/src/templates/vendor/deno.land/x/path_to_regexp@v6.2.1/index.ts +621 -0
  160. package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/compiled/cookie.js +13 -0
  161. package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/request.js +12 -0
  162. package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/response.js +5 -0
  163. package/src/templates/vendor/import_map.json +13 -0
  164. package/src/templates/vendor/raw.githubusercontent.com/worker-tools/resolvable-promise/master/index.ts +50 -0
@@ -0,0 +1,2607 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ // Copyright Joyent and Node contributors. All rights reserved. MIT license.
3
+ // Copyright Feross Aboukhadijeh, and other contributors. All rights reserved. MIT license.
4
+
5
+ import { codes } from "./error_codes.ts";
6
+ import { encodings } from "../internal_binding/string_decoder.ts";
7
+ import { indexOfBuffer, indexOfNumber } from "../internal_binding/buffer.ts";
8
+ import {
9
+ asciiToBytes,
10
+ base64ToBytes,
11
+ base64UrlToBytes,
12
+ bytesToAscii,
13
+ bytesToUtf16le,
14
+ hexToBytes,
15
+ utf16leToBytes,
16
+ } from "../internal_binding/_utils.ts";
17
+ import { isAnyArrayBuffer, isArrayBufferView } from "./util/types.ts";
18
+ import { normalizeEncoding } from "./util.mjs";
19
+ import { validateBuffer } from "./validators.mjs";
20
+ import { isUint8Array } from "./util/types.ts";
21
+ import * as base64 from "../../encoding/base64.ts";
22
+ import * as base64url from "../../encoding/base64url.ts";
23
+
24
+ const utf8Encoder = new TextEncoder();
25
+
26
+ // Temporary buffers to convert numbers.
27
+ const float32Array = new Float32Array(1);
28
+ const uInt8Float32Array = new Uint8Array(float32Array.buffer);
29
+ const float64Array = new Float64Array(1);
30
+ const uInt8Float64Array = new Uint8Array(float64Array.buffer);
31
+
32
+ // Check endianness.
33
+ float32Array[0] = -1; // 0xBF800000
34
+ // Either it is [0, 0, 128, 191] or [191, 128, 0, 0]. It is not possible to
35
+ // check this with `os.endianness()` because that is determined at compile time.
36
+ export const bigEndian = uInt8Float32Array[3] === 0;
37
+
38
+ export const kMaxLength = 2147483647;
39
+ export const kStringMaxLength = 536870888;
40
+ const MAX_UINT32 = 2 ** 32;
41
+
42
+ const customInspectSymbol =
43
+ typeof Symbol === "function" && typeof Symbol["for"] === "function"
44
+ ? Symbol["for"]("nodejs.util.inspect.custom")
45
+ : null;
46
+
47
+ const INSPECT_MAX_BYTES = 50;
48
+
49
+ export const constants = {
50
+ MAX_LENGTH: kMaxLength,
51
+ MAX_STRING_LENGTH: kStringMaxLength,
52
+ };
53
+
54
+ Object.defineProperty(Buffer.prototype, "parent", {
55
+ enumerable: true,
56
+ get: function () {
57
+ if (!Buffer.isBuffer(this)) {
58
+ return void 0;
59
+ }
60
+ return this.buffer;
61
+ },
62
+ });
63
+
64
+ Object.defineProperty(Buffer.prototype, "offset", {
65
+ enumerable: true,
66
+ get: function () {
67
+ if (!Buffer.isBuffer(this)) {
68
+ return void 0;
69
+ }
70
+ return this.byteOffset;
71
+ },
72
+ });
73
+
74
+ function createBuffer(length) {
75
+ if (length > kMaxLength) {
76
+ throw new RangeError(
77
+ 'The value "' + length + '" is invalid for option "size"',
78
+ );
79
+ }
80
+ const buf = new Uint8Array(length);
81
+ Object.setPrototypeOf(buf, Buffer.prototype);
82
+ return buf;
83
+ }
84
+
85
+ export function Buffer(arg, encodingOrOffset, length) {
86
+ if (typeof arg === "number") {
87
+ if (typeof encodingOrOffset === "string") {
88
+ throw new codes.ERR_INVALID_ARG_TYPE(
89
+ "string",
90
+ "string",
91
+ arg,
92
+ );
93
+ }
94
+ return _allocUnsafe(arg);
95
+ }
96
+ return _from(arg, encodingOrOffset, length);
97
+ }
98
+
99
+ Buffer.poolSize = 8192;
100
+
101
+ function _from(value, encodingOrOffset, length) {
102
+ if (typeof value === "string") {
103
+ return fromString(value, encodingOrOffset);
104
+ }
105
+
106
+ if (typeof value === "object" && value !== null) {
107
+ if (isAnyArrayBuffer(value)) {
108
+ return fromArrayBuffer(value, encodingOrOffset, length);
109
+ }
110
+
111
+ const valueOf = value.valueOf && value.valueOf();
112
+ if (
113
+ valueOf != null &&
114
+ valueOf !== value &&
115
+ (typeof valueOf === "string" || typeof valueOf === "object")
116
+ ) {
117
+ return _from(valueOf, encodingOrOffset, length);
118
+ }
119
+
120
+ const b = fromObject(value);
121
+ if (b) {
122
+ return b;
123
+ }
124
+
125
+ if (typeof value[Symbol.toPrimitive] === "function") {
126
+ const primitive = value[Symbol.toPrimitive]("string");
127
+ if (typeof primitive === "string") {
128
+ return fromString(primitive, encodingOrOffset);
129
+ }
130
+ }
131
+ }
132
+
133
+ throw new codes.ERR_INVALID_ARG_TYPE(
134
+ "first argument",
135
+ ["string", "Buffer", "ArrayBuffer", "Array", "Array-like Object"],
136
+ value,
137
+ );
138
+ }
139
+
140
+ Buffer.from = function from(value, encodingOrOffset, length) {
141
+ return _from(value, encodingOrOffset, length);
142
+ };
143
+
144
+ Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
145
+
146
+ Object.setPrototypeOf(Buffer, Uint8Array);
147
+
148
+ function assertSize(size) {
149
+ validateNumber(size, "size");
150
+ if (!(size >= 0 && size <= kMaxLength)) {
151
+ throw new codes.ERR_INVALID_ARG_VALUE.RangeError("size", size);
152
+ }
153
+ }
154
+
155
+ function _alloc(size, fill, encoding) {
156
+ assertSize(size);
157
+
158
+ const buffer = createBuffer(size);
159
+ if (fill !== undefined) {
160
+ if (encoding !== undefined && typeof encoding !== "string") {
161
+ throw new codes.ERR_INVALID_ARG_TYPE(
162
+ "encoding",
163
+ "string",
164
+ encoding,
165
+ );
166
+ }
167
+ return buffer.fill(fill, encoding);
168
+ }
169
+ return buffer;
170
+ }
171
+
172
+ Buffer.alloc = function alloc(size, fill, encoding) {
173
+ return _alloc(size, fill, encoding);
174
+ };
175
+
176
+ function _allocUnsafe(size) {
177
+ assertSize(size);
178
+ return createBuffer(size < 0 ? 0 : checked(size) | 0);
179
+ }
180
+
181
+ Buffer.allocUnsafe = function allocUnsafe(size) {
182
+ return _allocUnsafe(size);
183
+ };
184
+
185
+ Buffer.allocUnsafeSlow = function allocUnsafeSlow(size) {
186
+ return _allocUnsafe(size);
187
+ };
188
+
189
+ function fromString(string, encoding) {
190
+ if (typeof encoding !== "string" || encoding === "") {
191
+ encoding = "utf8";
192
+ }
193
+ if (!Buffer.isEncoding(encoding)) {
194
+ throw new codes.ERR_UNKNOWN_ENCODING(encoding);
195
+ }
196
+ const length = byteLength(string, encoding) | 0;
197
+ let buf = createBuffer(length);
198
+ const actual = buf.write(string, encoding);
199
+ if (actual !== length) {
200
+ buf = buf.slice(0, actual);
201
+ }
202
+ return buf;
203
+ }
204
+
205
+ function fromArrayLike(array) {
206
+ const length = array.length < 0 ? 0 : checked(array.length) | 0;
207
+ const buf = createBuffer(length);
208
+ for (let i = 0; i < length; i += 1) {
209
+ buf[i] = array[i] & 255;
210
+ }
211
+ return buf;
212
+ }
213
+
214
+ function fromObject(obj) {
215
+ if (obj.length !== undefined || isAnyArrayBuffer(obj.buffer)) {
216
+ if (typeof obj.length !== "number") {
217
+ return createBuffer(0);
218
+ }
219
+ return fromArrayLike(obj);
220
+ }
221
+
222
+ if (obj.type === "Buffer" && Array.isArray(obj.data)) {
223
+ return fromArrayLike(obj.data);
224
+ }
225
+ }
226
+
227
+ function checked(length) {
228
+ if (length >= kMaxLength) {
229
+ throw new RangeError(
230
+ "Attempt to allocate Buffer larger than maximum size: 0x" +
231
+ kMaxLength.toString(16) + " bytes",
232
+ );
233
+ }
234
+ return length | 0;
235
+ }
236
+
237
+ export function SlowBuffer(length) {
238
+ assertSize(length);
239
+ return Buffer.alloc(+length);
240
+ }
241
+
242
+ Object.setPrototypeOf(SlowBuffer.prototype, Uint8Array.prototype);
243
+
244
+ Object.setPrototypeOf(SlowBuffer, Uint8Array);
245
+
246
+ Buffer.isBuffer = function isBuffer(b) {
247
+ return b != null && b._isBuffer === true && b !== Buffer.prototype;
248
+ };
249
+
250
+ Buffer.compare = function compare(a, b) {
251
+ if (isInstance(a, Uint8Array)) {
252
+ a = Buffer.from(a, a.offset, a.byteLength);
253
+ }
254
+ if (isInstance(b, Uint8Array)) {
255
+ b = Buffer.from(b, b.offset, b.byteLength);
256
+ }
257
+ if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
258
+ throw new TypeError(
259
+ 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array',
260
+ );
261
+ }
262
+ if (a === b) {
263
+ return 0;
264
+ }
265
+ let x = a.length;
266
+ let y = b.length;
267
+ for (let i = 0, len = Math.min(x, y); i < len; ++i) {
268
+ if (a[i] !== b[i]) {
269
+ x = a[i];
270
+ y = b[i];
271
+ break;
272
+ }
273
+ }
274
+ if (x < y) {
275
+ return -1;
276
+ }
277
+ if (y < x) {
278
+ return 1;
279
+ }
280
+ return 0;
281
+ };
282
+
283
+ Buffer.isEncoding = function isEncoding(encoding) {
284
+ return typeof encoding === "string" && encoding.length !== 0 &&
285
+ normalizeEncoding(encoding) !== undefined;
286
+ };
287
+
288
+ Buffer.concat = function concat(list, length) {
289
+ if (!Array.isArray(list)) {
290
+ throw new codes.ERR_INVALID_ARG_TYPE("list", "Array", list);
291
+ }
292
+
293
+ if (list.length === 0) {
294
+ return Buffer.alloc(0);
295
+ }
296
+
297
+ if (length === undefined) {
298
+ length = 0;
299
+ for (let i = 0; i < list.length; i++) {
300
+ if (list[i].length) {
301
+ length += list[i].length;
302
+ }
303
+ }
304
+ } else {
305
+ validateOffset(length, "length");
306
+ }
307
+
308
+ const buffer = Buffer.allocUnsafe(length);
309
+ let pos = 0;
310
+ for (let i = 0; i < list.length; i++) {
311
+ const buf = list[i];
312
+ if (!isUint8Array(buf)) {
313
+ // TODO(BridgeAR): This should not be of type ERR_INVALID_ARG_TYPE.
314
+ // Instead, find the proper error code for this.
315
+ throw new codes.ERR_INVALID_ARG_TYPE(
316
+ `list[${i}]`,
317
+ ["Buffer", "Uint8Array"],
318
+ list[i],
319
+ );
320
+ }
321
+ pos += _copyActual(buf, buffer, pos, 0, buf.length);
322
+ }
323
+
324
+ // Note: `length` is always equal to `buffer.length` at this point
325
+ if (pos < length) {
326
+ // Zero-fill the remaining bytes if the specified `length` was more than
327
+ // the actual total length, i.e. if we have some remaining allocated bytes
328
+ // there were not initialized.
329
+ buffer.fill(0, pos, length);
330
+ }
331
+
332
+ return buffer;
333
+ };
334
+
335
+ function byteLength(string, encoding) {
336
+ if (typeof string !== "string") {
337
+ if (isArrayBufferView(string) || isAnyArrayBuffer(string)) {
338
+ return string.byteLength;
339
+ }
340
+
341
+ throw new codes.ERR_INVALID_ARG_TYPE(
342
+ "string",
343
+ ["string", "Buffer", "ArrayBuffer"],
344
+ string,
345
+ );
346
+ }
347
+
348
+ const len = string.length;
349
+ const mustMatch = arguments.length > 2 && arguments[2] === true;
350
+ if (!mustMatch && len === 0) {
351
+ return 0;
352
+ }
353
+
354
+ if (!encoding) {
355
+ return (mustMatch ? -1 : byteLengthUtf8(string));
356
+ }
357
+
358
+ const ops = getEncodingOps(encoding);
359
+ if (ops === undefined) {
360
+ return (mustMatch ? -1 : byteLengthUtf8(string));
361
+ }
362
+ return ops.byteLength(string);
363
+ }
364
+
365
+ Buffer.byteLength = byteLength;
366
+
367
+ Buffer.prototype._isBuffer = true;
368
+
369
+ function swap(b, n, m) {
370
+ const i = b[n];
371
+ b[n] = b[m];
372
+ b[m] = i;
373
+ }
374
+
375
+ Buffer.prototype.swap16 = function swap16() {
376
+ const len = this.length;
377
+ if (len % 2 !== 0) {
378
+ throw new RangeError("Buffer size must be a multiple of 16-bits");
379
+ }
380
+ for (let i = 0; i < len; i += 2) {
381
+ swap(this, i, i + 1);
382
+ }
383
+ return this;
384
+ };
385
+
386
+ Buffer.prototype.swap32 = function swap32() {
387
+ const len = this.length;
388
+ if (len % 4 !== 0) {
389
+ throw new RangeError("Buffer size must be a multiple of 32-bits");
390
+ }
391
+ for (let i = 0; i < len; i += 4) {
392
+ swap(this, i, i + 3);
393
+ swap(this, i + 1, i + 2);
394
+ }
395
+ return this;
396
+ };
397
+
398
+ Buffer.prototype.swap64 = function swap64() {
399
+ const len = this.length;
400
+ if (len % 8 !== 0) {
401
+ throw new RangeError("Buffer size must be a multiple of 64-bits");
402
+ }
403
+ for (let i = 0; i < len; i += 8) {
404
+ swap(this, i, i + 7);
405
+ swap(this, i + 1, i + 6);
406
+ swap(this, i + 2, i + 5);
407
+ swap(this, i + 3, i + 4);
408
+ }
409
+ return this;
410
+ };
411
+
412
+ Buffer.prototype.toString = function toString(encoding, start, end) {
413
+ if (arguments.length === 0) {
414
+ return this.utf8Slice(0, this.length);
415
+ }
416
+
417
+ const len = this.length;
418
+
419
+ if (start <= 0) {
420
+ start = 0;
421
+ } else if (start >= len) {
422
+ return "";
423
+ } else {
424
+ start |= 0;
425
+ }
426
+
427
+ if (end === undefined || end > len) {
428
+ end = len;
429
+ } else {
430
+ end |= 0;
431
+ }
432
+
433
+ if (end <= start) {
434
+ return "";
435
+ }
436
+
437
+ if (encoding === undefined) {
438
+ return this.utf8Slice(start, end);
439
+ }
440
+
441
+ const ops = getEncodingOps(encoding);
442
+ if (ops === undefined) {
443
+ throw new codes.ERR_UNKNOWN_ENCODING(encoding);
444
+ }
445
+
446
+ return ops.slice(this, start, end);
447
+ };
448
+
449
+ Buffer.prototype.toLocaleString = Buffer.prototype.toString;
450
+
451
+ Buffer.prototype.equals = function equals(b) {
452
+ if (!isUint8Array(b)) {
453
+ throw new codes.ERR_INVALID_ARG_TYPE(
454
+ "otherBuffer",
455
+ ["Buffer", "Uint8Array"],
456
+ b,
457
+ );
458
+ }
459
+ if (this === b) {
460
+ return true;
461
+ }
462
+ return Buffer.compare(this, b) === 0;
463
+ };
464
+
465
+ Buffer.prototype.inspect = function inspect() {
466
+ let str = "";
467
+ const max = INSPECT_MAX_BYTES;
468
+ str = this.toString("hex", 0, max).replace(/(.{2})/g, "$1 ").trim();
469
+ if (this.length > max) {
470
+ str += " ... ";
471
+ }
472
+ return "<Buffer " + str + ">";
473
+ };
474
+
475
+ if (customInspectSymbol) {
476
+ Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
477
+ }
478
+
479
+ Buffer.prototype.compare = function compare(
480
+ target,
481
+ start,
482
+ end,
483
+ thisStart,
484
+ thisEnd,
485
+ ) {
486
+ if (isInstance(target, Uint8Array)) {
487
+ target = Buffer.from(target, target.offset, target.byteLength);
488
+ }
489
+ if (!Buffer.isBuffer(target)) {
490
+ throw new codes.ERR_INVALID_ARG_TYPE(
491
+ "target",
492
+ ["Buffer", "Uint8Array"],
493
+ target,
494
+ );
495
+ }
496
+
497
+ if (start === undefined) {
498
+ start = 0;
499
+ } else {
500
+ validateOffset(start, "targetStart", 0, kMaxLength);
501
+ }
502
+
503
+ if (end === undefined) {
504
+ end = target.length;
505
+ } else {
506
+ validateOffset(end, "targetEnd", 0, target.length);
507
+ }
508
+
509
+ if (thisStart === undefined) {
510
+ thisStart = 0;
511
+ } else {
512
+ validateOffset(start, "sourceStart", 0, kMaxLength);
513
+ }
514
+
515
+ if (thisEnd === undefined) {
516
+ thisEnd = this.length;
517
+ } else {
518
+ validateOffset(end, "sourceEnd", 0, this.length);
519
+ }
520
+
521
+ if (
522
+ start < 0 || end > target.length || thisStart < 0 ||
523
+ thisEnd > this.length
524
+ ) {
525
+ throw new codes.ERR_OUT_OF_RANGE("out of range index", "range");
526
+ }
527
+
528
+ if (thisStart >= thisEnd && start >= end) {
529
+ return 0;
530
+ }
531
+ if (thisStart >= thisEnd) {
532
+ return -1;
533
+ }
534
+ if (start >= end) {
535
+ return 1;
536
+ }
537
+ start >>>= 0;
538
+ end >>>= 0;
539
+ thisStart >>>= 0;
540
+ thisEnd >>>= 0;
541
+ if (this === target) {
542
+ return 0;
543
+ }
544
+ let x = thisEnd - thisStart;
545
+ let y = end - start;
546
+ const len = Math.min(x, y);
547
+ const thisCopy = this.slice(thisStart, thisEnd);
548
+ const targetCopy = target.slice(start, end);
549
+ for (let i = 0; i < len; ++i) {
550
+ if (thisCopy[i] !== targetCopy[i]) {
551
+ x = thisCopy[i];
552
+ y = targetCopy[i];
553
+ break;
554
+ }
555
+ }
556
+ if (x < y) {
557
+ return -1;
558
+ }
559
+ if (y < x) {
560
+ return 1;
561
+ }
562
+ return 0;
563
+ };
564
+
565
+ function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
566
+ validateBuffer(buffer);
567
+
568
+ if (typeof byteOffset === "string") {
569
+ encoding = byteOffset;
570
+ byteOffset = undefined;
571
+ } else if (byteOffset > 0x7fffffff) {
572
+ byteOffset = 0x7fffffff;
573
+ } else if (byteOffset < -0x80000000) {
574
+ byteOffset = -0x80000000;
575
+ }
576
+ byteOffset = +byteOffset;
577
+ if (Number.isNaN(byteOffset)) {
578
+ byteOffset = dir ? 0 : (buffer.length || buffer.byteLength);
579
+ }
580
+ dir = !!dir;
581
+
582
+ if (typeof val === "number") {
583
+ return indexOfNumber(buffer, val >>> 0, byteOffset, dir);
584
+ }
585
+
586
+ let ops;
587
+ if (encoding === undefined) {
588
+ ops = encodingOps.utf8;
589
+ } else {
590
+ ops = getEncodingOps(encoding);
591
+ }
592
+
593
+ if (typeof val === "string") {
594
+ if (ops === undefined) {
595
+ throw new codes.ERR_UNKNOWN_ENCODING(encoding);
596
+ }
597
+ return ops.indexOf(buffer, val, byteOffset, dir);
598
+ }
599
+
600
+ if (isUint8Array(val)) {
601
+ const encodingVal = ops === undefined ? encodingsMap.utf8 : ops.encodingVal;
602
+ return indexOfBuffer(buffer, val, byteOffset, encodingVal, dir);
603
+ }
604
+
605
+ throw new codes.ERR_INVALID_ARG_TYPE(
606
+ "value",
607
+ ["number", "string", "Buffer", "Uint8Array"],
608
+ val,
609
+ );
610
+ }
611
+
612
+ Buffer.prototype.includes = function includes(val, byteOffset, encoding) {
613
+ return this.indexOf(val, byteOffset, encoding) !== -1;
614
+ };
615
+
616
+ Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
617
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
618
+ };
619
+
620
+ Buffer.prototype.lastIndexOf = function lastIndexOf(
621
+ val,
622
+ byteOffset,
623
+ encoding,
624
+ ) {
625
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
626
+ };
627
+
628
+ Buffer.prototype.asciiSlice = function asciiSlice(offset, length) {
629
+ if (offset === 0 && length === this.length) {
630
+ return bytesToAscii(this);
631
+ } else {
632
+ return bytesToAscii(this.slice(offset, length));
633
+ }
634
+ };
635
+
636
+ Buffer.prototype.asciiWrite = function asciiWrite(string, offset, length) {
637
+ return blitBuffer(asciiToBytes(string), this, offset, length);
638
+ };
639
+
640
+ Buffer.prototype.base64Slice = function base64Slice(
641
+ offset,
642
+ length,
643
+ ) {
644
+ if (offset === 0 && length === this.length) {
645
+ return base64.encode(this);
646
+ } else {
647
+ return base64.encode(this.slice(offset, length));
648
+ }
649
+ };
650
+
651
+ Buffer.prototype.base64Write = function base64Write(
652
+ string,
653
+ offset,
654
+ length,
655
+ ) {
656
+ return blitBuffer(base64ToBytes(string), this, offset, length);
657
+ };
658
+
659
+ Buffer.prototype.base64urlSlice = function base64urlSlice(
660
+ offset,
661
+ length,
662
+ ) {
663
+ if (offset === 0 && length === this.length) {
664
+ return base64url.encode(this);
665
+ } else {
666
+ return base64url.encode(this.slice(offset, length));
667
+ }
668
+ };
669
+
670
+ Buffer.prototype.base64urlWrite = function base64urlWrite(
671
+ string,
672
+ offset,
673
+ length,
674
+ ) {
675
+ return blitBuffer(base64UrlToBytes(string), this, offset, length);
676
+ };
677
+
678
+ Buffer.prototype.hexWrite = function hexWrite(string, offset, length) {
679
+ return blitBuffer(
680
+ hexToBytes(string, this.length - offset),
681
+ this,
682
+ offset,
683
+ length,
684
+ );
685
+ };
686
+
687
+ Buffer.prototype.hexSlice = function hexSlice(string, offset, length) {
688
+ return _hexSlice(this, string, offset, length);
689
+ };
690
+
691
+ Buffer.prototype.latin1Slice = function latin1Slice(
692
+ string,
693
+ offset,
694
+ length,
695
+ ) {
696
+ return _latin1Slice(this, string, offset, length);
697
+ };
698
+
699
+ Buffer.prototype.latin1Write = function latin1Write(
700
+ string,
701
+ offset,
702
+ length,
703
+ ) {
704
+ return blitBuffer(asciiToBytes(string), this, offset, length);
705
+ };
706
+
707
+ Buffer.prototype.ucs2Slice = function ucs2Slice(offset, length) {
708
+ if (offset === 0 && length === this.length) {
709
+ return bytesToUtf16le(this);
710
+ } else {
711
+ return bytesToUtf16le(this.slice(offset, length));
712
+ }
713
+ };
714
+
715
+ Buffer.prototype.ucs2Write = function ucs2Write(string, offset, length) {
716
+ return blitBuffer(
717
+ utf16leToBytes(string, this.length - offset),
718
+ this,
719
+ offset,
720
+ length,
721
+ );
722
+ };
723
+
724
+ Buffer.prototype.utf8Slice = function utf8Slice(string, offset, length) {
725
+ return _utf8Slice(this, string, offset, length);
726
+ };
727
+
728
+ Buffer.prototype.utf8Write = function utf8Write(string, offset, length) {
729
+ return blitBuffer(
730
+ utf8ToBytes(string, this.length - offset),
731
+ this,
732
+ offset,
733
+ length,
734
+ );
735
+ };
736
+
737
+ Buffer.prototype.write = function write(string, offset, length, encoding) {
738
+ // Buffer#write(string);
739
+ if (offset === undefined) {
740
+ return this.utf8Write(string, 0, this.length);
741
+ }
742
+ // Buffer#write(string, encoding)
743
+ if (length === undefined && typeof offset === "string") {
744
+ encoding = offset;
745
+ length = this.length;
746
+ offset = 0;
747
+
748
+ // Buffer#write(string, offset[, length][, encoding])
749
+ } else {
750
+ validateOffset(offset, "offset", 0, this.length);
751
+
752
+ const remaining = this.length - offset;
753
+
754
+ if (length === undefined) {
755
+ length = remaining;
756
+ } else if (typeof length === "string") {
757
+ encoding = length;
758
+ length = remaining;
759
+ } else {
760
+ validateOffset(length, "length", 0, this.length);
761
+ if (length > remaining) {
762
+ length = remaining;
763
+ }
764
+ }
765
+ }
766
+
767
+ if (!encoding) {
768
+ return this.utf8Write(string, offset, length);
769
+ }
770
+
771
+ const ops = getEncodingOps(encoding);
772
+ if (ops === undefined) {
773
+ throw new codes.ERR_UNKNOWN_ENCODING(encoding);
774
+ }
775
+ return ops.write(this, string, offset, length);
776
+ };
777
+
778
+ Buffer.prototype.toJSON = function toJSON() {
779
+ return {
780
+ type: "Buffer",
781
+ data: Array.prototype.slice.call(this._arr || this, 0),
782
+ };
783
+ };
784
+ function fromArrayBuffer(obj, byteOffset, length) {
785
+ // Convert byteOffset to integer
786
+ if (byteOffset === undefined) {
787
+ byteOffset = 0;
788
+ } else {
789
+ byteOffset = +byteOffset;
790
+ if (Number.isNaN(byteOffset)) {
791
+ byteOffset = 0;
792
+ }
793
+ }
794
+
795
+ const maxLength = obj.byteLength - byteOffset;
796
+
797
+ if (maxLength < 0) {
798
+ throw new codes.ERR_BUFFER_OUT_OF_BOUNDS("offset");
799
+ }
800
+
801
+ if (length === undefined) {
802
+ length = maxLength;
803
+ } else {
804
+ // Convert length to non-negative integer.
805
+ length = +length;
806
+ if (length > 0) {
807
+ if (length > maxLength) {
808
+ throw new codes.ERR_BUFFER_OUT_OF_BOUNDS("length");
809
+ }
810
+ } else {
811
+ length = 0;
812
+ }
813
+ }
814
+
815
+ const buffer = new Uint8Array(obj, byteOffset, length);
816
+ Object.setPrototypeOf(buffer, Buffer.prototype);
817
+ return buffer;
818
+ }
819
+
820
+ function _base64Slice(buf, start, end) {
821
+ if (start === 0 && end === buf.length) {
822
+ return base64.encode(buf);
823
+ } else {
824
+ return base64.encode(buf.slice(start, end));
825
+ }
826
+ }
827
+
828
+ const decoder = new TextDecoder();
829
+
830
+ function _utf8Slice(buf, start, end) {
831
+ return decoder.decode(buf.slice(start, end));
832
+ }
833
+
834
+ function _latin1Slice(buf, start, end) {
835
+ let ret = "";
836
+ end = Math.min(buf.length, end);
837
+ for (let i = start; i < end; ++i) {
838
+ ret += String.fromCharCode(buf[i]);
839
+ }
840
+ return ret;
841
+ }
842
+
843
+ function _hexSlice(buf, start, end) {
844
+ const len = buf.length;
845
+ if (!start || start < 0) {
846
+ start = 0;
847
+ }
848
+ if (!end || end < 0 || end > len) {
849
+ end = len;
850
+ }
851
+ let out = "";
852
+ for (let i = start; i < end; ++i) {
853
+ out += hexSliceLookupTable[buf[i]];
854
+ }
855
+ return out;
856
+ }
857
+
858
+ Buffer.prototype.slice = function slice(start, end) {
859
+ const len = this.length;
860
+ start = ~~start;
861
+ end = end === void 0 ? len : ~~end;
862
+ if (start < 0) {
863
+ start += len;
864
+ if (start < 0) {
865
+ start = 0;
866
+ }
867
+ } else if (start > len) {
868
+ start = len;
869
+ }
870
+ if (end < 0) {
871
+ end += len;
872
+ if (end < 0) {
873
+ end = 0;
874
+ }
875
+ } else if (end > len) {
876
+ end = len;
877
+ }
878
+ if (end < start) {
879
+ end = start;
880
+ }
881
+ const newBuf = this.subarray(start, end);
882
+ Object.setPrototypeOf(newBuf, Buffer.prototype);
883
+ return newBuf;
884
+ };
885
+
886
+ Buffer.prototype.readUintLE = Buffer.prototype.readUIntLE = function readUIntLE(
887
+ offset,
888
+ byteLength,
889
+ ) {
890
+ if (offset === undefined) {
891
+ throw new codes.ERR_INVALID_ARG_TYPE("offset", "number", offset);
892
+ }
893
+ if (byteLength === 6) {
894
+ return readUInt48LE(this, offset);
895
+ }
896
+ if (byteLength === 5) {
897
+ return readUInt40LE(this, offset);
898
+ }
899
+ if (byteLength === 3) {
900
+ return readUInt24LE(this, offset);
901
+ }
902
+ if (byteLength === 4) {
903
+ return this.readUInt32LE(offset);
904
+ }
905
+ if (byteLength === 2) {
906
+ return this.readUInt16LE(offset);
907
+ }
908
+ if (byteLength === 1) {
909
+ return this.readUInt8(offset);
910
+ }
911
+
912
+ boundsError(byteLength, 6, "byteLength");
913
+ };
914
+
915
+ Buffer.prototype.readUintBE = Buffer.prototype.readUIntBE = function readUIntBE(
916
+ offset,
917
+ byteLength,
918
+ ) {
919
+ if (offset === undefined) {
920
+ throw new codes.ERR_INVALID_ARG_TYPE("offset", "number", offset);
921
+ }
922
+ if (byteLength === 6) {
923
+ return readUInt48BE(this, offset);
924
+ }
925
+ if (byteLength === 5) {
926
+ return readUInt40BE(this, offset);
927
+ }
928
+ if (byteLength === 3) {
929
+ return readUInt24BE(this, offset);
930
+ }
931
+ if (byteLength === 4) {
932
+ return this.readUInt32BE(offset);
933
+ }
934
+ if (byteLength === 2) {
935
+ return this.readUInt16BE(offset);
936
+ }
937
+ if (byteLength === 1) {
938
+ return this.readUInt8(offset);
939
+ }
940
+
941
+ boundsError(byteLength, 6, "byteLength");
942
+ };
943
+
944
+ Buffer.prototype.readUint8 = Buffer.prototype.readUInt8 = function readUInt8(
945
+ offset = 0,
946
+ ) {
947
+ validateNumber(offset, "offset");
948
+ const val = this[offset];
949
+ if (val === undefined) {
950
+ boundsError(offset, this.length - 1);
951
+ }
952
+
953
+ return val;
954
+ };
955
+
956
+ Buffer.prototype.readUint16BE = Buffer.prototype.readUInt16BE = readUInt16BE;
957
+
958
+ Buffer.prototype.readUint16LE =
959
+ Buffer.prototype.readUInt16LE =
960
+ function readUInt16LE(offset = 0) {
961
+ validateNumber(offset, "offset");
962
+ const first = this[offset];
963
+ const last = this[offset + 1];
964
+ if (first === undefined || last === undefined) {
965
+ boundsError(offset, this.length - 2);
966
+ }
967
+
968
+ return first + last * 2 ** 8;
969
+ };
970
+
971
+ Buffer.prototype.readUint32LE =
972
+ Buffer.prototype.readUInt32LE =
973
+ function readUInt32LE(offset = 0) {
974
+ validateNumber(offset, "offset");
975
+ const first = this[offset];
976
+ const last = this[offset + 3];
977
+ if (first === undefined || last === undefined) {
978
+ boundsError(offset, this.length - 4);
979
+ }
980
+
981
+ return first +
982
+ this[++offset] * 2 ** 8 +
983
+ this[++offset] * 2 ** 16 +
984
+ last * 2 ** 24;
985
+ };
986
+
987
+ Buffer.prototype.readUint32BE = Buffer.prototype.readUInt32BE = readUInt32BE;
988
+
989
+ Buffer.prototype.readBigUint64LE =
990
+ Buffer.prototype.readBigUInt64LE =
991
+ defineBigIntMethod(
992
+ function readBigUInt64LE(offset) {
993
+ offset = offset >>> 0;
994
+ validateNumber(offset, "offset");
995
+ const first = this[offset];
996
+ const last = this[offset + 7];
997
+ if (first === void 0 || last === void 0) {
998
+ boundsError(offset, this.length - 8);
999
+ }
1000
+ const lo = first + this[++offset] * 2 ** 8 +
1001
+ this[++offset] * 2 ** 16 +
1002
+ this[++offset] * 2 ** 24;
1003
+ const hi = this[++offset] + this[++offset] * 2 ** 8 +
1004
+ this[++offset] * 2 ** 16 + last * 2 ** 24;
1005
+ return BigInt(lo) + (BigInt(hi) << BigInt(32));
1006
+ },
1007
+ );
1008
+
1009
+ Buffer.prototype.readBigUint64BE =
1010
+ Buffer.prototype.readBigUInt64BE =
1011
+ defineBigIntMethod(
1012
+ function readBigUInt64BE(offset) {
1013
+ offset = offset >>> 0;
1014
+ validateNumber(offset, "offset");
1015
+ const first = this[offset];
1016
+ const last = this[offset + 7];
1017
+ if (first === void 0 || last === void 0) {
1018
+ boundsError(offset, this.length - 8);
1019
+ }
1020
+ const hi = first * 2 ** 24 + this[++offset] * 2 ** 16 +
1021
+ this[++offset] * 2 ** 8 + this[++offset];
1022
+ const lo = this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 +
1023
+ this[++offset] * 2 ** 8 + last;
1024
+ return (BigInt(hi) << BigInt(32)) + BigInt(lo);
1025
+ },
1026
+ );
1027
+
1028
+ Buffer.prototype.readIntLE = function readIntLE(
1029
+ offset,
1030
+ byteLength,
1031
+ ) {
1032
+ if (offset === undefined) {
1033
+ throw new codes.ERR_INVALID_ARG_TYPE("offset", "number", offset);
1034
+ }
1035
+ if (byteLength === 6) {
1036
+ return readInt48LE(this, offset);
1037
+ }
1038
+ if (byteLength === 5) {
1039
+ return readInt40LE(this, offset);
1040
+ }
1041
+ if (byteLength === 3) {
1042
+ return readInt24LE(this, offset);
1043
+ }
1044
+ if (byteLength === 4) {
1045
+ return this.readInt32LE(offset);
1046
+ }
1047
+ if (byteLength === 2) {
1048
+ return this.readInt16LE(offset);
1049
+ }
1050
+ if (byteLength === 1) {
1051
+ return this.readInt8(offset);
1052
+ }
1053
+
1054
+ boundsError(byteLength, 6, "byteLength");
1055
+ };
1056
+
1057
+ Buffer.prototype.readIntBE = function readIntBE(offset, byteLength) {
1058
+ if (offset === undefined) {
1059
+ throw new codes.ERR_INVALID_ARG_TYPE("offset", "number", offset);
1060
+ }
1061
+ if (byteLength === 6) {
1062
+ return readInt48BE(this, offset);
1063
+ }
1064
+ if (byteLength === 5) {
1065
+ return readInt40BE(this, offset);
1066
+ }
1067
+ if (byteLength === 3) {
1068
+ return readInt24BE(this, offset);
1069
+ }
1070
+ if (byteLength === 4) {
1071
+ return this.readInt32BE(offset);
1072
+ }
1073
+ if (byteLength === 2) {
1074
+ return this.readInt16BE(offset);
1075
+ }
1076
+ if (byteLength === 1) {
1077
+ return this.readInt8(offset);
1078
+ }
1079
+
1080
+ boundsError(byteLength, 6, "byteLength");
1081
+ };
1082
+
1083
+ Buffer.prototype.readInt8 = function readInt8(offset = 0) {
1084
+ validateNumber(offset, "offset");
1085
+ const val = this[offset];
1086
+ if (val === undefined) {
1087
+ boundsError(offset, this.length - 1);
1088
+ }
1089
+
1090
+ return val | (val & 2 ** 7) * 0x1fffffe;
1091
+ };
1092
+
1093
+ Buffer.prototype.readInt16LE = function readInt16LE(offset = 0) {
1094
+ validateNumber(offset, "offset");
1095
+ const first = this[offset];
1096
+ const last = this[offset + 1];
1097
+ if (first === undefined || last === undefined) {
1098
+ boundsError(offset, this.length - 2);
1099
+ }
1100
+
1101
+ const val = first + last * 2 ** 8;
1102
+ return val | (val & 2 ** 15) * 0x1fffe;
1103
+ };
1104
+
1105
+ Buffer.prototype.readInt16BE = function readInt16BE(offset = 0) {
1106
+ validateNumber(offset, "offset");
1107
+ const first = this[offset];
1108
+ const last = this[offset + 1];
1109
+ if (first === undefined || last === undefined) {
1110
+ boundsError(offset, this.length - 2);
1111
+ }
1112
+
1113
+ const val = first * 2 ** 8 + last;
1114
+ return val | (val & 2 ** 15) * 0x1fffe;
1115
+ };
1116
+
1117
+ Buffer.prototype.readInt32LE = function readInt32LE(offset = 0) {
1118
+ validateNumber(offset, "offset");
1119
+ const first = this[offset];
1120
+ const last = this[offset + 3];
1121
+ if (first === undefined || last === undefined) {
1122
+ boundsError(offset, this.length - 4);
1123
+ }
1124
+
1125
+ return first +
1126
+ this[++offset] * 2 ** 8 +
1127
+ this[++offset] * 2 ** 16 +
1128
+ (last << 24); // Overflow
1129
+ };
1130
+
1131
+ Buffer.prototype.readInt32BE = function readInt32BE(offset = 0) {
1132
+ validateNumber(offset, "offset");
1133
+ const first = this[offset];
1134
+ const last = this[offset + 3];
1135
+ if (first === undefined || last === undefined) {
1136
+ boundsError(offset, this.length - 4);
1137
+ }
1138
+
1139
+ return (first << 24) + // Overflow
1140
+ this[++offset] * 2 ** 16 +
1141
+ this[++offset] * 2 ** 8 +
1142
+ last;
1143
+ };
1144
+
1145
+ Buffer.prototype.readBigInt64LE = defineBigIntMethod(
1146
+ function readBigInt64LE(offset) {
1147
+ offset = offset >>> 0;
1148
+ validateNumber(offset, "offset");
1149
+ const first = this[offset];
1150
+ const last = this[offset + 7];
1151
+ if (first === void 0 || last === void 0) {
1152
+ boundsError(offset, this.length - 8);
1153
+ }
1154
+ const val = this[offset + 4] + this[offset + 5] * 2 ** 8 +
1155
+ this[offset + 6] * 2 ** 16 + (last << 24);
1156
+ return (BigInt(val) << BigInt(32)) +
1157
+ BigInt(
1158
+ first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 +
1159
+ this[++offset] * 2 ** 24,
1160
+ );
1161
+ },
1162
+ );
1163
+
1164
+ Buffer.prototype.readBigInt64BE = defineBigIntMethod(
1165
+ function readBigInt64BE(offset) {
1166
+ offset = offset >>> 0;
1167
+ validateNumber(offset, "offset");
1168
+ const first = this[offset];
1169
+ const last = this[offset + 7];
1170
+ if (first === void 0 || last === void 0) {
1171
+ boundsError(offset, this.length - 8);
1172
+ }
1173
+ const val = (first << 24) + this[++offset] * 2 ** 16 +
1174
+ this[++offset] * 2 ** 8 + this[++offset];
1175
+ return (BigInt(val) << BigInt(32)) +
1176
+ BigInt(
1177
+ this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 +
1178
+ this[++offset] * 2 ** 8 + last,
1179
+ );
1180
+ },
1181
+ );
1182
+
1183
+ Buffer.prototype.readFloatLE = function readFloatLE(offset) {
1184
+ return bigEndian
1185
+ ? readFloatBackwards(this, offset)
1186
+ : readFloatForwards(this, offset);
1187
+ };
1188
+
1189
+ Buffer.prototype.readFloatBE = function readFloatBE(offset) {
1190
+ return bigEndian
1191
+ ? readFloatForwards(this, offset)
1192
+ : readFloatBackwards(this, offset);
1193
+ };
1194
+
1195
+ Buffer.prototype.readDoubleLE = function readDoubleLE(offset) {
1196
+ return bigEndian
1197
+ ? readDoubleBackwards(this, offset)
1198
+ : readDoubleForwards(this, offset);
1199
+ };
1200
+
1201
+ Buffer.prototype.readDoubleBE = function readDoubleBE(offset) {
1202
+ return bigEndian
1203
+ ? readDoubleForwards(this, offset)
1204
+ : readDoubleBackwards(this, offset);
1205
+ };
1206
+
1207
+ Buffer.prototype.writeUintLE =
1208
+ Buffer.prototype.writeUIntLE =
1209
+ function writeUIntLE(value, offset, byteLength) {
1210
+ if (byteLength === 6) {
1211
+ return writeU_Int48LE(this, value, offset, 0, 0xffffffffffff);
1212
+ }
1213
+ if (byteLength === 5) {
1214
+ return writeU_Int40LE(this, value, offset, 0, 0xffffffffff);
1215
+ }
1216
+ if (byteLength === 3) {
1217
+ return writeU_Int24LE(this, value, offset, 0, 0xffffff);
1218
+ }
1219
+ if (byteLength === 4) {
1220
+ return writeU_Int32LE(this, value, offset, 0, 0xffffffff);
1221
+ }
1222
+ if (byteLength === 2) {
1223
+ return writeU_Int16LE(this, value, offset, 0, 0xffff);
1224
+ }
1225
+ if (byteLength === 1) {
1226
+ return writeU_Int8(this, value, offset, 0, 0xff);
1227
+ }
1228
+
1229
+ boundsError(byteLength, 6, "byteLength");
1230
+ };
1231
+
1232
+ Buffer.prototype.writeUintBE =
1233
+ Buffer.prototype.writeUIntBE =
1234
+ function writeUIntBE(value, offset, byteLength) {
1235
+ if (byteLength === 6) {
1236
+ return writeU_Int48BE(this, value, offset, 0, 0xffffffffffff);
1237
+ }
1238
+ if (byteLength === 5) {
1239
+ return writeU_Int40BE(this, value, offset, 0, 0xffffffffff);
1240
+ }
1241
+ if (byteLength === 3) {
1242
+ return writeU_Int24BE(this, value, offset, 0, 0xffffff);
1243
+ }
1244
+ if (byteLength === 4) {
1245
+ return writeU_Int32BE(this, value, offset, 0, 0xffffffff);
1246
+ }
1247
+ if (byteLength === 2) {
1248
+ return writeU_Int16BE(this, value, offset, 0, 0xffff);
1249
+ }
1250
+ if (byteLength === 1) {
1251
+ return writeU_Int8(this, value, offset, 0, 0xff);
1252
+ }
1253
+
1254
+ boundsError(byteLength, 6, "byteLength");
1255
+ };
1256
+
1257
+ Buffer.prototype.writeUint8 = Buffer.prototype.writeUInt8 = function writeUInt8(
1258
+ value,
1259
+ offset = 0,
1260
+ ) {
1261
+ return writeU_Int8(this, value, offset, 0, 0xff);
1262
+ };
1263
+
1264
+ Buffer.prototype.writeUint16LE =
1265
+ Buffer.prototype.writeUInt16LE =
1266
+ function writeUInt16LE(value, offset = 0) {
1267
+ return writeU_Int16LE(this, value, offset, 0, 0xffff);
1268
+ };
1269
+
1270
+ Buffer.prototype.writeUint16BE =
1271
+ Buffer.prototype.writeUInt16BE =
1272
+ function writeUInt16BE(value, offset = 0) {
1273
+ return writeU_Int16BE(this, value, offset, 0, 0xffff);
1274
+ };
1275
+
1276
+ Buffer.prototype.writeUint32LE =
1277
+ Buffer.prototype.writeUInt32LE =
1278
+ function writeUInt32LE(value, offset = 0) {
1279
+ return _writeUInt32LE(this, value, offset, 0, 0xffffffff);
1280
+ };
1281
+
1282
+ Buffer.prototype.writeUint32BE =
1283
+ Buffer.prototype.writeUInt32BE =
1284
+ function writeUInt32BE(value, offset = 0) {
1285
+ return _writeUInt32BE(this, value, offset, 0, 0xffffffff);
1286
+ };
1287
+
1288
+ function wrtBigUInt64LE(buf, value, offset, min, max) {
1289
+ checkIntBI(value, min, max, buf, offset, 7);
1290
+ let lo = Number(value & BigInt(4294967295));
1291
+ buf[offset++] = lo;
1292
+ lo = lo >> 8;
1293
+ buf[offset++] = lo;
1294
+ lo = lo >> 8;
1295
+ buf[offset++] = lo;
1296
+ lo = lo >> 8;
1297
+ buf[offset++] = lo;
1298
+ let hi = Number(value >> BigInt(32) & BigInt(4294967295));
1299
+ buf[offset++] = hi;
1300
+ hi = hi >> 8;
1301
+ buf[offset++] = hi;
1302
+ hi = hi >> 8;
1303
+ buf[offset++] = hi;
1304
+ hi = hi >> 8;
1305
+ buf[offset++] = hi;
1306
+ return offset;
1307
+ }
1308
+
1309
+ function wrtBigUInt64BE(buf, value, offset, min, max) {
1310
+ checkIntBI(value, min, max, buf, offset, 7);
1311
+ let lo = Number(value & BigInt(4294967295));
1312
+ buf[offset + 7] = lo;
1313
+ lo = lo >> 8;
1314
+ buf[offset + 6] = lo;
1315
+ lo = lo >> 8;
1316
+ buf[offset + 5] = lo;
1317
+ lo = lo >> 8;
1318
+ buf[offset + 4] = lo;
1319
+ let hi = Number(value >> BigInt(32) & BigInt(4294967295));
1320
+ buf[offset + 3] = hi;
1321
+ hi = hi >> 8;
1322
+ buf[offset + 2] = hi;
1323
+ hi = hi >> 8;
1324
+ buf[offset + 1] = hi;
1325
+ hi = hi >> 8;
1326
+ buf[offset] = hi;
1327
+ return offset + 8;
1328
+ }
1329
+
1330
+ Buffer.prototype.writeBigUint64LE =
1331
+ Buffer.prototype.writeBigUInt64LE =
1332
+ defineBigIntMethod(
1333
+ function writeBigUInt64LE(value, offset = 0) {
1334
+ return wrtBigUInt64LE(
1335
+ this,
1336
+ value,
1337
+ offset,
1338
+ BigInt(0),
1339
+ BigInt("0xffffffffffffffff"),
1340
+ );
1341
+ },
1342
+ );
1343
+
1344
+ Buffer.prototype.writeBigUint64BE =
1345
+ Buffer.prototype.writeBigUInt64BE =
1346
+ defineBigIntMethod(
1347
+ function writeBigUInt64BE(value, offset = 0) {
1348
+ return wrtBigUInt64BE(
1349
+ this,
1350
+ value,
1351
+ offset,
1352
+ BigInt(0),
1353
+ BigInt("0xffffffffffffffff"),
1354
+ );
1355
+ },
1356
+ );
1357
+
1358
+ Buffer.prototype.writeIntLE = function writeIntLE(
1359
+ value,
1360
+ offset,
1361
+ byteLength,
1362
+ ) {
1363
+ if (byteLength === 6) {
1364
+ return writeU_Int48LE(
1365
+ this,
1366
+ value,
1367
+ offset,
1368
+ -0x800000000000,
1369
+ 0x7fffffffffff,
1370
+ );
1371
+ }
1372
+ if (byteLength === 5) {
1373
+ return writeU_Int40LE(this, value, offset, -0x8000000000, 0x7fffffffff);
1374
+ }
1375
+ if (byteLength === 3) {
1376
+ return writeU_Int24LE(this, value, offset, -0x800000, 0x7fffff);
1377
+ }
1378
+ if (byteLength === 4) {
1379
+ return writeU_Int32LE(this, value, offset, -0x80000000, 0x7fffffff);
1380
+ }
1381
+ if (byteLength === 2) {
1382
+ return writeU_Int16LE(this, value, offset, -0x8000, 0x7fff);
1383
+ }
1384
+ if (byteLength === 1) {
1385
+ return writeU_Int8(this, value, offset, -0x80, 0x7f);
1386
+ }
1387
+
1388
+ boundsError(byteLength, 6, "byteLength");
1389
+ };
1390
+
1391
+ Buffer.prototype.writeIntBE = function writeIntBE(
1392
+ value,
1393
+ offset,
1394
+ byteLength,
1395
+ ) {
1396
+ if (byteLength === 6) {
1397
+ return writeU_Int48BE(
1398
+ this,
1399
+ value,
1400
+ offset,
1401
+ -0x800000000000,
1402
+ 0x7fffffffffff,
1403
+ );
1404
+ }
1405
+ if (byteLength === 5) {
1406
+ return writeU_Int40BE(this, value, offset, -0x8000000000, 0x7fffffffff);
1407
+ }
1408
+ if (byteLength === 3) {
1409
+ return writeU_Int24BE(this, value, offset, -0x800000, 0x7fffff);
1410
+ }
1411
+ if (byteLength === 4) {
1412
+ return writeU_Int32BE(this, value, offset, -0x80000000, 0x7fffffff);
1413
+ }
1414
+ if (byteLength === 2) {
1415
+ return writeU_Int16BE(this, value, offset, -0x8000, 0x7fff);
1416
+ }
1417
+ if (byteLength === 1) {
1418
+ return writeU_Int8(this, value, offset, -0x80, 0x7f);
1419
+ }
1420
+
1421
+ boundsError(byteLength, 6, "byteLength");
1422
+ };
1423
+
1424
+ Buffer.prototype.writeInt8 = function writeInt8(value, offset = 0) {
1425
+ return writeU_Int8(this, value, offset, -0x80, 0x7f);
1426
+ };
1427
+
1428
+ Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset = 0) {
1429
+ return writeU_Int16LE(this, value, offset, -0x8000, 0x7fff);
1430
+ };
1431
+
1432
+ Buffer.prototype.writeInt16BE = function writeInt16BE(
1433
+ value,
1434
+ offset = 0,
1435
+ ) {
1436
+ return writeU_Int16BE(this, value, offset, -0x8000, 0x7fff);
1437
+ };
1438
+
1439
+ Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset = 0) {
1440
+ return writeU_Int32LE(this, value, offset, -0x80000000, 0x7fffffff);
1441
+ };
1442
+
1443
+ Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset = 0) {
1444
+ return writeU_Int32BE(this, value, offset, -0x80000000, 0x7fffffff);
1445
+ };
1446
+
1447
+ Buffer.prototype.writeBigInt64LE = defineBigIntMethod(
1448
+ function writeBigInt64LE(value, offset = 0) {
1449
+ return wrtBigUInt64LE(
1450
+ this,
1451
+ value,
1452
+ offset,
1453
+ -BigInt("0x8000000000000000"),
1454
+ BigInt("0x7fffffffffffffff"),
1455
+ );
1456
+ },
1457
+ );
1458
+
1459
+ Buffer.prototype.writeBigInt64BE = defineBigIntMethod(
1460
+ function writeBigInt64BE(value, offset = 0) {
1461
+ return wrtBigUInt64BE(
1462
+ this,
1463
+ value,
1464
+ offset,
1465
+ -BigInt("0x8000000000000000"),
1466
+ BigInt("0x7fffffffffffffff"),
1467
+ );
1468
+ },
1469
+ );
1470
+
1471
+ Buffer.prototype.writeFloatLE = function writeFloatLE(
1472
+ value,
1473
+ offset,
1474
+ ) {
1475
+ return bigEndian
1476
+ ? writeFloatBackwards(this, value, offset)
1477
+ : writeFloatForwards(this, value, offset);
1478
+ };
1479
+
1480
+ Buffer.prototype.writeFloatBE = function writeFloatBE(
1481
+ value,
1482
+ offset,
1483
+ ) {
1484
+ return bigEndian
1485
+ ? writeFloatForwards(this, value, offset)
1486
+ : writeFloatBackwards(this, value, offset);
1487
+ };
1488
+
1489
+ Buffer.prototype.writeDoubleLE = function writeDoubleLE(
1490
+ value,
1491
+ offset,
1492
+ ) {
1493
+ return bigEndian
1494
+ ? writeDoubleBackwards(this, value, offset)
1495
+ : writeDoubleForwards(this, value, offset);
1496
+ };
1497
+
1498
+ Buffer.prototype.writeDoubleBE = function writeDoubleBE(
1499
+ value,
1500
+ offset,
1501
+ ) {
1502
+ return bigEndian
1503
+ ? writeDoubleForwards(this, value, offset)
1504
+ : writeDoubleBackwards(this, value, offset);
1505
+ };
1506
+
1507
+ Buffer.prototype.copy = function copy(
1508
+ target,
1509
+ targetStart,
1510
+ sourceStart,
1511
+ sourceEnd,
1512
+ ) {
1513
+ if (!isUint8Array(this)) {
1514
+ throw new codes.ERR_INVALID_ARG_TYPE(
1515
+ "source",
1516
+ ["Buffer", "Uint8Array"],
1517
+ this,
1518
+ );
1519
+ }
1520
+
1521
+ if (!isUint8Array(target)) {
1522
+ throw new codes.ERR_INVALID_ARG_TYPE(
1523
+ "target",
1524
+ ["Buffer", "Uint8Array"],
1525
+ target,
1526
+ );
1527
+ }
1528
+
1529
+ if (targetStart === undefined) {
1530
+ targetStart = 0;
1531
+ } else {
1532
+ targetStart = toInteger(targetStart, 0);
1533
+ if (targetStart < 0) {
1534
+ throw new codes.ERR_OUT_OF_RANGE("targetStart", ">= 0", targetStart);
1535
+ }
1536
+ }
1537
+
1538
+ if (sourceStart === undefined) {
1539
+ sourceStart = 0;
1540
+ } else {
1541
+ sourceStart = toInteger(sourceStart, 0);
1542
+ if (sourceStart < 0) {
1543
+ throw new codes.ERR_OUT_OF_RANGE("sourceStart", ">= 0", sourceStart);
1544
+ }
1545
+ if (sourceStart >= MAX_UINT32) {
1546
+ throw new codes.ERR_OUT_OF_RANGE(
1547
+ "sourceStart",
1548
+ `< ${MAX_UINT32}`,
1549
+ sourceStart,
1550
+ );
1551
+ }
1552
+ }
1553
+
1554
+ if (sourceEnd === undefined) {
1555
+ sourceEnd = this.length;
1556
+ } else {
1557
+ sourceEnd = toInteger(sourceEnd, 0);
1558
+ if (sourceEnd < 0) {
1559
+ throw new codes.ERR_OUT_OF_RANGE("sourceEnd", ">= 0", sourceEnd);
1560
+ }
1561
+ if (sourceEnd >= MAX_UINT32) {
1562
+ throw new codes.ERR_OUT_OF_RANGE(
1563
+ "sourceEnd",
1564
+ `< ${MAX_UINT32}`,
1565
+ sourceEnd,
1566
+ );
1567
+ }
1568
+ }
1569
+
1570
+ if (targetStart >= target.length) {
1571
+ return 0;
1572
+ }
1573
+
1574
+ if (sourceEnd > 0 && sourceEnd < sourceStart) {
1575
+ sourceEnd = sourceStart;
1576
+ }
1577
+ if (sourceEnd === sourceStart) {
1578
+ return 0;
1579
+ }
1580
+ if (target.length === 0 || this.length === 0) {
1581
+ return 0;
1582
+ }
1583
+
1584
+ if (sourceEnd > this.length) {
1585
+ sourceEnd = this.length;
1586
+ }
1587
+
1588
+ if (target.length - targetStart < sourceEnd - sourceStart) {
1589
+ sourceEnd = target.length - targetStart + sourceStart;
1590
+ }
1591
+
1592
+ const len = sourceEnd - sourceStart;
1593
+ if (
1594
+ this === target && typeof Uint8Array.prototype.copyWithin === "function"
1595
+ ) {
1596
+ this.copyWithin(targetStart, sourceStart, sourceEnd);
1597
+ } else {
1598
+ Uint8Array.prototype.set.call(
1599
+ target,
1600
+ this.subarray(sourceStart, sourceEnd),
1601
+ targetStart,
1602
+ );
1603
+ }
1604
+ return len;
1605
+ };
1606
+
1607
+ Buffer.prototype.fill = function fill(val, start, end, encoding) {
1608
+ if (typeof val === "string") {
1609
+ if (typeof start === "string") {
1610
+ encoding = start;
1611
+ start = 0;
1612
+ end = this.length;
1613
+ } else if (typeof end === "string") {
1614
+ encoding = end;
1615
+ end = this.length;
1616
+ }
1617
+ if (encoding !== void 0 && typeof encoding !== "string") {
1618
+ throw new TypeError("encoding must be a string");
1619
+ }
1620
+ if (typeof encoding === "string" && !Buffer.isEncoding(encoding)) {
1621
+ throw new TypeError("Unknown encoding: " + encoding);
1622
+ }
1623
+ if (val.length === 1) {
1624
+ const code = val.charCodeAt(0);
1625
+ if (encoding === "utf8" && code < 128 || encoding === "latin1") {
1626
+ val = code;
1627
+ }
1628
+ }
1629
+ } else if (typeof val === "number") {
1630
+ val = val & 255;
1631
+ } else if (typeof val === "boolean") {
1632
+ val = Number(val);
1633
+ }
1634
+ if (start < 0 || this.length < start || this.length < end) {
1635
+ throw new RangeError("Out of range index");
1636
+ }
1637
+ if (end <= start) {
1638
+ return this;
1639
+ }
1640
+ start = start >>> 0;
1641
+ end = end === void 0 ? this.length : end >>> 0;
1642
+ if (!val) {
1643
+ val = 0;
1644
+ }
1645
+ let i;
1646
+ if (typeof val === "number") {
1647
+ for (i = start; i < end; ++i) {
1648
+ this[i] = val;
1649
+ }
1650
+ } else {
1651
+ const bytes = Buffer.isBuffer(val) ? val : Buffer.from(val, encoding);
1652
+ const len = bytes.length;
1653
+ if (len === 0) {
1654
+ throw new codes.ERR_INVALID_ARG_VALUE(
1655
+ "value",
1656
+ val,
1657
+ );
1658
+ }
1659
+ for (i = 0; i < end - start; ++i) {
1660
+ this[i + start] = bytes[i % len];
1661
+ }
1662
+ }
1663
+ return this;
1664
+ };
1665
+
1666
+ function checkBounds(buf, offset, byteLength2) {
1667
+ validateNumber(offset, "offset");
1668
+ if (buf[offset] === void 0 || buf[offset + byteLength2] === void 0) {
1669
+ boundsError(offset, buf.length - (byteLength2 + 1));
1670
+ }
1671
+ }
1672
+
1673
+ function checkIntBI(value, min, max, buf, offset, byteLength2) {
1674
+ if (value > max || value < min) {
1675
+ const n = typeof min === "bigint" ? "n" : "";
1676
+ let range;
1677
+ if (byteLength2 > 3) {
1678
+ if (min === 0 || min === BigInt(0)) {
1679
+ range = `>= 0${n} and < 2${n} ** ${(byteLength2 + 1) * 8}${n}`;
1680
+ } else {
1681
+ range = `>= -(2${n} ** ${(byteLength2 + 1) * 8 - 1}${n}) and < 2 ** ${
1682
+ (byteLength2 + 1) * 8 - 1
1683
+ }${n}`;
1684
+ }
1685
+ } else {
1686
+ range = `>= ${min}${n} and <= ${max}${n}`;
1687
+ }
1688
+ throw new codes.ERR_OUT_OF_RANGE("value", range, value);
1689
+ }
1690
+ checkBounds(buf, offset, byteLength2);
1691
+ }
1692
+
1693
+ function utf8ToBytes(string, units) {
1694
+ units = units || Infinity;
1695
+ let codePoint;
1696
+ const length = string.length;
1697
+ let leadSurrogate = null;
1698
+ const bytes = [];
1699
+ for (let i = 0; i < length; ++i) {
1700
+ codePoint = string.charCodeAt(i);
1701
+ if (codePoint > 55295 && codePoint < 57344) {
1702
+ if (!leadSurrogate) {
1703
+ if (codePoint > 56319) {
1704
+ if ((units -= 3) > -1) {
1705
+ bytes.push(239, 191, 189);
1706
+ }
1707
+ continue;
1708
+ } else if (i + 1 === length) {
1709
+ if ((units -= 3) > -1) {
1710
+ bytes.push(239, 191, 189);
1711
+ }
1712
+ continue;
1713
+ }
1714
+ leadSurrogate = codePoint;
1715
+ continue;
1716
+ }
1717
+ if (codePoint < 56320) {
1718
+ if ((units -= 3) > -1) {
1719
+ bytes.push(239, 191, 189);
1720
+ }
1721
+ leadSurrogate = codePoint;
1722
+ continue;
1723
+ }
1724
+ codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536;
1725
+ } else if (leadSurrogate) {
1726
+ if ((units -= 3) > -1) {
1727
+ bytes.push(239, 191, 189);
1728
+ }
1729
+ }
1730
+ leadSurrogate = null;
1731
+ if (codePoint < 128) {
1732
+ if ((units -= 1) < 0) {
1733
+ break;
1734
+ }
1735
+ bytes.push(codePoint);
1736
+ } else if (codePoint < 2048) {
1737
+ if ((units -= 2) < 0) {
1738
+ break;
1739
+ }
1740
+ bytes.push(codePoint >> 6 | 192, codePoint & 63 | 128);
1741
+ } else if (codePoint < 65536) {
1742
+ if ((units -= 3) < 0) {
1743
+ break;
1744
+ }
1745
+ bytes.push(
1746
+ codePoint >> 12 | 224,
1747
+ codePoint >> 6 & 63 | 128,
1748
+ codePoint & 63 | 128,
1749
+ );
1750
+ } else if (codePoint < 1114112) {
1751
+ if ((units -= 4) < 0) {
1752
+ break;
1753
+ }
1754
+ bytes.push(
1755
+ codePoint >> 18 | 240,
1756
+ codePoint >> 12 & 63 | 128,
1757
+ codePoint >> 6 & 63 | 128,
1758
+ codePoint & 63 | 128,
1759
+ );
1760
+ } else {
1761
+ throw new Error("Invalid code point");
1762
+ }
1763
+ }
1764
+ return bytes;
1765
+ }
1766
+
1767
+ function blitBuffer(src, dst, offset, byteLength) {
1768
+ let i;
1769
+ const length = byteLength === undefined ? src.length : byteLength;
1770
+ for (i = 0; i < length; ++i) {
1771
+ if (i + offset >= dst.length || i >= src.length) {
1772
+ break;
1773
+ }
1774
+ dst[i + offset] = src[i];
1775
+ }
1776
+ return i;
1777
+ }
1778
+
1779
+ function isInstance(obj, type) {
1780
+ return obj instanceof type ||
1781
+ obj != null && obj.constructor != null &&
1782
+ obj.constructor.name != null && obj.constructor.name === type.name;
1783
+ }
1784
+
1785
+ const hexSliceLookupTable = function () {
1786
+ const alphabet = "0123456789abcdef";
1787
+ const table = new Array(256);
1788
+ for (let i = 0; i < 16; ++i) {
1789
+ const i16 = i * 16;
1790
+ for (let j = 0; j < 16; ++j) {
1791
+ table[i16 + j] = alphabet[i] + alphabet[j];
1792
+ }
1793
+ }
1794
+ return table;
1795
+ }();
1796
+
1797
+ function defineBigIntMethod(fn) {
1798
+ return typeof BigInt === "undefined" ? BufferBigIntNotDefined : fn;
1799
+ }
1800
+
1801
+ function BufferBigIntNotDefined() {
1802
+ throw new Error("BigInt not supported");
1803
+ }
1804
+
1805
+ export const atob = globalThis.atob;
1806
+ export const Blob = globalThis.Blob;
1807
+ export const btoa = globalThis.btoa;
1808
+
1809
+ export function readUInt48LE(buf, offset = 0) {
1810
+ validateNumber(offset, "offset");
1811
+ const first = buf[offset];
1812
+ const last = buf[offset + 5];
1813
+ if (first === undefined || last === undefined) {
1814
+ boundsError(offset, buf.length - 6);
1815
+ }
1816
+
1817
+ return first +
1818
+ buf[++offset] * 2 ** 8 +
1819
+ buf[++offset] * 2 ** 16 +
1820
+ buf[++offset] * 2 ** 24 +
1821
+ (buf[++offset] + last * 2 ** 8) * 2 ** 32;
1822
+ }
1823
+
1824
+ export function readUInt40LE(buf, offset = 0) {
1825
+ validateNumber(offset, "offset");
1826
+ const first = buf[offset];
1827
+ const last = buf[offset + 4];
1828
+ if (first === undefined || last === undefined) {
1829
+ boundsError(offset, buf.length - 5);
1830
+ }
1831
+
1832
+ return first +
1833
+ buf[++offset] * 2 ** 8 +
1834
+ buf[++offset] * 2 ** 16 +
1835
+ buf[++offset] * 2 ** 24 +
1836
+ last * 2 ** 32;
1837
+ }
1838
+
1839
+ export function readUInt24LE(buf, offset = 0) {
1840
+ validateNumber(offset, "offset");
1841
+ const first = buf[offset];
1842
+ const last = buf[offset + 2];
1843
+ if (first === undefined || last === undefined) {
1844
+ boundsError(offset, buf.length - 3);
1845
+ }
1846
+
1847
+ return first + buf[++offset] * 2 ** 8 + last * 2 ** 16;
1848
+ }
1849
+
1850
+ export function readUInt48BE(buf, offset = 0) {
1851
+ validateNumber(offset, "offset");
1852
+ const first = buf[offset];
1853
+ const last = buf[offset + 5];
1854
+ if (first === undefined || last === undefined) {
1855
+ boundsError(offset, buf.length - 6);
1856
+ }
1857
+
1858
+ return (first * 2 ** 8 + buf[++offset]) * 2 ** 32 +
1859
+ buf[++offset] * 2 ** 24 +
1860
+ buf[++offset] * 2 ** 16 +
1861
+ buf[++offset] * 2 ** 8 +
1862
+ last;
1863
+ }
1864
+
1865
+ export function readUInt40BE(buf, offset = 0) {
1866
+ validateNumber(offset, "offset");
1867
+ const first = buf[offset];
1868
+ const last = buf[offset + 4];
1869
+ if (first === undefined || last === undefined) {
1870
+ boundsError(offset, buf.length - 5);
1871
+ }
1872
+
1873
+ return first * 2 ** 32 +
1874
+ buf[++offset] * 2 ** 24 +
1875
+ buf[++offset] * 2 ** 16 +
1876
+ buf[++offset] * 2 ** 8 +
1877
+ last;
1878
+ }
1879
+
1880
+ export function readUInt24BE(buf, offset = 0) {
1881
+ validateNumber(offset, "offset");
1882
+ const first = buf[offset];
1883
+ const last = buf[offset + 2];
1884
+ if (first === undefined || last === undefined) {
1885
+ boundsError(offset, buf.length - 3);
1886
+ }
1887
+
1888
+ return first * 2 ** 16 + buf[++offset] * 2 ** 8 + last;
1889
+ }
1890
+
1891
+ export function readUInt16BE(offset = 0) {
1892
+ validateNumber(offset, "offset");
1893
+ const first = this[offset];
1894
+ const last = this[offset + 1];
1895
+ if (first === undefined || last === undefined) {
1896
+ boundsError(offset, this.length - 2);
1897
+ }
1898
+
1899
+ return first * 2 ** 8 + last;
1900
+ }
1901
+
1902
+ export function readUInt32BE(offset = 0) {
1903
+ validateNumber(offset, "offset");
1904
+ const first = this[offset];
1905
+ const last = this[offset + 3];
1906
+ if (first === undefined || last === undefined) {
1907
+ boundsError(offset, this.length - 4);
1908
+ }
1909
+
1910
+ return first * 2 ** 24 +
1911
+ this[++offset] * 2 ** 16 +
1912
+ this[++offset] * 2 ** 8 +
1913
+ last;
1914
+ }
1915
+
1916
+ export function readDoubleBackwards(buffer, offset = 0) {
1917
+ validateNumber(offset, "offset");
1918
+ const first = buffer[offset];
1919
+ const last = buffer[offset + 7];
1920
+ if (first === undefined || last === undefined) {
1921
+ boundsError(offset, buffer.length - 8);
1922
+ }
1923
+
1924
+ uInt8Float64Array[7] = first;
1925
+ uInt8Float64Array[6] = buffer[++offset];
1926
+ uInt8Float64Array[5] = buffer[++offset];
1927
+ uInt8Float64Array[4] = buffer[++offset];
1928
+ uInt8Float64Array[3] = buffer[++offset];
1929
+ uInt8Float64Array[2] = buffer[++offset];
1930
+ uInt8Float64Array[1] = buffer[++offset];
1931
+ uInt8Float64Array[0] = last;
1932
+ return float64Array[0];
1933
+ }
1934
+
1935
+ export function readDoubleForwards(buffer, offset = 0) {
1936
+ validateNumber(offset, "offset");
1937
+ const first = buffer[offset];
1938
+ const last = buffer[offset + 7];
1939
+ if (first === undefined || last === undefined) {
1940
+ boundsError(offset, buffer.length - 8);
1941
+ }
1942
+
1943
+ uInt8Float64Array[0] = first;
1944
+ uInt8Float64Array[1] = buffer[++offset];
1945
+ uInt8Float64Array[2] = buffer[++offset];
1946
+ uInt8Float64Array[3] = buffer[++offset];
1947
+ uInt8Float64Array[4] = buffer[++offset];
1948
+ uInt8Float64Array[5] = buffer[++offset];
1949
+ uInt8Float64Array[6] = buffer[++offset];
1950
+ uInt8Float64Array[7] = last;
1951
+ return float64Array[0];
1952
+ }
1953
+
1954
+ export function writeDoubleForwards(buffer, val, offset = 0) {
1955
+ val = +val;
1956
+ checkBounds(buffer, offset, 7);
1957
+
1958
+ float64Array[0] = val;
1959
+ buffer[offset++] = uInt8Float64Array[0];
1960
+ buffer[offset++] = uInt8Float64Array[1];
1961
+ buffer[offset++] = uInt8Float64Array[2];
1962
+ buffer[offset++] = uInt8Float64Array[3];
1963
+ buffer[offset++] = uInt8Float64Array[4];
1964
+ buffer[offset++] = uInt8Float64Array[5];
1965
+ buffer[offset++] = uInt8Float64Array[6];
1966
+ buffer[offset++] = uInt8Float64Array[7];
1967
+ return offset;
1968
+ }
1969
+
1970
+ export function writeDoubleBackwards(buffer, val, offset = 0) {
1971
+ val = +val;
1972
+ checkBounds(buffer, offset, 7);
1973
+
1974
+ float64Array[0] = val;
1975
+ buffer[offset++] = uInt8Float64Array[7];
1976
+ buffer[offset++] = uInt8Float64Array[6];
1977
+ buffer[offset++] = uInt8Float64Array[5];
1978
+ buffer[offset++] = uInt8Float64Array[4];
1979
+ buffer[offset++] = uInt8Float64Array[3];
1980
+ buffer[offset++] = uInt8Float64Array[2];
1981
+ buffer[offset++] = uInt8Float64Array[1];
1982
+ buffer[offset++] = uInt8Float64Array[0];
1983
+ return offset;
1984
+ }
1985
+
1986
+ export function readFloatBackwards(buffer, offset = 0) {
1987
+ validateNumber(offset, "offset");
1988
+ const first = buffer[offset];
1989
+ const last = buffer[offset + 3];
1990
+ if (first === undefined || last === undefined) {
1991
+ boundsError(offset, buffer.length - 4);
1992
+ }
1993
+
1994
+ uInt8Float32Array[3] = first;
1995
+ uInt8Float32Array[2] = buffer[++offset];
1996
+ uInt8Float32Array[1] = buffer[++offset];
1997
+ uInt8Float32Array[0] = last;
1998
+ return float32Array[0];
1999
+ }
2000
+
2001
+ export function readFloatForwards(buffer, offset = 0) {
2002
+ validateNumber(offset, "offset");
2003
+ const first = buffer[offset];
2004
+ const last = buffer[offset + 3];
2005
+ if (first === undefined || last === undefined) {
2006
+ boundsError(offset, buffer.length - 4);
2007
+ }
2008
+
2009
+ uInt8Float32Array[0] = first;
2010
+ uInt8Float32Array[1] = buffer[++offset];
2011
+ uInt8Float32Array[2] = buffer[++offset];
2012
+ uInt8Float32Array[3] = last;
2013
+ return float32Array[0];
2014
+ }
2015
+
2016
+ export function writeFloatForwards(buffer, val, offset = 0) {
2017
+ val = +val;
2018
+ checkBounds(buffer, offset, 3);
2019
+
2020
+ float32Array[0] = val;
2021
+ buffer[offset++] = uInt8Float32Array[0];
2022
+ buffer[offset++] = uInt8Float32Array[1];
2023
+ buffer[offset++] = uInt8Float32Array[2];
2024
+ buffer[offset++] = uInt8Float32Array[3];
2025
+ return offset;
2026
+ }
2027
+
2028
+ export function writeFloatBackwards(buffer, val, offset = 0) {
2029
+ val = +val;
2030
+ checkBounds(buffer, offset, 3);
2031
+
2032
+ float32Array[0] = val;
2033
+ buffer[offset++] = uInt8Float32Array[3];
2034
+ buffer[offset++] = uInt8Float32Array[2];
2035
+ buffer[offset++] = uInt8Float32Array[1];
2036
+ buffer[offset++] = uInt8Float32Array[0];
2037
+ return offset;
2038
+ }
2039
+
2040
+ export function readInt24LE(buf, offset = 0) {
2041
+ validateNumber(offset, "offset");
2042
+ const first = buf[offset];
2043
+ const last = buf[offset + 2];
2044
+ if (first === undefined || last === undefined) {
2045
+ boundsError(offset, buf.length - 3);
2046
+ }
2047
+
2048
+ const val = first + buf[++offset] * 2 ** 8 + last * 2 ** 16;
2049
+ return val | (val & 2 ** 23) * 0x1fe;
2050
+ }
2051
+
2052
+ export function readInt40LE(buf, offset = 0) {
2053
+ validateNumber(offset, "offset");
2054
+ const first = buf[offset];
2055
+ const last = buf[offset + 4];
2056
+ if (first === undefined || last === undefined) {
2057
+ boundsError(offset, buf.length - 5);
2058
+ }
2059
+
2060
+ return (last | (last & 2 ** 7) * 0x1fffffe) * 2 ** 32 +
2061
+ first +
2062
+ buf[++offset] * 2 ** 8 +
2063
+ buf[++offset] * 2 ** 16 +
2064
+ buf[++offset] * 2 ** 24;
2065
+ }
2066
+
2067
+ export function readInt48LE(buf, offset = 0) {
2068
+ validateNumber(offset, "offset");
2069
+ const first = buf[offset];
2070
+ const last = buf[offset + 5];
2071
+ if (first === undefined || last === undefined) {
2072
+ boundsError(offset, buf.length - 6);
2073
+ }
2074
+
2075
+ const val = buf[offset + 4] + last * 2 ** 8;
2076
+ return (val | (val & 2 ** 15) * 0x1fffe) * 2 ** 32 +
2077
+ first +
2078
+ buf[++offset] * 2 ** 8 +
2079
+ buf[++offset] * 2 ** 16 +
2080
+ buf[++offset] * 2 ** 24;
2081
+ }
2082
+
2083
+ export function readInt24BE(buf, offset = 0) {
2084
+ validateNumber(offset, "offset");
2085
+ const first = buf[offset];
2086
+ const last = buf[offset + 2];
2087
+ if (first === undefined || last === undefined) {
2088
+ boundsError(offset, buf.length - 3);
2089
+ }
2090
+
2091
+ const val = first * 2 ** 16 + buf[++offset] * 2 ** 8 + last;
2092
+ return val | (val & 2 ** 23) * 0x1fe;
2093
+ }
2094
+
2095
+ export function readInt48BE(buf, offset = 0) {
2096
+ validateNumber(offset, "offset");
2097
+ const first = buf[offset];
2098
+ const last = buf[offset + 5];
2099
+ if (first === undefined || last === undefined) {
2100
+ boundsError(offset, buf.length - 6);
2101
+ }
2102
+
2103
+ const val = buf[++offset] + first * 2 ** 8;
2104
+ return (val | (val & 2 ** 15) * 0x1fffe) * 2 ** 32 +
2105
+ buf[++offset] * 2 ** 24 +
2106
+ buf[++offset] * 2 ** 16 +
2107
+ buf[++offset] * 2 ** 8 +
2108
+ last;
2109
+ }
2110
+
2111
+ export function readInt40BE(buf, offset = 0) {
2112
+ validateNumber(offset, "offset");
2113
+ const first = buf[offset];
2114
+ const last = buf[offset + 4];
2115
+ if (first === undefined || last === undefined) {
2116
+ boundsError(offset, buf.length - 5);
2117
+ }
2118
+
2119
+ return (first | (first & 2 ** 7) * 0x1fffffe) * 2 ** 32 +
2120
+ buf[++offset] * 2 ** 24 +
2121
+ buf[++offset] * 2 ** 16 +
2122
+ buf[++offset] * 2 ** 8 +
2123
+ last;
2124
+ }
2125
+
2126
+ export function byteLengthUtf8(str) {
2127
+ return utf8Encoder.encode(str).length;
2128
+ }
2129
+
2130
+ function base64ByteLength(str, bytes) {
2131
+ // Handle padding
2132
+ if (str.charCodeAt(bytes - 1) === 0x3D) {
2133
+ bytes--;
2134
+ }
2135
+ if (bytes > 1 && str.charCodeAt(bytes - 1) === 0x3D) {
2136
+ bytes--;
2137
+ }
2138
+
2139
+ // Base64 ratio: 3/4
2140
+ return (bytes * 3) >>> 2;
2141
+ }
2142
+
2143
+ export const encodingsMap = Object.create(null);
2144
+ for (let i = 0; i < encodings.length; ++i) {
2145
+ encodingsMap[encodings[i]] = i;
2146
+ }
2147
+
2148
+ export const encodingOps = {
2149
+ ascii: {
2150
+ byteLength: (string) => string.length,
2151
+ encoding: "ascii",
2152
+ encodingVal: encodingsMap.ascii,
2153
+ indexOf: (buf, val, byteOffset, dir) =>
2154
+ indexOfBuffer(
2155
+ buf,
2156
+ asciiToBytes(val),
2157
+ byteOffset,
2158
+ encodingsMap.ascii,
2159
+ dir,
2160
+ ),
2161
+ slice: (buf, start, end) => buf.asciiSlice(start, end),
2162
+ write: (buf, string, offset, len) => buf.asciiWrite(string, offset, len),
2163
+ },
2164
+ base64: {
2165
+ byteLength: (string) => base64ByteLength(string, string.length),
2166
+ encoding: "base64",
2167
+ encodingVal: encodingsMap.base64,
2168
+ indexOf: (buf, val, byteOffset, dir) =>
2169
+ indexOfBuffer(
2170
+ buf,
2171
+ base64ToBytes(val),
2172
+ byteOffset,
2173
+ encodingsMap.base64,
2174
+ dir,
2175
+ ),
2176
+ slice: (buf, start, end) => buf.base64Slice(start, end),
2177
+ write: (buf, string, offset, len) => buf.base64Write(string, offset, len),
2178
+ },
2179
+ base64url: {
2180
+ byteLength: (string) => base64ByteLength(string, string.length),
2181
+ encoding: "base64url",
2182
+ encodingVal: encodingsMap.base64url,
2183
+ indexOf: (buf, val, byteOffset, dir) =>
2184
+ indexOfBuffer(
2185
+ buf,
2186
+ base64UrlToBytes(val),
2187
+ byteOffset,
2188
+ encodingsMap.base64url,
2189
+ dir,
2190
+ ),
2191
+ slice: (buf, start, end) => buf.base64urlSlice(start, end),
2192
+ write: (buf, string, offset, len) =>
2193
+ buf.base64urlWrite(string, offset, len),
2194
+ },
2195
+ hex: {
2196
+ byteLength: (string) => string.length >>> 1,
2197
+ encoding: "hex",
2198
+ encodingVal: encodingsMap.hex,
2199
+ indexOf: (buf, val, byteOffset, dir) =>
2200
+ indexOfBuffer(
2201
+ buf,
2202
+ hexToBytes(val),
2203
+ byteOffset,
2204
+ encodingsMap.hex,
2205
+ dir,
2206
+ ),
2207
+ slice: (buf, start, end) => buf.hexSlice(start, end),
2208
+ write: (buf, string, offset, len) => buf.hexWrite(string, offset, len),
2209
+ },
2210
+ latin1: {
2211
+ byteLength: (string) => string.length,
2212
+ encoding: "latin1",
2213
+ encodingVal: encodingsMap.latin1,
2214
+ indexOf: (buf, val, byteOffset, dir) =>
2215
+ indexOfBuffer(
2216
+ buf,
2217
+ asciiToBytes(val),
2218
+ byteOffset,
2219
+ encodingsMap.latin1,
2220
+ dir,
2221
+ ),
2222
+ slice: (buf, start, end) => buf.latin1Slice(start, end),
2223
+ write: (buf, string, offset, len) => buf.latin1Write(string, offset, len),
2224
+ },
2225
+ ucs2: {
2226
+ byteLength: (string) => string.length * 2,
2227
+ encoding: "ucs2",
2228
+ encodingVal: encodingsMap.utf16le,
2229
+ indexOf: (buf, val, byteOffset, dir) =>
2230
+ indexOfBuffer(
2231
+ buf,
2232
+ utf16leToBytes(val),
2233
+ byteOffset,
2234
+ encodingsMap.utf16le,
2235
+ dir,
2236
+ ),
2237
+ slice: (buf, start, end) => buf.ucs2Slice(start, end),
2238
+ write: (buf, string, offset, len) => buf.ucs2Write(string, offset, len),
2239
+ },
2240
+ utf8: {
2241
+ byteLength: byteLengthUtf8,
2242
+ encoding: "utf8",
2243
+ encodingVal: encodingsMap.utf8,
2244
+ indexOf: (buf, val, byteOffset, dir) =>
2245
+ indexOfBuffer(
2246
+ buf,
2247
+ utf8Encoder.encode(val),
2248
+ byteOffset,
2249
+ encodingsMap.utf8,
2250
+ dir,
2251
+ ),
2252
+ slice: (buf, start, end) => buf.utf8Slice(start, end),
2253
+ write: (buf, string, offset, len) => buf.utf8Write(string, offset, len),
2254
+ },
2255
+ utf16le: {
2256
+ byteLength: (string) => string.length * 2,
2257
+ encoding: "utf16le",
2258
+ encodingVal: encodingsMap.utf16le,
2259
+ indexOf: (buf, val, byteOffset, dir) =>
2260
+ indexOfBuffer(
2261
+ buf,
2262
+ utf16leToBytes(val),
2263
+ byteOffset,
2264
+ encodingsMap.utf16le,
2265
+ dir,
2266
+ ),
2267
+ slice: (buf, start, end) => buf.ucs2Slice(start, end),
2268
+ write: (buf, string, offset, len) => buf.ucs2Write(string, offset, len),
2269
+ },
2270
+ };
2271
+
2272
+ export function getEncodingOps(encoding) {
2273
+ encoding = String(encoding).toLowerCase();
2274
+ switch (encoding.length) {
2275
+ case 4:
2276
+ if (encoding === "utf8") return encodingOps.utf8;
2277
+ if (encoding === "ucs2") return encodingOps.ucs2;
2278
+ break;
2279
+ case 5:
2280
+ if (encoding === "utf-8") return encodingOps.utf8;
2281
+ if (encoding === "ascii") return encodingOps.ascii;
2282
+ if (encoding === "ucs-2") return encodingOps.ucs2;
2283
+ break;
2284
+ case 7:
2285
+ if (encoding === "utf16le") {
2286
+ return encodingOps.utf16le;
2287
+ }
2288
+ break;
2289
+ case 8:
2290
+ if (encoding === "utf-16le") {
2291
+ return encodingOps.utf16le;
2292
+ }
2293
+ break;
2294
+ // deno-lint-ignore no-fallthrough
2295
+ case 6:
2296
+ if (encoding === "latin1" || encoding === "binary") {
2297
+ return encodingOps.latin1;
2298
+ }
2299
+ if (encoding === "base64") return encodingOps.base64;
2300
+ case 3:
2301
+ if (encoding === "hex") {
2302
+ return encodingOps.hex;
2303
+ }
2304
+ break;
2305
+ case 9:
2306
+ if (encoding === "base64url") {
2307
+ return encodingOps.base64url;
2308
+ }
2309
+ break;
2310
+ }
2311
+ }
2312
+
2313
+ export function _copyActual(
2314
+ source,
2315
+ target,
2316
+ targetStart,
2317
+ sourceStart,
2318
+ sourceEnd,
2319
+ ) {
2320
+ if (sourceEnd - sourceStart > target.length - targetStart) {
2321
+ sourceEnd = sourceStart + target.length - targetStart;
2322
+ }
2323
+
2324
+ let nb = sourceEnd - sourceStart;
2325
+ const sourceLen = source.length - sourceStart;
2326
+ if (nb > sourceLen) {
2327
+ nb = sourceLen;
2328
+ }
2329
+
2330
+ if (sourceStart !== 0 || sourceEnd < source.length) {
2331
+ source = new Uint8Array(source.buffer, source.byteOffset + sourceStart, nb);
2332
+ }
2333
+
2334
+ target.set(source, targetStart);
2335
+
2336
+ return nb;
2337
+ }
2338
+
2339
+ export function boundsError(value, length, type) {
2340
+ if (Math.floor(value) !== value) {
2341
+ validateNumber(value, type);
2342
+ throw new codes.ERR_OUT_OF_RANGE(type || "offset", "an integer", value);
2343
+ }
2344
+
2345
+ if (length < 0) {
2346
+ throw new codes.ERR_BUFFER_OUT_OF_BOUNDS();
2347
+ }
2348
+
2349
+ throw new codes.ERR_OUT_OF_RANGE(
2350
+ type || "offset",
2351
+ `>= ${type ? 1 : 0} and <= ${length}`,
2352
+ value,
2353
+ );
2354
+ }
2355
+
2356
+ export function validateNumber(value, name) {
2357
+ if (typeof value !== "number") {
2358
+ throw new codes.ERR_INVALID_ARG_TYPE(name, "number", value);
2359
+ }
2360
+ }
2361
+
2362
+ function checkInt(value, min, max, buf, offset, byteLength) {
2363
+ if (value > max || value < min) {
2364
+ const n = typeof min === "bigint" ? "n" : "";
2365
+ let range;
2366
+ if (byteLength > 3) {
2367
+ if (min === 0 || min === 0n) {
2368
+ range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`;
2369
+ } else {
2370
+ range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and ` +
2371
+ `< 2${n} ** ${(byteLength + 1) * 8 - 1}${n}`;
2372
+ }
2373
+ } else {
2374
+ range = `>= ${min}${n} and <= ${max}${n}`;
2375
+ }
2376
+ throw new codes.ERR_OUT_OF_RANGE("value", range, value);
2377
+ }
2378
+ checkBounds(buf, offset, byteLength);
2379
+ }
2380
+
2381
+ export function toInteger(n, defaultVal) {
2382
+ n = +n;
2383
+ if (
2384
+ !Number.isNaN(n) &&
2385
+ n >= Number.MIN_SAFE_INTEGER &&
2386
+ n <= Number.MAX_SAFE_INTEGER
2387
+ ) {
2388
+ return ((n % 1) === 0 ? n : Math.floor(n));
2389
+ }
2390
+ return defaultVal;
2391
+ }
2392
+
2393
+ // deno-lint-ignore camelcase
2394
+ export function writeU_Int8(buf, value, offset, min, max) {
2395
+ value = +value;
2396
+ validateNumber(offset, "offset");
2397
+ if (value > max || value < min) {
2398
+ throw new codes.ERR_OUT_OF_RANGE("value", `>= ${min} and <= ${max}`, value);
2399
+ }
2400
+ if (buf[offset] === undefined) {
2401
+ boundsError(offset, buf.length - 1);
2402
+ }
2403
+
2404
+ buf[offset] = value;
2405
+ return offset + 1;
2406
+ }
2407
+
2408
+ // deno-lint-ignore camelcase
2409
+ export function writeU_Int16BE(buf, value, offset, min, max) {
2410
+ value = +value;
2411
+ checkInt(value, min, max, buf, offset, 1);
2412
+
2413
+ buf[offset++] = value >>> 8;
2414
+ buf[offset++] = value;
2415
+ return offset;
2416
+ }
2417
+
2418
+ export function _writeUInt32LE(buf, value, offset, min, max) {
2419
+ value = +value;
2420
+ checkInt(value, min, max, buf, offset, 3);
2421
+
2422
+ buf[offset++] = value;
2423
+ value = value >>> 8;
2424
+ buf[offset++] = value;
2425
+ value = value >>> 8;
2426
+ buf[offset++] = value;
2427
+ value = value >>> 8;
2428
+ buf[offset++] = value;
2429
+ return offset;
2430
+ }
2431
+
2432
+ // deno-lint-ignore camelcase
2433
+ export function writeU_Int16LE(buf, value, offset, min, max) {
2434
+ value = +value;
2435
+ checkInt(value, min, max, buf, offset, 1);
2436
+
2437
+ buf[offset++] = value;
2438
+ buf[offset++] = value >>> 8;
2439
+ return offset;
2440
+ }
2441
+
2442
+ export function _writeUInt32BE(buf, value, offset, min, max) {
2443
+ value = +value;
2444
+ checkInt(value, min, max, buf, offset, 3);
2445
+
2446
+ buf[offset + 3] = value;
2447
+ value = value >>> 8;
2448
+ buf[offset + 2] = value;
2449
+ value = value >>> 8;
2450
+ buf[offset + 1] = value;
2451
+ value = value >>> 8;
2452
+ buf[offset] = value;
2453
+ return offset + 4;
2454
+ }
2455
+
2456
+ // deno-lint-ignore camelcase
2457
+ export function writeU_Int48BE(buf, value, offset, min, max) {
2458
+ value = +value;
2459
+ checkInt(value, min, max, buf, offset, 5);
2460
+
2461
+ const newVal = Math.floor(value * 2 ** -32);
2462
+ buf[offset++] = newVal >>> 8;
2463
+ buf[offset++] = newVal;
2464
+ buf[offset + 3] = value;
2465
+ value = value >>> 8;
2466
+ buf[offset + 2] = value;
2467
+ value = value >>> 8;
2468
+ buf[offset + 1] = value;
2469
+ value = value >>> 8;
2470
+ buf[offset] = value;
2471
+ return offset + 4;
2472
+ }
2473
+
2474
+ // deno-lint-ignore camelcase
2475
+ export function writeU_Int40BE(buf, value, offset, min, max) {
2476
+ value = +value;
2477
+ checkInt(value, min, max, buf, offset, 4);
2478
+
2479
+ buf[offset++] = Math.floor(value * 2 ** -32);
2480
+ buf[offset + 3] = value;
2481
+ value = value >>> 8;
2482
+ buf[offset + 2] = value;
2483
+ value = value >>> 8;
2484
+ buf[offset + 1] = value;
2485
+ value = value >>> 8;
2486
+ buf[offset] = value;
2487
+ return offset + 4;
2488
+ }
2489
+
2490
+ // deno-lint-ignore camelcase
2491
+ export function writeU_Int32BE(buf, value, offset, min, max) {
2492
+ value = +value;
2493
+ checkInt(value, min, max, buf, offset, 3);
2494
+
2495
+ buf[offset + 3] = value;
2496
+ value = value >>> 8;
2497
+ buf[offset + 2] = value;
2498
+ value = value >>> 8;
2499
+ buf[offset + 1] = value;
2500
+ value = value >>> 8;
2501
+ buf[offset] = value;
2502
+ return offset + 4;
2503
+ }
2504
+
2505
+ // deno-lint-ignore camelcase
2506
+ export function writeU_Int24BE(buf, value, offset, min, max) {
2507
+ value = +value;
2508
+ checkInt(value, min, max, buf, offset, 2);
2509
+
2510
+ buf[offset + 2] = value;
2511
+ value = value >>> 8;
2512
+ buf[offset + 1] = value;
2513
+ value = value >>> 8;
2514
+ buf[offset] = value;
2515
+ return offset + 3;
2516
+ }
2517
+
2518
+ export function validateOffset(
2519
+ value,
2520
+ name,
2521
+ min = 0,
2522
+ max = Number.MAX_SAFE_INTEGER,
2523
+ ) {
2524
+ if (typeof value !== "number") {
2525
+ throw new codes.ERR_INVALID_ARG_TYPE(name, "number", value);
2526
+ }
2527
+ if (!Number.isInteger(value)) {
2528
+ throw new codes.ERR_OUT_OF_RANGE(name, "an integer", value);
2529
+ }
2530
+ if (value < min || value > max) {
2531
+ throw new codes.ERR_OUT_OF_RANGE(name, `>= ${min} && <= ${max}`, value);
2532
+ }
2533
+ }
2534
+
2535
+ // deno-lint-ignore camelcase
2536
+ export function writeU_Int48LE(buf, value, offset, min, max) {
2537
+ value = +value;
2538
+ checkInt(value, min, max, buf, offset, 5);
2539
+
2540
+ const newVal = Math.floor(value * 2 ** -32);
2541
+ buf[offset++] = value;
2542
+ value = value >>> 8;
2543
+ buf[offset++] = value;
2544
+ value = value >>> 8;
2545
+ buf[offset++] = value;
2546
+ value = value >>> 8;
2547
+ buf[offset++] = value;
2548
+ buf[offset++] = newVal;
2549
+ buf[offset++] = newVal >>> 8;
2550
+ return offset;
2551
+ }
2552
+
2553
+ // deno-lint-ignore camelcase
2554
+ export function writeU_Int40LE(buf, value, offset, min, max) {
2555
+ value = +value;
2556
+ checkInt(value, min, max, buf, offset, 4);
2557
+
2558
+ const newVal = value;
2559
+ buf[offset++] = value;
2560
+ value = value >>> 8;
2561
+ buf[offset++] = value;
2562
+ value = value >>> 8;
2563
+ buf[offset++] = value;
2564
+ value = value >>> 8;
2565
+ buf[offset++] = value;
2566
+ buf[offset++] = Math.floor(newVal * 2 ** -32);
2567
+ return offset;
2568
+ }
2569
+
2570
+ // deno-lint-ignore camelcase
2571
+ export function writeU_Int32LE(buf, value, offset, min, max) {
2572
+ value = +value;
2573
+ checkInt(value, min, max, buf, offset, 3);
2574
+
2575
+ buf[offset++] = value;
2576
+ value = value >>> 8;
2577
+ buf[offset++] = value;
2578
+ value = value >>> 8;
2579
+ buf[offset++] = value;
2580
+ value = value >>> 8;
2581
+ buf[offset++] = value;
2582
+ return offset;
2583
+ }
2584
+
2585
+ // deno-lint-ignore camelcase
2586
+ export function writeU_Int24LE(buf, value, offset, min, max) {
2587
+ value = +value;
2588
+ checkInt(value, min, max, buf, offset, 2);
2589
+
2590
+ buf[offset++] = value;
2591
+ value = value >>> 8;
2592
+ buf[offset++] = value;
2593
+ value = value >>> 8;
2594
+ buf[offset++] = value;
2595
+ return offset;
2596
+ }
2597
+
2598
+ export default {
2599
+ atob,
2600
+ btoa,
2601
+ Blob,
2602
+ Buffer,
2603
+ constants,
2604
+ kMaxLength,
2605
+ kStringMaxLength,
2606
+ SlowBuffer,
2607
+ };