Skip to content

feat: suport compressed files #4

@RodrigoDornelles

Description

@RodrigoDornelles

allow decompressing, as this serves both to load game roms and fonts from other sites.

I'm trying to use DecompressionStream but I still don't understand how to use the API.

export function isDeflate(fileContent: string): boolean {
    return fileContent.slice(0, 2) == 'PK'
}

export async function fileFromDeflate(fileContent: string): Promise<string> {
    const zipData = Uint8Array.from(fileContent, (c) => c.charCodeAt(0));
    console.log(zipData)

    // @ts-ignore
    const decompressionStream = new DecompressionStream('deflate');

    const response = new Response(zipData);
    console.log(response)

    // @ts-ignore
    const unzippedStream = response.body.pipeThrough(decompressionStream);
    
    const unzippedText = await new Response(unzippedStream).blob();
    return unzippedText.text(); 
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions