Introduce some Uint8Array.fromBase64 and Uint8Array.prototype.toBase64 usage in the main code-base

See https://github.com/tc39/proposal-arraybuffer-base64
This commit is contained in:
Jonas Jenwald 2024-04-10 12:45:22 +02:00
parent f9fc477080
commit bfc645bab1
2 changed files with 3 additions and 5 deletions

View File

@ -102,7 +102,7 @@ import {
getStringOption, getStringOption,
HTMLResult, HTMLResult,
} from "./utils.js"; } from "./utils.js";
import { stringToBytes, Util, warn } from "../../shared/util.js"; import { Util, warn } from "../../shared/util.js";
import { getMetrics } from "./fonts.js"; import { getMetrics } from "./fonts.js";
import { recoverJsURL } from "../core_utils.js"; import { recoverJsURL } from "../core_utils.js";
import { searchNode } from "./som.js"; import { searchNode } from "./som.js";
@ -3427,7 +3427,7 @@ class Image extends StringObject {
} }
if (!buffer && this.transferEncoding === "base64") { if (!buffer && this.transferEncoding === "base64") {
buffer = stringToBytes(atob(this[$content])); buffer = Uint8Array.fromBase64(this[$content]);
} }
if (!buffer) { if (!buffer) {

View File

@ -15,7 +15,6 @@
import { import {
assert, assert,
bytesToString,
FontRenderOps, FontRenderOps,
isNodeJS, isNodeJS,
shadow, shadow,
@ -399,9 +398,8 @@ class FontFaceObject {
if (!this.data || this.disableFontFace) { if (!this.data || this.disableFontFace) {
return null; return null;
} }
const data = bytesToString(this.data);
// Add the @font-face rule to the document. // Add the @font-face rule to the document.
const url = `url(data:${this.mimetype};base64,${btoa(data)});`; const url = `url(data:${this.mimetype};base64,${this.data.toBase64()});`;
let rule; let rule;
if (!this.cssFontInfo) { if (!this.cssFontInfo) {
rule = `@font-face {font-family:"${this.loadedName}";src:${url}}`; rule = `@font-face {font-family:"${this.loadedName}";src:${url}}`;