Giter Club home page Giter Club logo

zipstreamedresponsebundle's Introduction

ZipStreamedResponseBundle

Largely inspired by ZipStream-PHP, PHPZip and of course, the ZIP specifications.

Installation

Require wamania/zip-streamed-response-bundle into your composer.json file:

{
    "require": {
        "wamania/zip-streamed-response-bundle": "dev-master"
    }
}

Register the bundle in app/AppKernel.php:

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

Usage

In your controller :

// ....
use Wamania\ZipStreamedResponseBundle\Response\ZipStreamer\ZipStreamer;
use Wamania\ZipStreamedResponseBundle\Response\ZipStreamer\ZipStreamerFile;
use Wamania\ZipStreamedResponseBundle\Response\ZipStreamer\ZipStreamerBigFile;
use Wamania\ZipStreamedResponseBundle\Response\ZipStreamedResponse;


class DefaultController extends Controller
{
    /**
     * @Route("/", name="homepage")
     */
    public function indexAction()
    {
        $zipStreamer = new ZipStreamer('test.zip');
        
        // 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);
    }
}

zipstreamedresponsebundle's People

Contributors

wamania avatar jeanloop avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.