diff options
| author | Noam Postavsky | 2018-10-27 17:45:00 -0400 |
|---|---|---|
| committer | Noam Postavsky | 2019-04-02 22:02:32 -0400 |
| commit | b36913d803ee22a314f2e0a27523fbadeb60dd2c (patch) | |
| tree | b5f8fa4e531198d1c049c42b1b0853a5dd87d72d /src | |
| parent | 2bd3e484041b2b7ea47c236b86f59610d971b609 (diff) | |
| download | emacs-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.c | 22 |
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 | ||
| 121 | DEFUN ("zlib-decompress-region", Fzlib_decompress_region, | 121 | DEFUN ("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. |
| 125 | Replace the text in the region by the decompressed data. | 125 | Replace the text in the region by the decompressed data. |
| 126 | On failure, return nil and leave the data in place. | 126 | |
| 127 | If optional parameter ALLOW-PARTIAL is nil or omitted, then on | ||
| 128 | failure, return nil and leave the data in place. Otherwise, return | ||
| 129 | the number of bytes that were not decompressed and replace the region | ||
| 130 | text by whatever data was successfully decompressed (similar to gzip). | ||
| 131 | If decompression is completely successful return t. | ||
| 132 | |||
| 127 | This function can be called only in unibyte buffers. */) | 133 | This 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 | ||