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 Bzip_Filter extends Tar_Filter |
22: | { |
23: | public static function extract_files($archive, $destination, array $files = null, array $opts = null) |
24: | { |
25: | $ext = self::$fc->compression_extension($archive); |
26: | $tar = in_array($ext, array('.tbz', '.tbz2', '.tar.bz', '.tar.bz2')); |
27: | $cmd = 'bzip2 ' . (!$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: | return false; |
40: | } |
41: | |
42: | self::$fc->file_delete($archive); |
43: | |
44: | return true; |
45: | } |
46: | |
47: | |
48: | public static function list_files($archive, array $opts = null) |
49: | { |
50: | $ext = self::$fc->compression_extension($archive); |
51: | $tar = in_array($ext, array('.tbz', '.tbz2', '.tar.bz', '.tar.bz2')); |
52: | if ($tar) { |
53: | $cmd = 'bzip2 -d -c %s'; |
54: | $proc = parent::exec( |
55: | $cmd, |
56: | $archive, |
57: | array(0), |
58: | array('run' => 0) |
59: | ); |
60: | |
61: | return self::list_files_pipe($archive, |
62: | $opts |
63: | ); |
64: | } |
65: | |
66: | $files = array(); |
67: | $files[] = array( |
68: | 'file_name' => basename($archive, self::$fc->compression_extension($archive)), |
69: | 'file_type' => 'file', |
70: | 'can_read' => true, |
71: | 'can_write' => true, |
72: | 'can_execute' => true, |
73: | 'size' => strlen(file_get_contents('compress.bzip2://' . $archive)), |
74: | 'packed_size' => filesize($archive), |
75: | 'crc' => '?', |
76: | 'link' => 0, |
77: | 'date' => filectime($archive) |
78: | ); |
79: | |
80: | return $files; |
81: | |
82: | } |
83: | |
84: | } |
85: | |
86: | ?> |
87: | |