1 | <?php |
||
14 | class GzDumpReader implements SeekableDumpReader { |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | private $dumpFile; |
||
20 | |||
21 | /** |
||
22 | * @var int |
||
23 | */ |
||
24 | private $initialPosition; |
||
25 | |||
26 | /** |
||
27 | * @var resource|null |
||
28 | */ |
||
29 | private $handle = null; |
||
30 | |||
31 | /** |
||
32 | * @param string $dumpFilePath |
||
33 | * @param int $initialPosition |
||
34 | */ |
||
35 | 5 | public function __construct( $dumpFilePath, $initialPosition = 0 ) { |
|
39 | |||
40 | 5 | public function __destruct() { |
|
43 | |||
44 | 5 | private function closeReader() { |
|
45 | 5 | if ( is_resource( $this->handle ) ) { |
|
46 | 4 | gzclose( $this->handle ); |
|
47 | 4 | $this->handle = null; |
|
48 | } |
||
49 | 5 | } |
|
50 | |||
51 | 1 | public function rewind() { |
|
55 | |||
56 | 5 | private function initReader() { |
|
57 | 5 | if ( $this->handle === null ) { |
|
58 | 5 | $this->handle = @gzopen( $this->dumpFile, 'r' ); |
|
59 | |||
60 | 5 | if ( $this->handle === false ) { |
|
61 | 1 | throw new DumpReadingException( 'Could not open file: ' . $this->dumpFile ); |
|
62 | } |
||
63 | |||
64 | 4 | $this->seekToPosition( $this->initialPosition ); |
|
65 | } |
||
66 | 4 | } |
|
67 | |||
68 | /** |
||
69 | * @return string|null |
||
70 | * @throws DumpReadingException |
||
71 | */ |
||
72 | 5 | public function nextJsonLine() { |
|
90 | |||
91 | /** |
||
92 | * @return int |
||
93 | * @throws DumpReadingException |
||
94 | */ |
||
95 | 1 | public function getPosition() { |
|
109 | |||
110 | /** |
||
111 | * @param int $position |
||
112 | * @throws DumpReadingException |
||
113 | */ |
||
114 | 4 | public function seekToPosition( $position ) { |
|
122 | |||
123 | } |
||
124 |