3 * An interface for seekable iterators which also allow to write to the file
6 * @author Roland Haeder <webmaster@ship-simu.org>
8 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
9 * @license GNU GPL 3.0 or any newer version
10 * @link http://www.ship-simu.org
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 interface SeekableWritableFileIterator extends SeekableIterator {
27 * Seeks to given position
29 * @param $seekPosition Seek position in file
30 * @return $status Status of this operation
32 function seek ($seekPosition);
37 * @return $size Size (in bytes) of file
42 * Reads given amount of bytes from file.
44 * @param $bytes Amount of bytes to read
45 * @return $data Data read from file
47 function read ($bytes);
50 * Analyzes entries in index file. This will count all found (and valid)
51 * entries, mark invalid as damaged and count gaps ("fragmentation"). If
52 * only gaps are found, the file is considered as "virgin" (no entries).
56 function analyzeFile ();
59 * Checks whether the file header is initialized
61 * @return $isInitialized Whether the file header is initialized
63 function isFileHeaderInitialized ();
66 * Creates the assigned file
70 function createFileHeader ();
73 * Pre-allocates file (if enabled) with some space for later faster write access.
75 * @param $type Type of the file
78 function preAllocateFile ($type);
81 * Initializes counter for valid entries, arrays for damaged entries and
82 * an array for gap seek positions. If you call this method on your own,
83 * please re-analyze the file structure. So you are better to call
84 * analyzeFile() instead of this method.
88 function initCountersGapsArray ();
91 * Getter for header size
93 * @return $totalEntries Size of file header
95 function getHeaderSize ();
98 * Setter for header size
100 * @param $headerSize Size of file header
103 function setHeaderSize ($headerSize);
106 * Getter for header array
108 * @return $totalEntries Size of file header
110 function getHeader ();
115 * @param $header Array for a file header
118 function setHeader (array $header);
121 * Updates seekPosition attribute from file to avoid to much access on file.
125 function updateSeekPosition ();
128 * Getter for total entries
130 * @return $totalEntries Total entries in this file
132 function getCounter ();
135 * "Getter" for file size
137 * @return $fileSize Size of currently loaded file
139 function getFileSize ();
142 * Writes data at given position
144 * @param $seekPosition Seek position
145 * @param $data Data to be written
146 * @param $flushHeader Whether to flush the header (default: flush)
149 function writeData ($seekPosition, $data, $flushHeader = TRUE);
152 * Getter for seek position
154 * @return $seekPosition Current seek position (stored here in object)
156 function getSeekPosition ();