3 namespace CoreFramework\Iterator\Filesystem;
6 * An interface for seekable iterators which also allow to write to the file
9 * @author Roland Haeder <webmaster@ship-simu.org>
11 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
12 * @license GNU GPL 3.0 or any newer version
13 * @link http://www.ship-simu.org
15 * This program is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 interface SeekableWritableFileIterator extends SeekableIterator {
30 * Seeks to given position
32 * @param $seekPosition Seek position in file
33 * @return $status Status of this operation
35 function seek ($seekPosition);
40 * @return $size Size (in bytes) of file
45 * Reads given amount of bytes from file.
47 * @param $bytes Amount of bytes to read
48 * @return $data Data read from file
50 function read ($bytes);
53 * Analyzes entries in index file. This will count all found (and valid)
54 * entries, mark invalid as damaged and count gaps ("fragmentation"). If
55 * only gaps are found, the file is considered as "virgin" (no entries).
59 function analyzeFile ();
62 * Checks whether the file header is initialized
64 * @return $isInitialized Whether the file header is initialized
66 function isFileHeaderInitialized ();
69 * Creates the assigned file
73 function createFileHeader ();
76 * Pre-allocates file (if enabled) with some space for later faster write access.
78 * @param $type Type of the file
81 function preAllocateFile ($type);
84 * Initializes counter for valid entries, arrays for damaged entries and
85 * an array for gap seek positions. If you call this method on your own,
86 * please re-analyze the file structure. So you are better to call
87 * analyzeFile() instead of this method.
91 function initCountersGapsArray ();
94 * Getter for header size
96 * @return $totalEntries Size of file header
98 function getHeaderSize ();
101 * Setter for header size
103 * @param $headerSize Size of file header
106 function setHeaderSize ($headerSize);
109 * Getter for header array
111 * @return $totalEntries Size of file header
113 function getHeader ();
118 * @param $header Array for a file header
121 function setHeader (array $header);
124 * Updates seekPosition attribute from file to avoid to much access on file.
128 function updateSeekPosition ();
131 * Getter for total entries
133 * @return $totalEntries Total entries in this file
135 function getCounter ();
138 * "Getter" for file size
140 * @return $fileSize Size of currently loaded file
142 function getFileSize ();
145 * Writes data at given position
147 * @param $seekPosition Seek position
148 * @param $data Data to be written
149 * @param $flushHeader Whether to flush the header (default: flush)
152 function writeData ($seekPosition, $data, $flushHeader = TRUE);
155 * Getter for seek position
157 * @return $seekPosition Current seek position (stored here in object)
159 function getSeekPosition ();
162 * Writes given value to the file and returns a hash and gap position for it
164 * @param $groupId Group identifier
165 * @param $value Value to be added to the stack
166 * @return $data Hash and gap position
168 function writeValueToFile ($groupId, $value);
171 * Writes given raw data to the file and returns a gap position and length
173 * @param $groupId Group identifier
174 * @param $hash Hash from encoded value
175 * @param $encoded Encoded value to be written to the file
176 * @return $data Gap position and length of the raw data
178 function writeDataToFreeGap ($groupId, $hash, $encoded);
181 * Searches for next suitable gap the given length of data can fit in
182 * including padding bytes.
184 * @param $length Length of raw data
185 * @return $seekPosition Found next gap's seek position
187 function searchNextGap ($length);