Rework the way IDF's SCM interface provides downloadable snapshots.
Instead of returning a command which gets executed and which should pass through / stream its output data to the client, we're just returning an instance of Pluf_HTTP_Response. This is needed, because some SCMs, most noticable monotone, have no locally executable command to provide a snapshot archive (and probably never will for our kind of setup). We therefor added a little BSD-licensed class "ZipArchive" which allows the creation of pkzip-compatible archives on the fly by letting it eat the file contents directly feed from the (remote) stdio instance. Download performance is ok and lies between 15K/s and 110K/s, but at least we do no longer block the browser while we pre-generate the zip file server-side. Thanks to Patrick Georgi for all his work!
This commit is contained in:
52
contrib/zipstream-php-0.2.2/test/index.php
Normal file
52
contrib/zipstream-php-0.2.2/test/index.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
# load zipstream class
|
||||
require '../zipstream.php';
|
||||
|
||||
# get path to current file
|
||||
$pwd = dirname(__FILE__);
|
||||
|
||||
# add some random files
|
||||
$files = array(
|
||||
'../extras/zip-appnote-6.3.1-20070411.txt',
|
||||
'../zipstream.php',
|
||||
);
|
||||
|
||||
# create new zip stream object
|
||||
$zip = new ZipStream('test.zip', array(
|
||||
'comment' => 'this is a zip file comment. hello?'
|
||||
));
|
||||
|
||||
# common file options
|
||||
$file_opt = array(
|
||||
# file creation time (2 hours ago)
|
||||
'time' => time() - 2 * 3600,
|
||||
|
||||
# file comment
|
||||
'comment' => 'this is a file comment. hi!',
|
||||
);
|
||||
|
||||
# add files under folder 'asdf'
|
||||
foreach ($files as $file) {
|
||||
# build absolute path and get file data
|
||||
$path = ($file[0] == '/') ? $file : "$pwd/$file";
|
||||
$data = file_get_contents($path);
|
||||
|
||||
# add file to archive
|
||||
$zip->add_file('asdf/' . basename($file), $data, $file_opt);
|
||||
}
|
||||
|
||||
# add same files again wihtout a folder
|
||||
foreach ($files as $file) {
|
||||
# build absolute path and get file data
|
||||
$path = ($file[0] == '/') ? $file : "$pwd/$file";
|
||||
$data = file_get_contents($path);
|
||||
|
||||
# add file to archive
|
||||
$zip->add_file(basename($file), $data, $file_opt);
|
||||
}
|
||||
|
||||
# finish archive
|
||||
$zip->finish();
|
||||
|
||||
?>
|
Reference in New Issue
Block a user