]> git.mxchange.org Git - core.git/blob - inc/main/interfaces/iterator/class_SeekableWritableFileIterator.php
205fa99512de6d5692ce42bfc0afad80bec02595
[core.git] / inc / main / interfaces / iterator / class_SeekableWritableFileIterator.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Iterator\Filesystem;
4
5 /**
6  * An interface for seekable iterators which also allow to write to the file
7  * in different ways.
8  *
9  * @author              Roland Haeder <webmaster@ship-simu.org>
10  * @version             0.0.0
11  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
12  * @license             GNU GPL 3.0 or any newer version
13  * @link                http://www.ship-simu.org
14  *
15  * This program is free software: you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation, either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program. If not, see <http://www.gnu.org/licenses/>.
27  */
28 interface SeekableWritableFileIterator extends SeekableIterator {
29         /**
30          * Seeks to given position
31          *
32          * @param       $seekPosition   Seek position in file
33          * @return      $status                 Status of this operation
34          */
35         function seek ($seekPosition);
36
37         /**
38          * Size of file stack
39          *
40          * @return      $size   Size (in bytes) of file
41          */
42         function size ();
43
44         /**
45          * Reads given amount of bytes from file.
46          *
47          * @param       $bytes  Amount of bytes to read
48          * @return      $data   Data read from file
49          */
50         function read ($bytes);
51
52         /**
53          * Analyzes entries in index file. This will count all found (and valid)
54          * entries, mark invalid as damaged and count gaps ("fragmentation"). If
55          * only gaps are found, the file is considered as "virgin" (no entries).
56          *
57          * @return      void
58          */
59         function analyzeFile ();
60
61         /**
62          * Checks whether the file header is initialized
63          *
64          * @return      $isInitialized  Whether the file header is initialized
65          */
66         function isFileHeaderInitialized ();
67
68         /**
69          * Creates the assigned file
70          *
71          * @return      void
72          */
73         function createFileHeader ();
74
75         /**
76          * Pre-allocates file (if enabled) with some space for later faster write access.
77          *
78          * @param       $type   Type of the file
79          * @return      void
80          */
81         function preAllocateFile ($type);
82
83         /**
84          * Initializes counter for valid entries, arrays for damaged entries and
85          * an array for gap seek positions. If you call this method on your own,
86          * please re-analyze the file structure. So you are better to call
87          * analyzeFile() instead of this method.
88          *
89          * @return      void
90          */
91         function initCountersGapsArray ();
92
93         /**
94          * Getter for header size
95          *
96          * @return      $totalEntries   Size of file header
97          */
98         function getHeaderSize ();
99
100         /**
101          * Setter for header size
102          *
103          * @param       $headerSize             Size of file header
104          * @return      void
105          */
106         function setHeaderSize ($headerSize);
107
108         /**
109          * Getter for header array
110          *
111          * @return      $totalEntries   Size of file header
112          */
113         function getHeader ();
114
115         /**
116          * Setter for header
117          *
118          * @param       $header         Array for a file header
119          * @return      void
120          */
121         function setHeader (array $header);
122
123         /**
124          * Updates seekPosition attribute from file to avoid to much access on file.
125          *
126          * @return      void
127          */
128         function updateSeekPosition ();
129
130         /**
131          * Getter for total entries
132          *
133          * @return      $totalEntries   Total entries in this file
134          */
135         function getCounter ();
136
137         /**
138          * "Getter" for file size
139          *
140          * @return      $fileSize       Size of currently loaded file
141          */
142         function getFileSize ();
143
144         /**
145          * Writes data at given position
146          *
147          * @param       $seekPosition   Seek position
148          * @param       $data                   Data to be written
149          * @param       $flushHeader    Whether to flush the header (default: flush)
150          * @return      void
151          */
152         function writeData ($seekPosition, $data, $flushHeader = TRUE);
153
154         /**
155          * Getter for seek position
156          *
157          * @return      $seekPosition   Current seek position (stored here in object)
158          */
159         function getSeekPosition ();
160
161         /**
162          * Writes given value to the file and returns a hash and gap position for it
163          *
164          * @param       $groupId        Group identifier
165          * @param       $value          Value to be added to the stack
166          * @return      $data           Hash and gap position
167          */
168         function writeValueToFile ($groupId, $value);
169
170         /**
171          * Writes given raw data to the file and returns a gap position and length
172          *
173          * @param       $groupId        Group identifier
174          * @param       $hash           Hash from encoded value
175          * @param       $encoded        Encoded value to be written to the file
176          * @return      $data           Gap position and length of the raw data
177          */
178         function writeDataToFreeGap ($groupId, $hash, $encoded);
179
180         /**
181          * Searches for next suitable gap the given length of data can fit in
182          * including padding bytes.
183          *
184          * @param       $length                 Length of raw data
185          * @return      $seekPosition   Found next gap's seek position
186          */
187         function searchNextGap ($length);
188
189 }