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

OperationMode::SIMULATE_STRICT and zero-byte files #301

Closed
4 tasks done
tomwelch opened this issue Apr 16, 2024 · 3 comments · Fixed by #302
Closed
4 tasks done

OperationMode::SIMULATE_STRICT and zero-byte files #301

tomwelch opened this issue Apr 16, 2024 · 3 comments · Fixed by #302
Assignees
Labels

Comments

@tomwelch
Copy link

tomwelch commented Apr 16, 2024

ZipStream-PHP version

3.1.0

PHP version

8.3.3

Constraints for Bug Report

Summary

I'm using the SIMULATE_STRICT Operation Mode to add the Content-Length header as documented here but I'm running into an error with zero-byte files (think .gitkeep etc)

Current behavior

A SimulationFileUnknownException is thrown when calling addFileFromCallback() and the exactSize is 0.

How to reproduce

Set the Operation Mode to SIMULATE_STRICT and add a file that has a size of zero bytes.

$files = [
    'hello-world.txt', // content: "hello world"
    'empty-file.txt',  // content: ""
];

$zip = new ZipStream(
    operationMode: OperationMode::SIMULATE_STRICT,
    defaultCompressionMethod: CompressionMethod::STORE,
    outputName: 'archive.zip',
);

foreach ($files as $path) {
    $zip->addFileFromCallback(
        fileName: basename($path),
        callback: fn () => fopen($path, 'r'),
        exactSize: filesize($path),
    );
}

$zip->finish();

Expected behavior

(Hopefully) it is possible to use the SIMULATE_STRICT Operation Mode with empty files.

@maennchen
Copy link
Owner

@tomwelch Can you try if #302 fixes your issue?

@maennchen maennchen changed the title OperationMode::SIMULATE_STRICT and zero-byte files OperationMode::SIMULATE_STRICT and zero-byte files Apr 22, 2024
@maennchen
Copy link
Owner

Closing in favor of PR

@tomwelch
Copy link
Author

Good morning @maennchen. That looks great, thank you for the fix!

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

Successfully merging a pull request may close this issue.

2 participants