1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | include_once('tar.php'); |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | class Gzip_Filter extends Tar_Filter |
22: | { |
23: | public static function extract_files($archive, $destination, array $files = null, array $opts = null) |
24: | { |
25: | $tar = (substr($archive, -4) == '.tgz' || |
26: | substr($archive, -7) == '.tar.gz'); |
27: | $cmd = 'gzip ' . (!$tar ? '-d' : '-d -c') . ' %s'; |
28: | $proc = parent::exec( |
29: | $cmd, |
30: | $archive, |
31: | array(0), |
32: | array('run' => !$tar) |
33: | ); |
34: | |
35: | if ($tar) { |
36: | return self::extract_files_pipe($archive, $destination, $files, $opts); |
37: | } |
38: | if ($proc['success']) { |
39: | self::$fc->file_delete($archive); |
40: | } |
41: | |
42: | return $proc; |
43: | } |
44: | |
45: | public static function list_files($archive, array $opts = null) |
46: | { |
47: | $tar = substr($archive, -4) == '.tgz' || |
48: | substr($archive, -7) == '.tar.gz'; |
49: | $cmd = 'gzip ' . (!$tar ? '-v -l' : '-d -c') . ' %s'; |
50: | $proc = parent::exec( |
51: | $cmd, |
52: | $archive, |
53: | array(0), |
54: | array('run' => !$tar) |
55: | ); |
56: | if ($tar) { |
57: | return self::list_files_pipe($archive, $opts); |
58: | } |
59: | |
60: | |
61: | $files = array(); |
62: | foreach (explode("\n", $proc['output']) as $line) { |
63: | if (!preg_match(Regex::FILE_HDR_GZIP, $line, $entry)) { |
64: | continue; |
65: | } |
66: | |
67: | $files[] = array( |
68: | 'file_name' => basename($entry['name']), |
69: | 'file_type' => 'file', |
70: | 'can_read' => true, |
71: | 'can_write' => true, |
72: | 'can_execute' => true, |
73: | 'size' => $entry['size'], |
74: | 'packed_size' => $entry['csize'], |
75: | 'crc' => $entry['crc'], |
76: | 'link' => 0, |
77: | 'date' => strtotime($entry['ts']) |
78: | ); |
79: | } |
80: | |
81: | return $files; |
82: | |
83: | } |
84: | |
85: | } |
86: | |
87: | ?> |
88: | |