summaryrefslogtreecommitdiff
path: root/src/decompress.c
diff options
context:
space:
mode:
authorNoam Postavsky <npostavs@users.sourceforge.net>2018-10-27 17:45:00 -0400
committerNoam Postavsky <npostavs@users.sourceforge.net>2019-04-02 22:02:32 -0400
commitb36913d803ee22a314f2e0a27523fbadeb60dd2c (patch)
treeb5f8fa4e531198d1c049c42b1b0853a5dd87d72d /src/decompress.c
parent2bd3e484041b2b7ea47c236b86f59610d971b609 (diff)
downloademacs-b36913d803ee22a314f2e0a27523fbadeb60dd2c.tar.gz
Allow partial decompression (Bug#33133)
* src/decompress.c (Fzlib_decompress_region): Add optional ALLOW-PARTIAL parameter. * lisp/url/url-http.el (url-handle-content-transfer-encoding): Use it. * doc/lispref/text.texi (Decompression): Document it. * etc/NEWS: Announce it.
Diffstat (limited to 'src/decompress.c')
-rw-r--r--src/decompress.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/decompress.c b/src/decompress.c
index e66e4798b18..4ca6a50b2a2 100644
--- a/src/decompress.c
+++ b/src/decompress.c
@@ -120,12 +120,18 @@ DEFUN ("zlib-available-p", Fzlib_available_p, Szlib_available_p, 0, 0, 0,
DEFUN ("zlib-decompress-region", Fzlib_decompress_region,
Szlib_decompress_region,
- 2, 2, 0,
+ 2, 3, 0,
doc: /* Decompress a gzip- or zlib-compressed region.
Replace the text in the region by the decompressed data.
-On failure, return nil and leave the data in place.
+
+If optional parameter ALLOW-PARTIAL is nil or omitted, then on
+failure, return nil and leave the data in place. Otherwise, return
+the number of bytes that were not decompressed and replace the region
+text by whatever data was successfully decompressed (similar to gzip).
+If decompression is completely successful return t.
+
This function can be called only in unibyte buffers. */)
- (Lisp_Object start, Lisp_Object end)
+ (Lisp_Object start, Lisp_Object end, Lisp_Object allow_partial)
{
ptrdiff_t istart, iend, pos_byte;
z_stream stream;
@@ -206,8 +212,14 @@ This function can be called only in unibyte buffers. */)
}
while (inflate_status == Z_OK);
+ Lisp_Object ret = Qt;
if (inflate_status != Z_STREAM_END)
- return unbind_to (count, Qnil);
+ {
+ if (!NILP (allow_partial))
+ ret = make_int (iend - pos_byte);
+ else
+ return unbind_to (count, Qnil);
+ }
unwind_data.start = 0;
@@ -218,7 +230,7 @@ This function can be called only in unibyte buffers. */)
signal_after_change (istart, iend - istart, unwind_data.nbytes);
update_compositions (istart, istart, CHECK_HEAD);
- return unbind_to (count, Qt);
+ return unbind_to (count, ret);
}