@@ -50,12 +50,20 @@ class Archive
50
50
/**
51
51
* Create a new ArchiveStream object.
52
52
*
53
- * @param string $name The name of the resulting archive (optional).
54
- * @param array $opt Hash of archive options (see archive options in readme).
55
- * @param string $base_path An optional base path for files to be named under.
53
+ * @param string $name The name of the resulting archive (optional).
54
+ * @param array $opt Hash of archive options (see archive options in readme).
55
+ * @param string $base_path An optional base path for files to be named under.
56
+ * @param resource $output_stream Output stream for archive contents.
56
57
*/
57
- public function __construct ($ name = null , array $ opt = array (), $ base_path = null )
58
+ public function __construct (
59
+ $ name = null ,
60
+ array $ opt = array (),
61
+ $ base_path = null ,
62
+ $ output_stream = STDOUT
63
+ )
58
64
{
65
+ $ this ->output_stream = $ output_stream ;
66
+
59
67
// save options
60
68
$ this ->opt = $ opt ;
61
69
@@ -90,25 +98,30 @@ public function __construct($name = null, array $opt = array(), $base_path = nul
90
98
/**
91
99
* Create instance based on useragent string
92
100
*
93
- * @param string $base_filename A name for the resulting archive (without an extension).
94
- * @param array $opt Map of archive options (see above for list).
101
+ * @param string $base_filename A name for the resulting archive (without an extension).
102
+ * @param array $opt Map of archive options (see above for list).
103
+ * @param resource $output_stream Output stream for archive contents.
95
104
* @return ArchiveStream for either zip or tar
96
105
*/
97
- public static function instance_by_useragent ($ base_filename = null , array $ opt = array ())
106
+ public static function instance_by_useragent (
107
+ $ base_filename = null ,
108
+ array $ opt = array (),
109
+ $ output_stream = STDOUT
110
+ )
98
111
{
99
112
$ user_agent = (isset ($ _SERVER ['HTTP_USER_AGENT ' ]) ? strtolower ($ _SERVER ['HTTP_USER_AGENT ' ]) : '' );
100
113
101
114
// detect windows and use zip
102
115
if (strpos ($ user_agent , 'windows ' ) !== false )
103
116
{
104
117
$ filename = (($ base_filename === null ) ? null : $ base_filename . '.zip ' );
105
- return new Zip ($ filename , $ opt , $ base_filename );
118
+ return new Zip ($ filename , $ opt , $ base_filename, $ output_stream );
106
119
}
107
120
// fallback to tar
108
121
else
109
122
{
110
123
$ filename = (($ base_filename === null ) ? null : $ base_filename . '.tar ' );
111
- return new Tar ($ filename , $ opt , $ base_filename );
124
+ return new Tar ($ filename , $ opt , $ base_filename, $ output_stream );
112
125
}
113
126
}
114
127
@@ -327,7 +340,7 @@ protected function send($data)
327
340
328
341
$ this ->need_headers = false ;
329
342
330
- echo $ data ;
343
+ fwrite ( $ this -> output_stream , $ data) ;
331
344
}
332
345
333
346
/**
0 commit comments