ISGArchiveDelegate.php
3 years ago
SGBGArchive.php
3 years ago
SGBGArchiveCdr.php
3 years ago
SGBGArchiveHelper.php
3 years ago
SGBGCache.php
3 years ago
SGBGCacheableFile.php
3 years ago
SGBGDirectoryTreeFile.php
3 years ago
SGBGFile.php
3 years ago
SGBGFileHelper.php
3 years ago
SGBGJsonFile.php
3 years ago
SGBGLog.php
3 years ago
SGBGReloader.php
3 years ago
SGBGStateFile.php
3 years ago
SGBGTask.php
3 years ago
SGBGArchiveCdr.php
71 lines
| 1 | <?php |
| 2 | require_once(__DIR__.'/SGBGCacheableFile.php'); |
| 3 | require_once(__DIR__.'/SGBGArchiveHelper.php'); |
| 4 | |
| 5 | class SGBGArchiveCdr extends SGBGCacheableFile |
| 6 | { |
| 7 | private $count = 0; |
| 8 | |
| 9 | public function getCount() |
| 10 | { |
| 11 | return $this->count; |
| 12 | } |
| 13 | |
| 14 | public function setCount($count) |
| 15 | { |
| 16 | $this->count = $count; |
| 17 | } |
| 18 | |
| 19 | public function addFile($filename, $offset, $compressedLength, $uncompressedLength, $fileChunks, $logCallable, $crcData) |
| 20 | { |
| 21 | $logCallable('Start write CDR item'); |
| 22 | |
| 23 | $logCallable('CRC: Not supported'); |
| 24 | |
| 25 | $rec = SGBGArchiveHelper::packToLittleEndian(abs(crc32($crcData)), 4); //crc (not used in this version) |
| 26 | |
| 27 | $filenameLen = strlen($filename); |
| 28 | $logCallable('Filename length: '.$filenameLen); |
| 29 | $rec .= SGBGArchiveHelper::packToLittleEndian($filenameLen, 2); |
| 30 | |
| 31 | $logCallable('Filename: '.$filename); |
| 32 | $rec .= $filename; |
| 33 | |
| 34 | //file offset, compressed length, uncompressed length, all of them are written in 8 bytes to cover big integer size |
| 35 | $logCallable('Offset: '.$offset); |
| 36 | $rec .= SGBGArchiveHelper::packToLittleEndian($offset, 8); |
| 37 | |
| 38 | $logCallable('Compressed length: '.$compressedLength); |
| 39 | $rec .= SGBGArchiveHelper::packToLittleEndian($compressedLength, 8); |
| 40 | |
| 41 | $logCallable('Uncompressed length: '.$uncompressedLength); |
| 42 | $rec .= SGBGArchiveHelper::packToLittleEndian($uncompressedLength, 8); //uncompressed size (not used in this version) |
| 43 | |
| 44 | if (!empty($fileChunks)) { |
| 45 | $chunksCount = count($fileChunks); |
| 46 | $logCallable('Number of chunks: ' . $chunksCount); |
| 47 | $rec .= SGBGArchiveHelper::packToLittleEndian($chunksCount, 4); |
| 48 | |
| 49 | foreach ($fileChunks as $fileChunk) { |
| 50 | $logCallable('Chunk: Start(' . $fileChunk['start'] . ') - Size(' . $fileChunk['size'] . ')'); |
| 51 | //start and size are written in 8 bytes to cover big integer size |
| 52 | $rec .= SGBGArchiveHelper::packToLittleEndian($fileChunk['start'], 8); |
| 53 | $rec .= SGBGArchiveHelper::packToLittleEndian($fileChunk['size'], 8); |
| 54 | } |
| 55 | } else { |
| 56 | $rec .= SGBGArchiveHelper::packToLittleEndian(0, 8); |
| 57 | $rec .= SGBGArchiveHelper::packToLittleEndian(0, 8); |
| 58 | } |
| 59 | |
| 60 | |
| 61 | $result = $this->write($rec); |
| 62 | if ($result === FALSE) { |
| 63 | throw new Exception('Failed to write in cdr.'); |
| 64 | } |
| 65 | |
| 66 | $this->count++; |
| 67 | |
| 68 | $logCallable('End write CDR item: '.$result.' bytes'); |
| 69 | } |
| 70 | } |
| 71 |