aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNoam Postavsky2018-10-27 17:45:00 -0400
committerNoam Postavsky2019-04-02 22:02:32 -0400
commitb36913d803ee22a314f2e0a27523fbadeb60dd2c (patch)
treeb5f8fa4e531198d1c049c42b1b0853a5dd87d72d /src
parent2bd3e484041b2b7ea47c236b86f59610d971b609 (diff)
downloademacs-b36913d803ee22a314f2e0a27523fbadeb60dd2c.tar.gz
emacs-b36913d803ee22a314f2e0a27523fbadeb60dd2c.zip
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')
-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,
120 120
121DEFUN ("zlib-decompress-region", Fzlib_decompress_region, 121DEFUN ("zlib-decompress-region", Fzlib_decompress_region,
122 Szlib_decompress_region, 122 Szlib_decompress_region,
123 2, 2, 0, 123 2, 3, 0,
124 doc: /* Decompress a gzip- or zlib-compressed region. 124 doc: /* Decompress a gzip- or zlib-compressed region.
125Replace the text in the region by the decompressed data. 125Replace the text in the region by the decompressed data.
126On failure, return nil and leave the data in place. 126
127If optional parameter ALLOW-PARTIAL is nil or omitted, then on
128failure, return nil and leave the data in place. Otherwise, return
129the number of bytes that were not decompressed and replace the region
130text by whatever data was successfully decompressed (similar to gzip).
131If decompression is completely successful return t.
132
127This function can be called only in unibyte buffers. */) 133This function can be called only in unibyte buffers. */)
128 (Lisp_Object start, Lisp_Object end) 134 (Lisp_Object start, Lisp_Object end, Lisp_Object allow_partial)
129{ 135{
130 ptrdiff_t istart, iend, pos_byte; 136 ptrdiff_t istart, iend, pos_byte;
131 z_stream stream; 137 z_stream stream;
@@ -206,8 +212,14 @@ This function can be called only in unibyte buffers. */)
206 } 212 }
207 while (inflate_status == Z_OK); 213 while (inflate_status == Z_OK);
208 214
215 Lisp_Object ret = Qt;
209 if (inflate_status != Z_STREAM_END) 216 if (inflate_status != Z_STREAM_END)
210 return unbind_to (count, Qnil); 217 {
218 if (!NILP (allow_partial))
219 ret = make_int (iend - pos_byte);
220 else
221 return unbind_to (count, Qnil);
222 }
211 223
212 unwind_data.start = 0; 224 unwind_data.start = 0;
213 225
@@ -218,7 +230,7 @@ This function can be called only in unibyte buffers. */)
218 signal_after_change (istart, iend - istart, unwind_data.nbytes); 230 signal_after_change (istart, iend - istart, unwind_data.nbytes);
219 update_compositions (istart, istart, CHECK_HEAD); 231 update_compositions (istart, istart, CHECK_HEAD);
220 232
221 return unbind_to (count, Qt); 233 return unbind_to (count, ret);
222} 234}
223 235
224 236