]> git.mxchange.org Git - core.git/blob - framework/main/interfaces/filesystem/binary/class_BinaryFile.php
Continued:
[core.git] / framework / main / interfaces / filesystem / binary / class_BinaryFile.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Filesystem\File;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Filesystem\Filesystem;
7
8 /**
9  * A virtual file system interface
10  *
11  * @author              Roland Haeder <webmaster@ship-simu.org>
12  * @version             0.0.0
13  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2021 Core Developer Team
14  * @license             GNU GPL 3.0 or any newer version
15  * @link                http://www.ship-simu.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 BinaryFile extends Filesystem {
31         /**
32          * Reads the file header
33          *
34          * @return      void
35          */
36         function readFileHeader ();
37
38         /**
39          * Flushes the file header
40          *
41          * @return      void
42          */
43         function flushFileHeader ();
44
45         /**
46          * Determines whether the EOF has been reached
47          *
48          * @return      $isEndOfFileReached             Whether the EOF has been reached
49          */
50         function isEndOfFileReached ();
51
52         /**
53          * Getter for header size
54          *
55          * @return      $totalEntries   Size of file header
56          */
57         function getHeaderSize ();
58
59         /**
60          * Setter for header size
61          *
62          * @param       $headerSize             Size of file header
63          * @return      void
64          */
65         function setHeaderSize (int $headerSize);
66
67         /**
68          * Getter for header array
69          *
70          * @return      $totalEntries   Size of file header
71          */
72         function getHeader ();
73
74         /**
75          * Setter for header
76          *
77          * @param       $header         Array for a file header
78          * @return      void
79          */
80         function setHeader (array $header);
81
82         /**
83          * Initializes counter for valid entries, arrays for damaged entries and
84          * an array for gap seek positions. If you call this method on your own,
85          * please re-analyze the file structure. So you are better to call
86          * analyzeFileStructure() instead of this method.
87          *
88          * @return      void
89          */
90         function initCountersGapsArray ();
91
92         /**
93          * Updates seekPosition attribute from file to avoid to much access on file.
94          *
95          * @return      void
96          */
97         function updateSeekPosition ();
98
99         /**
100          * Getter for total entries
101          *
102          * @return      $totalEntries   Total entries in this file
103          */
104         function getCounter ();
105
106         /**
107          * "Getter" for file size
108          *
109          * @return      $fileSize       Size of currently loaded file
110          */
111         function getFileSize ();
112
113         /**
114          * Checks whether the abstracted file only contains gaps by counting all
115          * gaps' bytes together and compare it to total length.
116          *
117          * @return      $isGapsOnly             Whether the abstracted file only contains gaps
118          */
119         function isFileGapsOnly();
120
121         /**
122          * Searches for next suitable gap the given length of data can fit in
123          * including padding bytes.
124          *
125          * @param       $length                 Length of raw data
126          * @return      $seekPosition   Found next gap's seek position
127          */
128         function searchNextGap (int $length);
129
130         /**
131          * Writes given value to the file and returns a hash and gap position for it
132          *
133          * @param       $groupId        Group identifier
134          * @param       $value          Value to be added to the stack
135          * @return      $data           Hash and gap position
136          */
137         function writeValueToFile (string $groupId, string $rawData);
138
139         /**
140          * Writes given raw data to the file and returns a gap position and length
141          *
142          * @param       $groupId        Group identifier
143          * @param       $hash           Hash from encoded value
144          * @param       $encoded        Encoded value to be written to the file
145          * @return      $data           Gap position and length of the raw data
146          */
147         function writeDataToFreeGap (string $groupId, string $hash, string $encoded);
148
149         /**
150          * Writes data at given position
151          *
152          * @param       $seekPosition   Seek position
153          * @param       $data                   Data to be written
154          * @param       $flushHeader    Whether to flush the header (default: flush)
155          * @return      void
156          */
157         function writeData (int $seekPosition, string $data, bool $flushHeader = true);
158
159         /**
160          * Writes at given position by seeking to it.
161          *
162          * @param       $seekPosition   Seek position in file
163          * @param       $dataStream             Data to be written
164          * @return      mixed                   Number of writes bytes or false on error
165          * @throws      InvalidArgumentException        If a parameter is not valid
166          */
167         function writeAtPosition (int $seekPosition, string $dataStream);
168
169 }