aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/3rdparty/libraries/MOBIClass/Record.php
blob: 3cb395823e7837bbabaec7bd72b31b496306769d (plain) (blame)
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
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
 * A Record of a PDB file
 *
 * @author Sander
 */
class Record extends FileObject {
	/**
	 * Data in the record
	 * @var string
	 */
	private $data;
	/**
	 * Length of the record
	 * @var int
	 */
	private $length;

	/**
	 * Create a record
	 * @param string $data Data contained in the record
	 * @param int $length Length of the record (if set to -1,
	 * the length of $data will be taken)
	 */
	public function __construct($data = "", $length = -1){
		$this->data = $data;
		if($length >= 0){
			$this->length = $length;
		}else{
			$this->length = strlen($data);
		}
	}

	public function compress($compression_method){
		switch($compression_method){
			case NO_COMPRESSION:
				//Finished!
				break;
			case PALMDOC_COMPRESSION:
				throw new Exception("Not implemented yet");
				break;
			case HUFF:
				throw new Exception("Not implemented yet");
				break;
			default:
				throw new Exception("Invalid argument");
		}
	}

	public function getByteLength(){
		return $this->getLength();
	}

	/**
	 * Get the length of the record
	 * @return int Length of the data
	 */
	public function getLength(){
		return $this->length;
	}

	/**
	 * Get the data contained in the record
	 * @return string Data contained in the record
	 */
	public function get(){
		return $this->data;
	}

	/**
	 * Set the data contained in the record
	 * @param string $value Data contained in the record
	 */
	public function set($value){
		$this->data = $value;
	}
	
    public function serialize(){
        return $this->data;
    }
    public function unserialize($data){
        __construct($data);
    }
	
	public function __toString() {
		$toShow = $this->data;
		if(strlen($this->data) > 103){
			$toShow = substr($this->data, 0, 100)."...";
		}
		$out = "Record: {\n";
		$out .= "\t".htmlspecialchars($toShow)."\n";
		$out .= "}";
		return $out;
	}
}
?>