-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPBOExtractor.php
More file actions
84 lines (68 loc) · 2.54 KB
/
PBOExtractor.php
File metadata and controls
84 lines (68 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* Created by Ascendro S.R.L.
* User: Michael
* Date: 19.06.13
* Time: 08:44
*/
define('PBOEXTRACTOR_BASE', dirname(__FILE__) . '/');
require_once PBOEXTRACTOR_BASE . 'PBODataTypes.php';
require_once PBOEXTRACTOR_BASE . 'RAPConverter.php';
class PBOExtractor {
public static $lastError = array('code' => 0, 'message' => "");
protected function __construct()
{
}
public static function getLastErrorCode() {
return PBOExtractor::$lastError['code'];
}
public static function getLastErrorMessage() {
return PBOExtractor::$lastError['message'];
}
public static function lastRunSuccesfull() {
return PBOExtractor::$lastError['code'] == 0;
}
public static function extract($fileToExtract,$pboFile) {
$pboStream = fopen($pboFile, 'r');
$result = PBOExtractor::extractFromStream($fileToExtract,$pboStream);
fclose($pboStream);
return $result;
}
public static function extractFromStream($fileToExtract,$pboStream) {
PBOExtractor::$lastError = array('code' => 0, 'message' => "");
$i = 0;
$headers = array();
$searchedHeader = array();
//Consume all the headers
do {
$header = PBOHeaderEntry::createByConsumeStream($pboStream);
$headers[$i] = $header;
if ($header->filename == $fileToExtract) {
$searchedHeader = $header;
}
$i++;
} while (!feof($pboStream) && !$header->isEndOfHeader());
if (empty($searchedHeader)) {
PBOExtractor::$lastError = array('code' => 1, 'message' => "Could not find ".$fileToExtract);
return false;
}
$file = null;
foreach ($headers as $header) {
if ($header == $searchedHeader) {
$file = PBOFileEntry::createByConsumeStream($pboStream,$header);
break;
} else {
PBOFileEntry::consumeFile($pboStream,$header);
}
}
if ($file->isCompressed) {
PBOExtractor::$lastError = array('code' => 2, 'message' => "File ".$fileToExtract." is compressed. Compressed files are not supported yet.");
return $file;
}
if ($file->isRapified) {
PBOExtractor::$lastError = array('code' => 3, 'message' => "File ".$fileToExtract." is raPified. raPified files are not supported yet.");
return $file;
}
return $file;
}
}