1. Go to this page and download the library: Download genkgo/archive-stream library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
genkgo / archive-stream example snippets
useGenkgo\ArchiveStream\Archive;
useGenkgo\ArchiveStream\CallbackContents;
useGenkgo\ArchiveStream\CallbackStringContent;
useGenkgo\ArchiveStream\EmptyDirectory;
useGenkgo\ArchiveStream\FileContent;
useGenkgo\ArchiveStream\Psr7Stream;
useGenkgo\ArchiveStream\StringContent;
useGenkgo\ArchiveStream\TarGzReader;
useGenkgo\ArchiveStream\TarReader;
useGenkgo\ArchiveStream\ZipReader;
$archive = (new Archive())
->withContent(new CallbackStringContent('callback.txt', function(){
return'data';
}))
->withContent(new StringContent('string.txt', 'data'))
->withContent(new FileContent('file.txt', 'local/file/name.txt'))
->withContent(new EmptyDirectory('directory'))
->withContents([new StringContent('string2.txt', 'data')])
->withContents(new CallbackContents(fn () => yieldnew StringContent('string3.txt', 'data')));
$response = $response->withBody(
new Psr7Stream(new ZipReader($archive))
);
// or for tar files
$response = $response->withBody(
new Psr7Stream(new TarReader($archive))
);
// or for tar.gz files
$response = $response->withBody(
new Psr7Stream(new TarGzReader(new TarReader($archive)))
);