madnest / madzipper Goto Github PK
View Code? Open in Web Editor NEWEasier zip file handling for Laravel applications.
License: MIT License
Easier zip file handling for Laravel applications.
License: MIT License
The ->setPassword()
method is not setting the password for the archive you are making; it's just setting the password to use to extract files when reading a zip archive.
As noted in this comment https://www.php.net/manual/en/ziparchive.setpassword.php#122465 the correct way to create a password protected zip file is to use ->setEncryptionName('test.txt', ZipArchive::EM_AES_256, 'passw0rd');
on each file entry.
This is currently not possible on Madzipper because the repository is not giving public access to the ZipArchive
instance.
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.
The following parts of the code throw an error with php 8 because the implementation passes the named parameter $stats
which is neither defined in the methods signature nor used.
Error: Unknown named parameter $stats
xqz/vendor/madnest/madzipper/src/Madnest/Madzipper/Repositories/ZipRepository.php:119
xyz/vendor/madnest/madzipper/src/Madnest/Madzipper/Madzipper.php:501
Madzipper:
public function listFiles($regexFilter = null)
{
$filesList = [];
if ($regexFilter) {
$filter = function ($file) use (&$filesList, $regexFilter) {
// push/pop an error handler here to to make sure no error/exception thrown if $expected is not a regex
set_error_handler(function () {
});
$match = preg_match($regexFilter, $file);
restore_error_handler();
if ($match === 1) {
$filesList[] = $file;
} elseif ($match === false) {
throw new \RuntimeException("regular expression match on '$file' failed with error. Please check if pattern is valid regular expression.");
}
};
} else {
$filter = function ($file) use (&$filesList) {
$filesList[] = $file;
};
}
$this->repository->each($filter);
return $filesList;
}
ZipRepositry:
public function each($callback)
{
for ($i = 0; $i < $this->archive->numFiles; ++$i) {
//skip if folder
$stats = $this->archive->statIndex($i);
if ($stats['size'] === 0 && $stats['crc'] === 0) {
continue;
}
call_user_func_array($callback, [
'file' => $this->archive->getNameIndex($i),
'stats' => $this->archive->statIndex($i),
]);
}
}
Trying to install on a Laravel 6.8 but the composer requeriments dont allow it.
- madnest/madzipper v1.0.1 requires illuminate/support 5.8 - 6.0 -> satisfiable by laravel/framework[v6.0.4], illuminate/support[v5.8.0, v5.8.11, v5.8.12, v5.8.14, v5.8.15, v5.8.17, v5.8.18, v5.8.19, v5.8.2, v5.8.20, v5.8.22, v5.8.24, v5.8.27, v5.8.28, v5.8.29, v5.8.3, v5.8.30, v5.8.31, v5.8.32, v5.8.33, v5.8.34, v5.8.35, v5.8.36, v5.8.4, v5.8.8, v5.8.9, v6.0.0, v6.0.1, v6.0.2, v6.0.3, v6.0.4].
Any chance this is going to get Laravel 11 support? Thanks
Verison v1.2.2 doesn't support Laravel 8, which supposed to support up to Laravel 8 according to readme.
yarn composer require madnest/madzipper:v1.2.2
yarn run v1.22.19
warning ../../../../package.json: No license field
$ docker-compose exec web composer require madnest/madzipper:v1.2.2
./composer.json has been updated
Running composer update madnest/madzipper
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires madnest/madzipper v1.2.2 -> satisfiable by madnest/madzipper[v1.2.2].
- madnest/madzipper v1.2.2 requires illuminate/support ^9.0 -> found illuminate/support[v9.0.0-beta.1, ..., 9.x-dev] but these were not loaded, likely because it conflicts with another require.
I'd like to use this package as an alternative for the chumper/zipper
package.
I'm not using Laravel, but since Laravel is required in composer.json, the complete Laravel Package is installed.
Is it possible to drop the Laravel requirement from composer.json, so I can use it in my own project?
First line of the open method within ZipRepository class causes a deprecation error due to the fact that NULL is used as default second parameter. This should be 0 (zero).
Sample code to reproduce:
$zipper = new Madzipper;
$zipper->make($relativeFolder . $filenameZip)
->addString($filename, $qms_data)
->close();
$zipper = null; // close is also called via destructor of Madzipper
ZipRepository.php
/**
* Closes the archive and saves it
*/
public function close()
{
@$this->archive->close(); // <---- error surpressed
}
In PHP 8.0, the @ operator does not suppress certain types of errors that were silenced prior to PHP 8.0.
Until this is fixed, I don't call close() after adding the string but let de destructor close it.
After adding the files, creating the zip, it can be saved in the database with its respective model
Does this support aws s3
This deprecation warning can be avoided by passing the ZipArchive::OVERWRITE
flag.
More information here: https://stackoverflow.com/questions/64698935/using-ziparchive-with-php-8-and-temporary-files
Due to
PHP8 thinks file
and stats
are named params.
use Madnest\Madzipper\Madzipper;
$files = glob('public/docs/180121007/*');
Madzipper::make('public/test.zip')->add($files)->close();
Hi,
Is there a way to check if a file is valid zip archive?
$zipper = new Madzipper;
$zipper->make($filePath);
Exception: Error: Failed to open /private/var/folders/23/m470jpgs09z9jwq25xg96qw80000gn/T/phpfdvQjI! Error: ZipArchive::ER_NOZIP - Not a zip archive.
Hi there,
First of all thanks for providing this package :)
I'm trying to install v1.2 in my Laravel 8 application, but I'm getting a composer error:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires madnest/madzipper 1.2, found madnest/madzipper[dev-master, v0.0.1, v1.0.0, ..., v1.3.x-dev] but it does not match the constraint.
Hello guys,
I just realized that version 1.2.1 on Packagist says Madzipper is compatible with PHP ^7.3 when it accepts only PHP 7.4 or above.
As for what I've seen, the only issue that makes it to be incompatible with PHP 7.4 is the fact the class ZipRepository has a typed property called $open. PHP 7.3 does not accept these typed variables yet, but only PHP 7.4 or above.
public bool $open = false;
It could be great to fix this minor detail =).
Sincerely,
Felipe Pastana.
Just did an upgrade on a project:
chumper/zipper v1.0.0 requires illuminate/filesystem 5.x
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.