]> git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/libraries/MOBIClass/Record.php
phpepub via composer
[github/wallabag/wallabag.git] / inc / 3rdparty / libraries / MOBIClass / Record.php
1 <?php
2 /**
3 * A Record of a PDB file
4 *
5 * @author Sander
6 */
7 class Record extends FileObject {
8 /**
9 * Data in the record
10 * @var string
11 */
12 private $data;
13 /**
14 * Length of the record
15 * @var int
16 */
17 private $length;
18
19 /**
20 * Create a record
21 * @param string $data Data contained in the record
22 * @param int $length Length of the record (if set to -1,
23 * the length of $data will be taken)
24 */
25 public function __construct($data = "", $length = -1){
26 $this->data = $data;
27 if($length >= 0){
28 $this->length = $length;
29 }else{
30 $this->length = strlen($data);
31 }
32 }
33
34 public function compress($compression_method){
35 switch($compression_method){
36 case NO_COMPRESSION:
37 //Finished!
38 break;
39 case PALMDOC_COMPRESSION:
40 throw new Exception("Not implemented yet");
41 break;
42 case HUFF:
43 throw new Exception("Not implemented yet");
44 break;
45 default:
46 throw new Exception("Invalid argument");
47 }
48 }
49
50 public function getByteLength(){
51 return $this->getLength();
52 }
53
54 /**
55 * Get the length of the record
56 * @return int Length of the data
57 */
58 public function getLength(){
59 return $this->length;
60 }
61
62 /**
63 * Get the data contained in the record
64 * @return string Data contained in the record
65 */
66 public function get(){
67 return $this->data;
68 }
69
70 /**
71 * Set the data contained in the record
72 * @param string $value Data contained in the record
73 */
74 public function set($value){
75 $this->data = $value;
76 }
77
78 public function serialize(){
79 return $this->data;
80 }
81 public function unserialize($data){
82 __construct($data);
83 }
84
85 public function __toString() {
86 $toShow = $this->data;
87 if(strlen($this->data) > 103){
88 $toShow = substr($this->data, 0, 100)."...";
89 }
90 $out = "Record: {\n";
91 $out .= "\t".htmlspecialchars($toShow)."\n";
92 $out .= "}";
93 return $out;
94 }
95 }
96 ?>