]> git.mxchange.org Git - core.git/blob - framework/main/interfaces/stacker/file/class_StackableFile.php
Continued:
[core.git] / framework / main / interfaces / stacker / file / class_StackableFile.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Stack\File;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Stack\Stackable;
7
8 /**
9  * A Stackable file interface
10  *
11  * @author              Roland Haeder <webmaster@shipsimu.org>
12  * @version             0.0.0
13  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
14  * @license             GNU GPL 3.0 or any newer version
15  * @link                http://www.shipsimu.org
16  *
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.
21  *
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.
26  *
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/>.
29  */
30 interface StackableFile extends Stackable {
31         /**
32          * Magic for this stack
33          */
34         const STACK_MAGIC = 'STACKv0.1';
35
36         /**
37          * Name of array index for gap position
38          */
39         const ARRAY_NAME_GAP_POSITION = 'gap';
40
41         /**
42          * Name of array index for hash
43          */
44         const ARRAY_NAME_HASH = 'hash';
45
46         /**
47          * Name of array index for length of raw data
48          */
49         const ARRAY_NAME_DATA_LENGTH = 'length';
50
51         /**
52          * Seeks to given position
53          *
54          * @param       $seekPosition   Seek position in file
55          * @return      $status                 Status of this operation
56          */
57         function seek (int $seekPosition);
58
59         /**
60          * Size of file stack
61          *
62          * @return      $size   Size (in bytes) of file
63          */
64         function size ();
65
66         /**
67          * Reads the stack's file header
68          *
69          * @return      void
70          * @todo        To hard assertions here, better rewrite them to exceptions
71          * @throws      UnexpectedValueException        If header is not proper length
72          * @throws      InvalidMagicException   If a bad magic was found
73          */
74         function readStackHeader ();
75
76         /**
77          * Flushes the file header
78          *
79          * @return      void
80          */
81         function flushFileHeader ();
82
83         /**
84          * Determines whether the EOF has been reached
85          *
86          * @return      $isEndOfFileReached             Whether the EOF has been reached
87          * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
88          */
89         function isEndOfFileReached ();
90
91         /**
92          * Calculates minimum length for one entry/block
93          *
94          * @return      $length         Minimum length for one entry/block
95          */
96         function calculateMinimumBlockLength ();
97
98         /**
99          * Initializes counter for valid entries, arrays for damaged entries and
100          * an array for gap seek positions. If you call this method on your own,
101          * please re-analyze the file structure. So you are better to call
102          * analyzeFileStructure() instead of this method.
103          *
104          * @return      void
105          * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
106          */
107         function initCountersGapsArray ();
108
109         /**
110          * Getter for header size
111          *
112          * @return      $totalEntries   Size of file header
113          * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
114          */
115         function getHeaderSize ();
116
117         /**
118          * Setter for header size
119          *
120          * @param       $headerSize             Size of file header
121          * @return      void
122          * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
123          */
124         function setHeaderSize (int $headerSize);
125
126         /**
127          * Getter for header array
128          *
129          * @return      $totalEntries   Size of file header
130          * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
131          */
132         function getHeader ();
133
134         /**
135          * Setter for header
136          *
137          * @param       $header         Array for a file header
138          * @return      void
139          * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
140          */
141         function setHeader (array $header);
142
143         /**
144          * Updates seekPosition attribute from file to avoid to much access on file.
145          *
146          * @return      void
147          * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
148          */
149         function updateSeekPosition ();
150
151         /**
152          * Getter for total entries
153          *
154          * @return      $totalEntries   Total entries in this file
155          * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
156          */
157         function getCounter ();
158
159         /**
160          * Writes data at given position
161          *
162          * @param       $seekPosition   Seek position
163          * @param       $data                   Data to be written
164          * @param       $flushHeader    Whether to flush the header (default: flush)
165          * @return      void
166          * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
167          */
168         function writeData (int $seekPosition, string $data, bool $flushHeader = true);
169
170         /**
171          * Writes at given position by seeking to it.
172          *
173          * @param       $seekPosition   Seek position in file
174          * @param       $dataStream             Data to be written
175          * @return      mixed                   Number of writes bytes or false on error
176          * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
177          */
178         function writeAtPosition (int $seekPosition, string $dataStream);
179
180         /**
181          * Writes given value to the file and returns a hash and gap position for it
182          *
183          * @param       $groupId        Group identifier
184          * @param       $value          Value to be added to the stack
185          * @return      $data           Hash and gap position
186          * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
187          */
188         function writeValueToFile (string $groupId, $value);
189
190         /**
191          * Searches for next suitable gap the given length of data can fit in
192          * including padding bytes.
193          *
194          * @param       $length                 Length of raw data
195          * @return      $seekPosition   Found next gap's seek position
196          * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
197          */
198         function searchNextGap (int $length);
199
200         /**
201          * "Getter" for file size
202          *
203          * @return      $fileSize       Size of currently loaded file
204          */
205         function getFileSize ();
206
207         /**
208          * Writes given raw data to the file and returns a gap position and length
209          *
210          * @param       $groupId        Group identifier
211          * @param       $hash           Hash from encoded value
212          * @param       $encoded        Encoded value to be written to the file
213          * @return      $data           Gap position and length of the raw data
214          */
215         function writeDataToFreeGap (string $groupId, string $hash, string $encoded);
216
217 }