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 <<<<<<< HEAD:framework/main/interfaces/iterator/file/class_SeekableWritableFileIterator.php
15 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
17 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
18 >>>>>>> Some updates::inc/main/interfaces/iterator/class_SeekableWritableFileIterator.php
19 * @license GNU GPL 3.0 or any newer version
20 * @link http://www.ship-simu.org
22 * This program is free software: you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation, either version 3 of the License, or
25 * (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program. If not, see <http://www.gnu.org/licenses/>.
35 interface SeekableWritableFileIterator extends SeekableIterator {
37 * Seeks to given position
39 * @param $seekPosition Seek position in file
40 * @return $status Status of this operation
42 function seek ($seekPosition);
47 * @return $size Size (in bytes) of file
52 * Reads given amount of bytes from file.
54 * @param $bytes Amount of bytes to read
55 * @return $data Data read from file
57 function read ($bytes);
60 * Analyzes entries in index file. This will count all found (and valid)
61 * entries, mark invalid as damaged and count gaps ("fragmentation"). If
62 * only gaps are found, the file is considered as "virgin" (no entries).
66 function analyzeFile ();
69 * Checks whether the file header is initialized
71 * @return $isInitialized Whether the file header is initialized
73 function isFileHeaderInitialized ();
76 * Creates the assigned file
80 function createFileHeader ();
83 * Pre-allocates file (if enabled) with some space for later faster write access.
85 * @param $type Type of the file
88 function preAllocateFile ($type);
91 * Initializes counter for valid entries, arrays for damaged entries and
92 * an array for gap seek positions. If you call this method on your own,
93 * please re-analyze the file structure. So you are better to call
94 * analyzeFile() instead of this method.
98 function initCountersGapsArray ();
101 * Getter for header size
103 * @return $totalEntries Size of file header
105 function getHeaderSize ();
108 * Setter for header size
110 * @param $headerSize Size of file header
113 function setHeaderSize ($headerSize);
116 * Getter for header array
118 * @return $totalEntries Size of file header
120 function getHeader ();
125 * @param $header Array for a file header
128 function setHeader (array $header);
131 * Updates seekPosition attribute from file to avoid to much access on file.
135 function updateSeekPosition ();
138 * Getter for total entries
140 * @return $totalEntries Total entries in this file
142 function getCounter ();
145 * "Getter" for file size
147 * @return $fileSize Size of currently loaded file
149 function getFileSize ();
152 * Writes data at given position
154 * @param $seekPosition Seek position
155 * @param $data Data to be written
156 * @param $flushHeader Whether to flush the header (default: flush)
159 function writeData ($seekPosition, $data, $flushHeader = true);
162 * Getter for seek position
164 * @return $seekPosition Current seek position (stored here in object)
166 function getSeekPosition ();
169 * Writes given value to the file and returns a hash and gap position for it
171 * @param $groupId Group identifier
172 * @param $value Value to be added to the stack
173 * @return $data Hash and gap position
175 function writeValueToFile ($groupId, $value);
178 * Writes given raw data to the file and returns a gap position and length
180 * @param $groupId Group identifier
181 * @param $hash Hash from encoded value
182 * @param $encoded Encoded value to be written to the file
183 * @return $data Gap position and length of the raw data
185 function writeDataToFreeGap ($groupId, $hash, $encoded);
188 * Searches for next suitable gap the given length of data can fit in
189 * including padding bytes.
191 * @param $length Length of raw data
192 * @return $seekPosition Found next gap's seek position
194 function searchNextGap ($length);