minor changes and import buffer

This commit is contained in:
Gabriel Gomes 2025-03-31 00:48:48 +01:00
parent 6ee38ad826
commit a89f353f5b
3 changed files with 10 additions and 6 deletions

View file

@ -1,5 +1,5 @@
import tEXt from "png-chunk-text";
import { encodeSync, decodeSync} from "png-chunk-itxt";
import * as iTXt from "png-chunk-itxt";
import encodePng from "png-chunks-encode";
import decodePng from "png-chunks-extract";
@ -28,7 +28,7 @@ export const getMetadataChunk = async (
if (iTXtChunk) {
try {
const decoded = decodeSync(iTXtChunk.data);
const decoded = iTXt.decodeSync(iTXtChunk.data);
console.log("Decoded iTXt chunk:", decoded);
return {
keyword: decoded.keyword,
@ -61,13 +61,13 @@ export const encodePngMetadata = async ({
useITXt?: boolean;
}) => {
const chunks = decodePng(new Uint8Array(await blobToArrayBuffer(blob)));
debugger;
const filteredChunks = chunks.filter(
(chunk) =>
!(chunk.name === "tEXt" &&
tEXt.decode(chunk.data).keyword === MIME_TYPES.excalidraw) &&
!(chunk.name === "iTXt" &&
decodeSync(chunk.data).keyword === MIME_TYPES.excalidraw)
iTXt.decodeSync(chunk.data).keyword === MIME_TYPES.excalidraw)
);
const encodedData = JSON.stringify(
@ -80,7 +80,7 @@ export const encodePngMetadata = async ({
let metadataChunk;
try {
if (useITXt) {
metadataChunk = encodeSync(
metadataChunk = iTXt.encodeSync(
MIME_TYPES.excalidraw,
encodedData,
{

View file

@ -56,7 +56,6 @@ declare module "png-chunk-itxt" {
language?: string;
translated?: string;
};
export { encodeSync, decodeSync };
}
declare module "png-chunks-encode" {
function encode(chunks: (TEXtChunk | ITXtChunk)[]): Uint8Array;

View file

@ -19,6 +19,11 @@ import type {
NonDeleted,
} from "@excalidraw/element/types";
import type { AppState, BinaryFiles } from "@excalidraw/excalidraw/types";
import { Buffer } from "buffer";
window.onload = () => {
window.Buffer = Buffer;
}
export { MIME_TYPES };