summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Collet <remi@remirepo.net>2024-05-30 16:52:30 +0200
committerRemi Collet <remi@php.net>2024-05-30 16:52:30 +0200
commitde61165aa4593ceb29f125703e7935d4094597be (patch)
tree18be18b7dcc9c2fbcb1d29bd172e1204710a0e39
parentdc511105f5637ddcb43377e5c1fbf3897c4f6099 (diff)
xz/zstd compression
-rw-r--r--class/Parser.php35
1 files changed, 26 insertions, 9 deletions
diff --git a/class/Parser.php b/class/Parser.php
index 5146044..57b0a77 100644
--- a/class/Parser.php
+++ b/class/Parser.php
@@ -191,15 +191,32 @@ class Parser
} else if ($TimRemote > $row['stamp']) {
self::log("Loading $UrlRemote");
- $fic=gzopen($UrlRemote, "r");
- if ($fic) {
- $txt="";
- while ($buf=gzread($fic, 8196)) {
- $txt .= $buf;
+ $txt = file_get_contents($UrlRemote);
+ if (!$txt) {
+ self::log("ERROR : can't read $UrlRemote");
+ } else if (str_ends_with($UrlRemote, '.xml')) {
+ // OK
+ } else if (str_ends_with($UrlRemote, '.xz')) {
+ if (function_exists('xzdecode')) {
+ $txt = xzdecode($txt);
+ } else {
+ self::log("ERROR : missing xz php extension");
+ return NULL;
}
- self::log("Read " . strlen($txt) . " bytes");
- gzclose($fic);
-
+ } else if (str_ends_with($UrlRemote, '.zst')) {
+ if (function_exists('zstd_uncompress')) {
+ $txt = zstd_uncompress($txt);
+ } else {
+ self::log("ERROR : missing zstd php extension");
+ return NULL;
+ }
+ } else if (str_ends_with($UrlRemote, '.gz')) {
+ $txt = gzdecode($txt);
+ } else {
+ self::log("ERROR : unkown compression");
+ return NULL;
+ }
+ if ($txt) {
$primary = simplexml_load_string($txt);
if ($primary) {
self::log("Read " . $primary->attributes() . " packages");
@@ -210,7 +227,7 @@ class Parser
self::log("ERROR : can't parse $UrlRemote");
}
} else {
- self::log("ERROR : can't read $UrlRemote");
+ self::log("ERROR : can't uncompress $UrlRemote");
}
} else {
self::log("no update needed : $TimRemote / " . $row['stamp']);