|
| 1 | +import { encodeBase64 } from "@std/encoding/base64"; |
1 | 2 | import { |
| 3 | + HOLE, |
2 | 4 | INFINITY_NEG, |
3 | 5 | INFINITY_POS, |
4 | 6 | NAN, |
5 | 7 | NULL, |
6 | 8 | UNDEFINED, |
7 | 9 | ZERO_NEG, |
8 | 10 | } from "./constants.ts"; |
9 | | -import { HOLE } from "./constants.ts"; |
10 | 11 |
|
11 | 12 | export type Stringifiers = Record< |
12 | 13 | string, |
@@ -109,7 +110,7 @@ function serializeInner( |
109 | 110 | } else if (value instanceof RegExp) { |
110 | 111 | str += `["RegExp",${JSON.stringify(value.source)}, "${value.flags}"]`; |
111 | 112 | } else if (value instanceof Uint8Array) { |
112 | | - str += `["Uint8Array","${b64encode(value.buffer)}"]`; |
| 113 | + str += `["Uint8Array","${encodeBase64(value)}"]`; |
113 | 114 | } else if (value instanceof Set) { |
114 | 115 | const items = new Array(value.size); |
115 | 116 | let i = 0; |
@@ -147,43 +148,3 @@ function serializeInner( |
147 | 148 | out[idx] = str; |
148 | 149 | return idx; |
149 | 150 | } |
150 | | - |
151 | | -// deno-fmt-ignore |
152 | | -const base64abc = [ |
153 | | - "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", |
154 | | - "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", |
155 | | - "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", |
156 | | - "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", |
157 | | - "8", "9", "+", "/", |
158 | | -]; |
159 | | - |
160 | | -/** |
161 | | - * CREDIT: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727 |
162 | | - * Encodes a given Uint8Array, ArrayBuffer or string into RFC4648 base64 representation |
163 | | - */ |
164 | | -export function b64encode(buffer: ArrayBufferLike): string { |
165 | | - const uint8 = new Uint8Array(buffer); |
166 | | - let result = "", |
167 | | - i; |
168 | | - const l = uint8.length; |
169 | | - for (i = 2; i < l; i += 3) { |
170 | | - result += base64abc[uint8[i - 2] >> 2]; |
171 | | - result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)]; |
172 | | - result += base64abc[((uint8[i - 1] & 0x0f) << 2) | (uint8[i] >> 6)]; |
173 | | - result += base64abc[uint8[i] & 0x3f]; |
174 | | - } |
175 | | - if (i === l + 1) { |
176 | | - // 1 octet yet to write |
177 | | - result += base64abc[uint8[i - 2] >> 2]; |
178 | | - result += base64abc[(uint8[i - 2] & 0x03) << 4]; |
179 | | - result += "=="; |
180 | | - } |
181 | | - if (i === l) { |
182 | | - // 2 octets yet to write |
183 | | - result += base64abc[uint8[i - 2] >> 2]; |
184 | | - result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)]; |
185 | | - result += base64abc[(uint8[i - 1] & 0x0f) << 2]; |
186 | | - result += "="; |
187 | | - } |
188 | | - return result; |
189 | | -} |
0 commit comments