|
1 | 1 | import { assertEmptyRest } from './assert.js' |
2 | | -import { typedView } from './array.js' |
3 | | -import { assertU8, fromUint8, E_STRING } from './fallback/_utils.js' |
| 2 | +import { assertU8, fromUint8, fromBuffer, E_STRING } from './fallback/_utils.js' |
4 | 3 | import { isHermes } from './fallback/platform.js' |
5 | 4 | import { decodeLatin1, encodeLatin1 } from './fallback/latin1.js' |
6 | 5 | import * as js from './fallback/base64.js' |
@@ -140,12 +139,14 @@ if (Uint8Array.fromBase64) { |
140 | 139 | } |
141 | 140 | } else if (haveNativeBuffer) { |
142 | 141 | fromBase64impl = (str, isBase64url, padding, format) => { |
143 | | - const arr = Buffer.from(str, 'base64') |
| 142 | + const size = Buffer.byteLength(str, 'base64') |
| 143 | + const arr = Buffer.allocUnsafeSlow(size) // non-pooled |
| 144 | + if (arr.base64Write(str) !== size) throw new SyntaxError(E_PADDING) |
144 | 145 | // Rechecking by re-encoding is cheaper than regexes on Node.js |
145 | 146 | const got = isBase64url ? maybeUnpad(str, padding === false) : maybePad(str, padding !== true) |
146 | 147 | const valid = isBase64url ? arr.base64urlSlice(0, arr.length) : arr.base64Slice(0, arr.length) |
147 | 148 | if (got !== valid) throw new SyntaxError(E_PADDING) |
148 | | - return typedView(arr, format) // fully checked |
| 149 | + return fromBuffer(arr, format) // fully checked |
149 | 150 | } |
150 | 151 | } else if (shouldUseAtob) { |
151 | 152 | // atob is faster than manual parsing on Hermes |
|
0 commit comments