summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/de/weechat_user.de.adoc2
-rw-r--r--doc/en/weechat_user.en.adoc2
-rw-r--r--doc/fr/weechat_user.fr.adoc2
-rw-r--r--doc/it/weechat_user.it.adoc2
-rw-r--r--doc/ja/weechat_user.ja.adoc2
-rw-r--r--doc/pl/weechat_user.pl.adoc2
-rw-r--r--doc/sr/weechat_user.sr.adoc2
-rw-r--r--src/core/wee-dir.c88
8 files changed, 86 insertions, 16 deletions
diff --git a/doc/de/weechat_user.de.adoc b/doc/de/weechat_user.de.adoc
index e9b09b38c..4a37a7018 100644
--- a/doc/de/weechat_user.de.adoc
+++ b/doc/de/weechat_user.de.adoc
@@ -143,7 +143,7 @@ WeeChat *erforderlich* sind:
Relay-Erweiterung: Kompression von Nachrichten (WeeChat -> client) with https://zlib.net/[zlib ^↗^,window=_blank] (weechat protocol). +
Script-Erweiterung: Lesen der Repository-Indexdatei (gzip).
-| libzstd-dev |
+| libzstd-dev | ≥ 0.8.1
| Logger-Erweiterung: Kompression von rotierenden Protokolldateien. +
Relay-Erweiterung: Kompression von Nachrichten (WeeChat -> client) with https://facebook.github.io/zstd/[Zstandard ^↗^,window=_blank] (weechat protocol).
|===
diff --git a/doc/en/weechat_user.en.adoc b/doc/en/weechat_user.en.adoc
index 332f96410..05cb89752 100644
--- a/doc/en/weechat_user.en.adoc
+++ b/doc/en/weechat_user.en.adoc
@@ -137,7 +137,7 @@ WeeChat:
Relay plugin: compression of messages (WeeChat -> client) with https://zlib.net/[zlib ^↗^,window=_blank] (weechat protocol). +
Script plugin: read of repository index file (gzip).
-| libzstd-dev |
+| libzstd-dev | ≥ 0.8.1
| Logger plugin: compression of rotated log files. +
Relay plugin: compression of messages (WeeChat -> client) with https://facebook.github.io/zstd/[Zstandard ^↗^,window=_blank] (weechat protocol).
|===
diff --git a/doc/fr/weechat_user.fr.adoc b/doc/fr/weechat_user.fr.adoc
index 07d17e2ca..dc9261d42 100644
--- a/doc/fr/weechat_user.fr.adoc
+++ b/doc/fr/weechat_user.fr.adoc
@@ -138,7 +138,7 @@ Le tableau suivant liste les paquets *requis* pour compiler WeeChat :
Extention Relay : compression des messages (WeeChat -> client) avec https://zlib.net/[zlib ^↗^,window=_blank] (protocole weechat). +
Extension Script : lecture du fichier d'index du dépôt (gzip).
-| libzstd-dev |
+| libzstd-dev | ≥ 0.8.1
| Extension Logger : compression des fichiers de log qui tournent. +
Extension Relay : compression des messages (WeeChat -> client) avec https://facebook.github.io/zstd/[Zstandard ^↗^,window=_blank] (protocole weechat).
|===
diff --git a/doc/it/weechat_user.it.adoc b/doc/it/weechat_user.it.adoc
index 0c610c15f..be7fd1648 100644
--- a/doc/it/weechat_user.it.adoc
+++ b/doc/it/weechat_user.it.adoc
@@ -167,7 +167,7 @@ WeeChat:
Script plugin: read of repository index file (gzip).
// TRANSLATION MISSING
-| libzstd-dev |
+| libzstd-dev | ≥ 0.8.1
| Logger plugin: compression of rotated log files. +
Relay plugin: compression of messages (WeeChat -> client) with https://facebook.github.io/zstd/[Zstandard ^↗^,window=_blank] (weechat protocol).
|===
diff --git a/doc/ja/weechat_user.ja.adoc b/doc/ja/weechat_user.ja.adoc
index f1b24b94c..d5d5fdca6 100644
--- a/doc/ja/weechat_user.ja.adoc
+++ b/doc/ja/weechat_user.ja.adoc
@@ -153,7 +153,7 @@ WeeChat:
Script plugin: read of repository index file (gzip).
// TRANSLATION MISSING
-| libzstd-dev |
+| libzstd-dev | ≥ 0.8.1
| Logger plugin: compression of rotated log files. +
Relay plugin: compression of messages (WeeChat -> client) with https://facebook.github.io/zstd/[Zstandard ^↗^,window=_blank] (weechat protocol).
|===
diff --git a/doc/pl/weechat_user.pl.adoc b/doc/pl/weechat_user.pl.adoc
index a87d693f2..106e2e0ff 100644
--- a/doc/pl/weechat_user.pl.adoc
+++ b/doc/pl/weechat_user.pl.adoc
@@ -153,7 +153,7 @@ WeeChat:
Script plugin: read of repository index file (gzip).
// TRANSLATION MISSING
-| libzstd-dev |
+| libzstd-dev | ≥ 0.8.1
| Logger plugin: compression of rotated log files. +
Relay plugin: compression of messages (WeeChat -> client) with https://facebook.github.io/zstd/[Zstandard ^↗^,window=_blank] (weechat protocol).
|===
diff --git a/doc/sr/weechat_user.sr.adoc b/doc/sr/weechat_user.sr.adoc
index 1bc872c79..58b3fff17 100644
--- a/doc/sr/weechat_user.sr.adoc
+++ b/doc/sr/weechat_user.sr.adoc
@@ -139,7 +139,7 @@ https://github.com/weechat/weechat-container[weechat-container ^↗^,window=_bl
Script plugin: read of repository index file (gzip).
// TRANSLATION MISSING
-| libzstd-dev |
+| libzstd-dev | ≥ 0.8.1
| Logger plugin: compression of rotated log files. +
Relay plugin: compression of messages (WeeChat -> client) with https://facebook.github.io/zstd/[Zstandard ^↗^,window=_blank] (weechat protocol).
|===
diff --git a/src/core/wee-dir.c b/src/core/wee-dir.c
index 32a607f34..d5267ffa3 100644
--- a/src/core/wee-dir.c
+++ b/src/core/wee-dir.c
@@ -1044,7 +1044,9 @@ end:
/*
* Compresses a file with gzip.
*
- * The output file must not exist.
+ * Notes:
+ * - the output file must not exist
+ * - compression_level is an integer between 1 and 9
*
* Returns:
* 1: OK
@@ -1119,7 +1121,7 @@ dir_file_compress_gzip (const char *from, const char *to,
if (ret == Z_STREAM_ERROR)
goto error;
have = buffer_size - strm.avail_out;
- if (fwrite (buffer_out, 1, have, dest) != have || ferror (dest))
+ if ((fwrite (buffer_out, 1, have, dest) != have) || ferror (dest))
goto error;
} while (strm.avail_out == 0);
if (strm.avail_in != 0)
@@ -1154,7 +1156,9 @@ end:
/*
* Compresses a file with zstandard.
*
- * The output file must not exist.
+ * Notes:
+ * - the output file must not exist
+ * - compression_level is an integer between 1 and 19
*
* Returns:
* 1: OK
@@ -1168,9 +1172,15 @@ dir_file_compress_zstd (const char *from, const char *to,
FILE *source, *dest;
void *buffer_in, *buffer_out;
size_t buffer_in_size, buffer_out_size, num_read, remaining;
- int rc, finished, last_chunk;
- ZSTD_CCtx *cctx;
+ int rc;
+#if ZSTD_VERSION_NUMBER >= 10400 /* zstd ≥ 1.4.0 */
+ ZSTD_CCtx *cctx = NULL;
ZSTD_EndDirective mode;
+ int finished, last_chunk;
+#else /* zstd < 1.4.0 */
+ ZSTD_CStream *cstream = NULL;
+ size_t result, to_read;
+#endif
ZSTD_inBuffer input;
ZSTD_outBuffer output;
@@ -1178,7 +1188,6 @@ dir_file_compress_zstd (const char *from, const char *to,
dest = NULL;
buffer_in = NULL;
buffer_out = NULL;
- cctx = NULL;
rc = 0;
if (!from || !to || (compression_level < 1) || (compression_level > 19))
@@ -1203,10 +1212,10 @@ dir_file_compress_zstd (const char *from, const char *to,
if (!dest)
goto end;
+#if ZSTD_VERSION_NUMBER >= 10400 /* zstd ≥ 1.4.0 */
cctx = ZSTD_createCCtx ();
if (!cctx)
- goto end;
-
+ goto error;
ZSTD_CCtx_setParameter (cctx, ZSTD_c_compressionLevel, compression_level);
while (1)
@@ -1228,7 +1237,11 @@ dir_file_compress_zstd (const char *from, const char *to,
remaining = ZSTD_compressStream2(cctx, &output , &input, mode);
if (ZSTD_isError (remaining))
goto error;
- fwrite (buffer_out, 1, output.pos, dest);
+ if ((fwrite (buffer_out, 1, output.pos, dest) != output.pos)
+ || ferror (dest))
+ {
+ goto error;
+ }
finished = (last_chunk) ? (remaining == 0) : (input.pos == input.size);
};
if (input.pos != input.size)
@@ -1236,21 +1249,78 @@ dir_file_compress_zstd (const char *from, const char *to,
if (last_chunk)
break;
}
+#else /* zstd < 1.4.0 */
+ cstream = ZSTD_createCStream ();
+ if (!cstream)
+ goto error;
+ result = ZSTD_initCStream (cstream, compression_level);
+ if (ZSTD_isError (result))
+ goto error;
+ to_read = buffer_in_size;
+ while ((num_read = fread (buffer_in, 1, buffer_in_size, source)))
+ {
+ input.src = buffer_in;
+ input.size = num_read;
+ input.pos = 0;
+ while (input.pos < input.size)
+ {
+ output.dst = buffer_out;
+ output.size = buffer_out_size;
+ output.pos = 0;
+ to_read = ZSTD_compressStream (cstream, &output , &input);
+ if (ZSTD_isError (to_read))
+ goto error;
+ if (to_read > buffer_in_size)
+ to_read = buffer_in_size;
+ if ((fwrite (buffer_out, 1, output.pos, dest) != output.pos)
+ || ferror (dest))
+ {
+ goto error;
+ }
+ }
+ }
+
+ output.dst = buffer_out;
+ output.size = buffer_out_size;
+ output.pos = 0;
+ remaining = ZSTD_endStream (cstream, &output);
+ if (remaining)
+ goto error;
+ if ((fwrite (buffer_out, 1, output.pos, dest) != output.pos)
+ || ferror (dest))
+ {
+ goto error;
+ }
+#endif
rc = 1;
goto end;
error:
+#if ZSTD_VERSION_NUMBER >= 10400 /* zstd ≥ 1.4.0 */
if (cctx)
{
ZSTD_freeCCtx (cctx);
cctx = NULL;
}
+#else /* zstd < 1.4.0 */
+ if (cstream)
+ {
+ ZSTD_freeCStream (cstream);
+ cstream = NULL;
+ }
+#endif
unlink (to);
end:
+#if ZSTD_VERSION_NUMBER >= 10400 /* zstd ≥ 1.4.0 */
if (cctx)
ZSTD_freeCCtx (cctx);
+#else /* zstd < 1.4.0 */
+ if (cstream)
+ ZSTD_freeCStream (cstream);
+#endif
+
if (buffer_in)
free (buffer_in);
if (buffer_out)