removing debuggin entry. /me bad.
[squirrelmail.git] / class / l10n / streams.class.php
1 <?php
2 /**
3 * Copyright (c) 2003 Danilo Segan <danilo@kvota.net>.
4 *
5 * This file is part of PHP-gettext.
6 *
7 * PHP-gettext is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * PHP-gettext is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with PHP-gettext; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * @package squirrelmail
22 * @subpackage i18n
23 */
24
25 /**
26 * Class that is used to read .mo files.
27 * @package squirrelmail
28 * @subpackage i18n
29 */
30 class FileReader {
31 /**
32 * Current position in file
33 * @var integer
34 */
35 var $_pos;
36 /**
37 * File descriptor
38 * @var resource
39 */
40 var $_fd;
41 /**
42 * File size
43 * @var integer
44 */
45 var $_length;
46 /**
47 * contains error codes
48 *
49 * 2 = File doesn't exist
50 * 3 = Can't read file
51 * @var integer
52 */
53 var $error=0;
54
55 /**
56 * reads translation file and fills translation input object properties
57 * @param string $filename path to file
58 * @return boolean false there is a problem with $filename
59 */
60 function FileReader($filename) {
61 if (file_exists($filename)) {
62
63 $this->_length=filesize($filename);
64 $this->_pos = 0;
65 $this->_fd = fopen($filename,'rb');
66 if (!$this->_fd) {
67 $this->error = 3; // Cannot read file, probably permissions
68 return false;
69 }
70 } else {
71 $this->error = 2; // File doesn't exist
72 return false;
73 }
74 }
75
76 /**
77 * reads data from current position
78 * @param integer $bytes number of bytes to read
79 * @return string read data
80 */
81 function read($bytes) {
82 fseek($this->_fd, $this->_pos);
83 $data = fread($this->_fd, $bytes);
84 $this->_pos = ftell($this->_fd);
85
86 return $data;
87 }
88
89 /**
90 * Moves to defined position in a file
91 * @param integer $pos position
92 * @return integer current position
93 */
94 function seekto($pos) {
95 fseek($this->_fd, $pos);
96 $this->_pos = ftell($this->_fd);
97 return $this->_pos;
98 }
99
100 /**
101 * return current position
102 * @return integer current position
103 */
104 function currentpos() {
105 return $this->_pos;
106 }
107
108 /**
109 * return file length
110 * @return integer file length
111 */
112 function length() {
113 return $this->_length;
114 }
115
116 /**
117 * close translation file
118 */
119 function close() {
120 fclose($this->_fd);
121 }
122 }
123 ?>