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

Madzipper Reads Archive as Empty #44

Open
MannikJ opened this issue Jun 3, 2024 · 0 comments
Open

Madzipper Reads Archive as Empty #44

MannikJ opened this issue Jun 3, 2024 · 0 comments

Comments

@MannikJ
Copy link

MannikJ commented Jun 3, 2024

I have a problem where Madzipper cannot read the files from an archive I create during a test, whereas when using native ZipArchive there is no issue.

I am currently using PHP 8.3 together with Laravel v.10.39 and the latest Madzipper.

Creates an empty directory:

        $zipper = \Madzipper::make($extractSourcePath);
        $zipper->extractTo($extractTargetPath);
        $zipper->close();

Creates directory as expected containing all the files from the archive:

        $zipArchive = new \ZipArchive;
        $zipArchive->open($extractSourcePath);
        $zipArchive->extractTo($extractTargetPath);
        $zipArchive->close();

It doesn't matter if I am just using extractTo or listFiles, it just cannot read the contents. listFiles will return [] accordingly.

The common test code is:

        $response = $this->get(route('batch.zip.download', [
            'task_files' => $inputTaskFiles->implode('id', ',')
        ]));

        $response->assertStatus(200);

        $response->assertDownload();

        $fileName = 'task_batch';
        $sourceFileName = "{$fileName}.zip";

        $this->getTestStorageDisk()->put(
            $sourceFileName,
            $response->streamedContent()
        );

        $extractSourcePath = $this->getTestStorageDisk()->path($sourceFileName);
        $extractTargetPath = $this->getTestStorageDisk()->path($fileName);

The controller code uses the ZipStream package:

  return response()->streamDownload(function () use ($request, $name) {
            $zip = new ZipStream(
                outputName: $name,
                // enable output of HTTP headers
                sendHttpHeaders: true
            );

           // Add files to archive

            $zip->finish();

            return $zip;
        }, $name, [
            'Content-Type' => 'application/zip',
        ]);

I don't think it even matters how the archive is created, we can assume it's there and not empty.

Maybe someone can help to find out why this happens.

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