Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deflate() creating broken zip file #267

Open
Umisyus opened this issue Jan 13, 2023 · 0 comments
Open

Deflate() creating broken zip file #267

Umisyus opened this issue Jan 13, 2023 · 0 comments

Comments

@Umisyus
Copy link

Umisyus commented Jan 13, 2023

Hello, I'm using Pako to create zip files on image buffers as the following type: U8IntArray.
The problem occurs when I use Pako to push the data into the zip object, I check for the last item in my for loop, then I call the final push with data as my first arg and true as my second arg.

// "files" is an array of data, split in pieces... An array of buffers.
// Example:
// ArrayOfManyFiles = [MoreFiles,MoreFiles, ... etc. ]
// MoreFiles = [ {key: string, value: Buffer}, {key: string, value: Buffer} ... ]
// 
   return new Promise(async (res, rej) => {

        let zp = new pako.Deflate()
        let final = false;

        for await (let file of files) {
            let len = file.length
            for (let index = 0; index < file.length; index++) {
                const ff = file[index];

                log.info(`Zipping ${ff.key}`)
                let data = (ff.value as any).data as Buffer
                const fileBuffer = new Uint8Array(data);

                if (index == len - 1) {
                    final = true;
                }

                zp.push(fileBuffer, final)

                if (zp.err > 0) {
                    rej("ERROR: " + Error("invalid file! " + ff.key))
                }
            }
        }
        let result = zp.result
        res(result)
    })

Please help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant