2017 © Pedro Peláez
 

symfony-bundle zip-streamed-response-bundle

A symfony Response to build and stream Zip on the fly

image

wamania/zip-streamed-response-bundle

A symfony Response to build and stream Zip on the fly

  • Monday, October 17, 2016
  • by Wamania
  • Repository
  • 1 Watchers
  • 8 Stars
  • 6,188 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 2 Open issues
  • 2 Versions
  • 27 % Grown

The README.md

ZipStreamedResponseBundle

Largely inspired by ZipStream-PHP, PHPZip and of course, the ZIP specifications., (*1)

Installation

Require wamania/zip-streamed-response-bundle into your composer.json file:, (*2)

``` json { "require": { "wamania/zip-streamed-response-bundle": "dev-master" } }, (*3)

Register the bundle in `app/AppKernel.php`:

``` php
// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Wamania\ZipStreamedResponseBundle\ZipStreamedResponseBundle(),
    );
}

Usage

In your controller :, (*4)

``` php // .... use Wamania\ZipStreamedResponseBundle\Response\ZipStreamer\ZipStreamer; use Wamania\ZipStreamedResponseBundle\Response\ZipStreamer\ZipStreamerFile; use Wamania\ZipStreamedResponseBundle\Response\ZipStreamer\ZipStreamerBigFile; use Wamania\ZipStreamedResponseBundle\Response\ZipStreamedResponse;, (*5)

class DefaultController extends Controller { /** * @Route("/", name="homepage") */ public function indexAction() { $zipStreamer = new ZipStreamer('test.zip');, (*6)

    // Auto switch files above switchAboveSize to "big files"
    ZipStreamer::setAutoSwitch(false/true); // default = true

    // If autoSwitch==true, files above $switchAboveSize will switch to "big files"
    ZipStreamer::setSwitchAboveSize(16777216); // default = 16Mb

    // For big file, size of the buffer for fread
    ZipStreamerBigFile::setBufferSize(1048576); //default = 1Mb

    // first string is localpath on hdd, second is pathname in zip
    $zipStreamer->add(
      '/home/wamania/photo.jpg', 
      'images/photo.jpg');

    // you can send directly a ZipStreamerFile object
    $zipStreamer->add(
      new ZipStreamerFile(
        '/home/wamania/movie.mp4', 
        'movies/movie.mp4'));

    // Big files are send by stream instead of being charged whole in RAM
    // Big files are NOT compressed
    $zipStreamer->addBigFile(
      '/home/wamania/another-big-movie.mp4', 
      'movies/another-big-movie.mp4');

    // or, directly send a ZipStreamerBigFile object
    $zipStreamer->add(
      new ZipStreamerBigFile(
        '/home/wamania/the-big-movie.mp4', 
        'movies/the-big-movie.mp4'));

    return new ZipStreamedResponse($zipStreamer);
}

} ```, (*7)

The Versions

17/10 2016

dev-master

9999999-dev https://github.com/wamania/ZipStreamedResponseBundle

A symfony Response to build and stream Zip on the fly

  Sources   Download

MIT

The Requires

 

17/10 2016

1.0

1.0.0.0 https://github.com/wamania/ZipStreamedResponseBundle

A symfony Response to build and stream Zip on the fly

  Sources   Download

MIT

The Requires