GithubHelp home page GithubHelp logo

joyes974 / archivestream-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from barracudanetworks/archivestream-php

0.0 2.0 0.0 158 KB

Archive streaming library for PHP

License: Other

PHP 100.00%

archivestream-php's Introduction

ArchiveStream 1.0.5

Code Climate

A library for dynamically streaming dynamic tar or zip files without the need to have the complete file stored on the server. You can specify if you want a tar or a zip; or if you want to have the library figure out the best option based on the user agent string.

Options

/**
 * Construct Parameters:
 *
 *   $name - Name of output file (optional).
 *   $opt  - Hash of archive options (optional, see "Archive Options"
 *           below).
 *
 * Archive Options:
 *
 *   comment             - Comment for this archive. (zip only)
 *   content_type        - HTTP Content-Type.  Defaults to 'application/x-zip'.
 *   content_disposition - HTTP Content-Disposition.  Defaults to
 *                         'attachment; filename=\"FILENAME\"', where
 *                         FILENAME is the specified filename.
 *   large_file_size     - Size, in bytes, of the largest file to try
 *                         and load into memory (used by
 *                         add_file_from_path()).  Large files may also
 *                         be compressed differently; see the
 *                         'large_file_method' option.
 *   send_http_headers   - Boolean indicating whether or not to send
 *                         the HTTP headers for this file.
 *   large_files_only    - Boolean indicating whether or not to assume
 *                         that all files we are sending are large.
 *
 * File Options:
 *  time     - Last-modified timestamp (seconds since the epoch) of
 *             this file.  Defaults to the current time.
 *  comment  - Comment related to this file. (zip only)
 *  type     - Type of file object. (tar only)
 *
 *
 * Note that content_type and content_disposition do nothing if you are
 * not sending HTTP headers.
 *
 * Large File Support:
 *
 * By default, the method add_file_from_path() will send send files
 * larger than 20 megabytes along raw rather than attempting to
 * compress them.  You can change both the maximum size and the
 * compression behavior using the large_file_* options above, with the
 * following caveats:
 *
 * * For "small" files (e.g. files smaller than large_file_size), the
 *   memory use can be up to twice that of the actual file.  In other
 *   words, adding a 10 megabyte file to the archive could potentially
 *   occupty 20 megabytes of memory.
 *
 * * For "large" files we use the store method, meaning that the file is
 *   not compressed at all, this is because there is not currenly a good way
 *   to compress a stream within PHP
 *
 * Notes:
 *
 * If you do not set a filename, then this library _DOES NOT_ send HTTP
 * headers by default.  This behavior is to allow software to send its
 * own headers (including the filename), and still use this library.
 */

Usage

Stream whole file at a time

A fast and simple streaming archive files for PHP. Here's a simple example:

// Create a new archive stream object (tar or zip depending on user agent)
$zip = \Barracuda\ArchiveStream\Archive::instance_by_useragent('example');

// Create a file named 'hello.txt'
$zip->add_file('hello.txt', 'This is the contents of hello.txt');

// Add a file named 'image.jpg' from a local file 'path/to/image.jpg'
$zip->add_file_from_path('image.jpg', 'path/to/image.jpg');

// Finish the zip stream
$zip->finish();

Stream each file in parts

This method can be used to serve files of any size (GB, TB).

// Create a new archive stream object (tar or zip depending on user agent)
$zip = \Barracuda\ArchiveStream\Archive::instance_by_useragent('example');

// Initiate the stream transfer of some_image.jpg with size 324134
$zip->init_file_stream_transfer('some_image.jpg', 324134);

// Stream part of the contents of some_image.jpg
// This method should be called as many times as needed to send all of its data
$zip->stream_file_part($data);

// Send data descriptor header for file
$zip->complete_file_stream();

// Other files can be added here, simply run the three commands above for each file that is being sent

// Explicitly add a directory to the zip (doesn't recurse - useful for empty
// directories)
$zip->add_directory('foo');
$zip->add_directory('foo/bar');

// Finish the zip stream
$zip->finish();

Installation

Simply run composer require barracudanetworks/archivestream-php inside your project.

Requirements

Limitations

  • Only the Zip64 (version 4.5 of the Zip specification) format is supported.
  • Files cannot be resumed if a download fails before finishing.

Other

You can also add comments, modify file timestamps, and customize (or disable) the HTTP headers. See the class file for details.

Contributors

  • Paul Duncan - Original author
  • Daniel Bergey
  • Andy Blyler
  • Tony Blyler
  • Andrew Borek
  • Rafael Corral
  • John Maguire

License

Original work Copyright 2007-2009 Paul Duncan [email protected] Modified work Copyright 2013-2015 Barracuda Networks, Inc.

Licensed under the MIT License

archivestream-php's People

Contributors

pablotron avatar johnmaguire avatar ablyler avatar rcorral avatar meowvalent avatar shimeche avatar donatj avatar luku avatar rairlie avatar samsouder avatar pvitaly avatar

Watchers

James Cloos avatar MOHAIMEN KHAN 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.