Skip to content

Commit

Permalink
Merge pull request #48 from sami-bel/master
Browse files Browse the repository at this point in the history
 Fix output stream for web server
  • Loading branch information
Meowvalent authored May 21, 2020
2 parents 87540ce + 34e0e37 commit c66e749
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ A library for dynamically streaming dynamic tar or zip files without the need to
* $name - Name of output file (optional).
* $opt - Hash of archive options (optional, see "Archive Options"
* below).
* $output_stream - Output stream for archive (optional - defaults to STDOUT)
* $output_stream - Output stream for archive (optional - defaults to php://output)
*
* Archive Options:
*
Expand Down
20 changes: 15 additions & 5 deletions src/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ public function __construct(
$name = null,
array $opt = array(),
$base_path = null,
$output_stream = STDOUT
$output_stream = null
)
{
$this->output_stream = $output_stream;
{
if ($output_stream === null) {
// Output stream for cli and web server
$output_stream = fopen('php://output', 'w');
}

$this->output_stream = $output_stream;

// save options
$this->opt = $opt;
Expand Down Expand Up @@ -101,14 +106,19 @@ public function __construct(
* @param string $base_filename A name for the resulting archive (without an extension).
* @param array $opt Map of archive options (see above for list).
* @param resource $output_stream Output stream for archive contents.
* @return ArchiveStream for either zip or tar
* @return Zip|Tar for either zip or tar
*/
public static function instance_by_useragent(
$base_filename = null,
array $opt = array(),
$output_stream = STDOUT
$output_stream = null
)
{
if ($output_stream === null) {
// Output stream for cli and web server
$output_stream = fopen('php://output', 'w');
}

$user_agent = (isset($_SERVER['HTTP_USER_AGENT']) ? strtolower($_SERVER['HTTP_USER_AGENT']) : '');

// detect windows and use zip
Expand Down

0 comments on commit c66e749

Please sign in to comment.