ntdash / zipstore
a single level virtual zip store
v0.1.2
2025-04-21 04:23 UTC
Requires
- php: ^8.1
- nesbot/carbon: ^2.73.0
Requires (Dev)
- laravel/pint: ^1.21
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
- symfony/process: ^7.2
README
In a constraint environment where a storage is scarce, ZipStore allow us to load file into a a virtual store and to seek and read any bytes from any postion in the file as if you were seeking and reading a native resource (i.e: returned value of fopen())
ZipStore reduce the storage usage by only genrating the components of a the resulting zip file while reading the content of added files on the fly
Important
ZipStore, Even though convinient, does restrict you from delivering core features of a zip file, like encryption and content deflation, so it is to be use with the awarness of the limitation
Installation
- php >=8.1 required
composer require ntdash/zip-store
Usage
Initialization
/* Typical initialization */ $store = new \ZipStore\Store();
Add file(s)
$store->addFile("map.json"); $store->addFiles([ "video.webm", "sample.png" ]);
Ready to start reading
$openedStore = $store->open();
Seek and Read
/* offset retrieve from custom user logic or Request Range*/ $offset = ...; $bytes = 1024 * 1024 * 4; $openStore->seek($offset); $buff = $openStore->read($bytes); /* both at the same time */ $buff2 = $openedStore->read($bytes, $offset); /* number of bytes to be read is optionnal with a default of 1MiB */ $buff3 = $openedStore->read(offset: $offset);
Closing resources
yeah! you don't ! 'cause there is nothing to close