3 namespace Org\Mxchange\CoreFramework\Iterator\Filesystem;
9 * An interface for seekable iterators which also allow to write to the file
12 * @author Roland Haeder <webmaster@ship-simu.org>
14 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
15 * @license GNU GPL 3.0 or any newer version
16 * @link http://www.ship-simu.org
18 * This program is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 interface SeekableWritableFileIterator extends SeekableIterator {
33 * Seeks to given position
35 * @param $seekPosition Seek position in file
36 * @return $status Status of this operation
38 function seek ($seekPosition);
43 * @return $size Size (in bytes) of file
48 * Reads given amount of bytes from file.
50 * @param $bytes Amount of bytes to read
51 * @return $data Data read from file
53 function read ($bytes);
56 * Analyzes entries in index file. This will count all found (and valid)
57 * entries, mark invalid as damaged and count gaps ("fragmentation"). If
58 * only gaps are found, the file is considered as "virgin" (no entries).
62 function analyzeFile ();
65 * Checks whether the file header is initialized
67 * @return $isInitialized Whether the file header is initialized
69 function isFileHeaderInitialized ();
72 * Creates the assigned file
76 function createFileHeader ();
79 * Pre-allocates file (if enabled) with some space for later faster write access.
81 * @param $type Type of the file
84 function preAllocateFile ($type);
87 * Initializes counter for valid entries, arrays for damaged entries and
88 * an array for gap seek positions. If you call this method on your own,
89 * please re-analyze the file structure. So you are better to call
90 * analyzeFile() instead of this method.
94 function initCountersGapsArray ();
97 * Getter for header size
99 * @return $totalEntries Size of file header
101 function getHeaderSize ();
104 * Setter for header size
106 * @param $headerSize Size of file header
109 function setHeaderSize ($headerSize);
112 * Getter for header array
114 * @return $totalEntries Size of file header
116 function getHeader ();
121 * @param $header Array for a file header
124 function setHeader (array $header);
127 * Updates seekPosition attribute from file to avoid to much access on file.
131 function updateSeekPosition ();
134 * Getter for total entries
136 * @return $totalEntries Total entries in this file
138 function getCounter ();
141 * "Getter" for file size
143 * @return $fileSize Size of currently loaded file
145 function getFileSize ();
148 * Writes data at given position
150 * @param $seekPosition Seek position
151 * @param $data Data to be written
152 * @param $flushHeader Whether to flush the header (default: flush)
155 function writeData ($seekPosition, $data, $flushHeader = true);
158 * Getter for seek position
160 * @return $seekPosition Current seek position (stored here in object)
162 function getSeekPosition ();
165 * Writes given value to the file and returns a hash and gap position for it
167 * @param $groupId Group identifier
168 * @param $value Value to be added to the stack
169 * @return $data Hash and gap position
171 function writeValueToFile ($groupId, $value);
174 * Writes given raw data to the file and returns a gap position and length
176 * @param $groupId Group identifier
177 * @param $hash Hash from encoded value
178 * @param $encoded Encoded value to be written to the file
179 * @return $data Gap position and length of the raw data
181 function writeDataToFreeGap ($groupId, $hash, $encoded);
184 * Searches for next suitable gap the given length of data can fit in
185 * including padding bytes.
187 * @param $length Length of raw data
188 * @return $seekPosition Found next gap's seek position
190 function searchNextGap ($length);