mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
buffer: improve btoa
performance
PR-URL: https://github.com/nodejs/node/pull/52427 Reviewed-By: Daniel Lemire <daniel@lemire.me> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
ee4fa77624
commit
21211a3fa9
3 changed files with 84 additions and 6 deletions
|
@ -69,6 +69,7 @@ const {
|
|||
kMaxLength,
|
||||
kStringMaxLength,
|
||||
atob: _atob,
|
||||
btoa: _btoa,
|
||||
} = internalBinding('buffer');
|
||||
const {
|
||||
constants: {
|
||||
|
@ -1249,13 +1250,11 @@ function btoa(input) {
|
|||
if (arguments.length === 0) {
|
||||
throw new ERR_MISSING_ARGS('input');
|
||||
}
|
||||
input = `${input}`;
|
||||
for (let n = 0; n < input.length; n++) {
|
||||
if (input[n].charCodeAt(0) > 0xff)
|
||||
throw lazyDOMException('Invalid character', 'InvalidCharacterError');
|
||||
const result = _btoa(`${input}`);
|
||||
if (result === -1) {
|
||||
throw lazyDOMException('Invalid character', 'InvalidCharacterError');
|
||||
}
|
||||
const buf = Buffer.from(input, 'latin1');
|
||||
return buf.toString('base64');
|
||||
return result;
|
||||
}
|
||||
|
||||
function atob(input) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue