diff --git a/src/app/Utils.ts b/src/app/Utils.ts index aa37752f..207f5067 100644 --- a/src/app/Utils.ts +++ b/src/app/Utils.ts @@ -295,23 +295,23 @@ export class BiMap { } } -export async function readZip(file: File | ArrayBuffer, predicate: (name: string) => boolean = () => true): Promise<[string, string][]> { +export async function readZip(file: File | ArrayBuffer, predicate: (name: string) => boolean = () => true): Promise<[string, Uint8Array][]> { const buffer = file instanceof File ? await file.arrayBuffer() : file const reader = new zip.ZipReader(new zip.BlobReader(new Blob([buffer]))) const entries = await reader.getEntries() return await Promise.all(entries .filter(e => !e.directory && predicate(e.filename)) .map(async e => { - const writer = new zip.TextWriter('utf-8') - return [e.filename, await e.getData?.(writer)] as [string, string] + const writer = new zip.Uint8ArrayWriter() + return [e.filename, await e.getData?.(writer)] }) ) } -export async function writeZip(entries: [string, string][]): Promise { +export async function writeZip(entries: [string, Uint8Array][]): Promise { const writer = new zip.ZipWriter(new zip.Data64URIWriter('application/zip')) await Promise.all(entries.map(async ([name, data]) => { - await writer.add(name, new zip.TextReader(data)) + await writer.add(name, new zip.Uint8ArrayReader(data)) })) return await writer.close() } diff --git a/src/app/components/customized/CustomizedPanel.tsx b/src/app/components/customized/CustomizedPanel.tsx index 0bc95e8f..0b0df0b2 100644 --- a/src/app/components/customized/CustomizedPanel.tsx +++ b/src/app/components/customized/CustomizedPanel.tsx @@ -44,11 +44,13 @@ export function CustomizedPanel({ tab }: Props) { const entries = Object.entries(pack).flatMap(([type, files]) => { const prefix = `data/minecraft/${type}/` return [...files.entries()].map(([name, data]) => { - return [prefix + name + '.json', stringifySource(JSON.stringify(data, null, 2), 'json')] as [string, string] + const text = stringifySource(JSON.stringify(data, null, 2), 'json') + return [prefix + name + '.json', new TextEncoder().encode(text)] as [string, Uint8Array] }) }) const pack_format = config.versions.find(v => v.id === version)!.pack_format - entries.push(['pack.mcmeta', stringifySource(JSON.stringify({ pack: { pack_format, description: 'Customized world from misode.github.io' } }, null, 2), 'json')]) + const packMcmetaText = stringifySource(JSON.stringify({ pack: { pack_format, description: 'Customized world from misode.github.io' } }, null, 2), 'json') + entries.push(['pack.mcmeta', new TextEncoder().encode(packMcmetaText)]) const url = await writeZip(entries) download.current.setAttribute('href', url) download.current.setAttribute('download', 'customized.zip') diff --git a/src/app/components/generator/ProjectPanel.tsx b/src/app/components/generator/ProjectPanel.tsx index 8cbf2c66..1d71ca16 100644 --- a/src/app/components/generator/ProjectPanel.tsx +++ b/src/app/components/generator/ProjectPanel.tsx @@ -47,8 +47,7 @@ export function ProjectPanel() { if (!download.current || entries === undefined) return const zipEntries = await Promise.all(entries.map(async e => { const data = await client.fs.readFile(projectRoot + e) - const text = new TextDecoder().decode(data) - return [e, text] as [string, string] + return [e, data] as [string, Uint8Array] })) const url = await writeZip(zipEntries) download.current.setAttribute('href', url)