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
SGBGArchiveHelper.php
88 lines
| 1 | <?php |
| 2 | |
| 3 | class SGBGArchiveHelper |
| 4 | { |
| 5 | public static function packToLittleEndian($value, $size = 4) |
| 6 | { |
| 7 | if (is_int($value)) { |
| 8 | $size *= 2; //2 characters for each byte |
| 9 | $value = str_pad(dechex($value), $size, '0', STR_PAD_LEFT); |
| 10 | return strrev(pack('H'.$size, $value)); |
| 11 | } |
| 12 | |
| 13 | $hex = str_pad($value->toHex(), 16, '0', STR_PAD_LEFT); |
| 14 | |
| 15 | $high = substr($hex, 0, 8); |
| 16 | $low = substr($hex, 8, 8); |
| 17 | |
| 18 | $high = strrev(pack('H8', $high)); |
| 19 | $low = strrev(pack('H8', $low)); |
| 20 | |
| 21 | return $low.$high; |
| 22 | } |
| 23 | |
| 24 | public static function unpackLittleEndian($data, $size) |
| 25 | { |
| 26 | $size *= 2; //2 characters for each byte |
| 27 | |
| 28 | $data = unpack('H'.$size, strrev($data)); |
| 29 | return $data[1]; |
| 30 | } |
| 31 | |
| 32 | public static function createPath($path) |
| 33 | { |
| 34 | if (is_dir($path)) { |
| 35 | return true; |
| 36 | } |
| 37 | |
| 38 | $prevPath = substr($path, 0, strrpos($path, '/', -2) + 1); |
| 39 | $return = self::createPath($prevPath); |
| 40 | if ($return && is_writable($prevPath)) { |
| 41 | if (!@mkdir($path)) { |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | @chmod($path, 0755); |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | public static function realFilesize($filename) |
| 53 | { |
| 54 | if (is_dir($filename)) { |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | $fp = fopen($filename, 'r'); |
| 59 | $return = false; |
| 60 | if (is_resource($fp)) { |
| 61 | if (PHP_INT_SIZE < 8) { // 32 bit |
| 62 | if (0 === fseek($fp, 0, SEEK_END)) { |
| 63 | $return = 0.0; |
| 64 | $step = 0x7FFFFFFF; |
| 65 | while ($step > 0) { |
| 66 | if (0 === fseek($fp, - $step, SEEK_CUR)) { |
| 67 | $return += floatval($step); |
| 68 | } |
| 69 | else { |
| 70 | $step >>= 1; |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | else if (0 === fseek($fp, 0, SEEK_END)) { // 64 bit |
| 76 | $return = ftell($fp); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | return $return; |
| 81 | } |
| 82 | |
| 83 | public static function is_dir_empty($dir) { |
| 84 | if (!is_readable($dir)) return null; |
| 85 | return (count(scandir($dir)) == 2); |
| 86 | } |
| 87 | } |
| 88 |