3 namespace Org\Mxchange\CoreFramework\Filesystem;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
11 * @author Roland Haeder <webmaster@ship-simu.org>
13 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
14 * @license GNU GPL 3.0 or any newer version
15 * @link http://www.ship-simu.org
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 interface Block extends FrameworkInterface {
32 * Reads the file header
36 function readFileHeader ();
39 * Flushes the file header
43 function flushFileHeader ();
46 * Determines whether the EOF has been reached
48 * @return $isEndOfFileReached Whether the EOF has been reached
50 function isEndOfFileReached ();
53 * Initializes counter for valid entries, arrays for damaged entries and
54 * an array for gap seek positions. If you call this method on your own,
55 * please re-analyze the file structure. So you are better to call
56 * analyzeFile() instead of this method.
60 function initCountersGapsArray ();
63 * Getter for header size
65 * @return $totalEntries Size of file header
67 function getHeaderSize ();
70 * Setter for header size
72 * @param $headerSize Size of file header
75 function setHeaderSize (int $headerSize);
78 * Getter for header array
80 * @return $totalEntries Size of file header
82 function getHeader ();
87 * @param $header Array for a file header
90 function setHeader (array $header);
93 * Updates seekPosition attribute from file to avoid to much access on file.
97 function updateSeekPosition ();
100 * Getter for total entries
102 * @return $totalEntries Total entries in this file
104 function getCounter ();
107 * "Getter" for file size
109 * @return $fileSize Size of currently loaded file
111 function getFileSize ();
114 * Writes given value to the file and returns a hash and gap position for it
116 * @param $groupId Group identifier
117 * @param $value Value to be added to the stack
118 * @return $data Hash and gap position
120 function writeValueToFile ($groupId, $rawData);
123 * Writes given raw data to the file and returns a gap position and length
125 * @param $groupId Group identifier
126 * @param $hash Hash from encoded value
127 * @param $encoded Encoded value to be written to the file
128 * @return $data Gap position and length of the raw data
130 function writeDataToFreeGap ($groupId, string $hash, $encoded);
133 * Writes data at given position
135 * @param $seekPosition Seek position
136 * @param $data Data to be written
137 * @param $flushHeader Whether to flush the header (default: flush)
140 function writeData ($seekPosition, $data, bool $flushHeader = true);
143 * Searches for next suitable gap the given length of data can fit in
144 * including padding bytes.
146 * @param $length Length of raw data
147 * @return $seekPosition Found next gap's seek position
149 function searchNextGap (int $length);