summaryrefslogtreecommitdiff
path: root/guix/lzlib.scm
diff options
context:
space:
mode:
authorPierre Neidhardt <mail@ambrevar.xyz>2019-05-07 18:40:40 +0200
committerPierre Neidhardt <mail@ambrevar.xyz>2019-05-07 18:40:40 +0200
commitecfc54403e2a1934b4f6e84ddad429b7970091fa (patch)
treea4b9fa7aeaf1050859fc04025be60ac7cbd071eb /guix/lzlib.scm
parentdbef9015db107dd148133420b89af552ef08f8ee (diff)
downloadpatches-ecfc54403e2a1934b4f6e84ddad429b7970091fa.tar
patches-ecfc54403e2a1934b4f6e84ddad429b7970091fa.tar.gz
guix: Simplify and robustify lzread!.
* guix/lzlib.scm (lzread!): Do it. Previously lzread! would fail if COUNT was bigger than (lz-decompress-write-size). This is possible if a previous call to lzread! didn't empty the LZ_decompress input buffer (e.g. BV was too small to fit all the data).
Diffstat (limited to 'guix/lzlib.scm')
-rw-r--r--guix/lzlib.scm20
1 files changed, 6 insertions, 14 deletions
diff --git a/guix/lzlib.scm b/guix/lzlib.scm
index d596f0d95d..a6dac46049 100644
--- a/guix/lzlib.scm
+++ b/guix/lzlib.scm
@@ -491,27 +491,19 @@ perhaps not yet read."
;; High level functions.
-(define %lz-decompress-input-buffer-size (* 64 1024))
-
(define* (lzread! decoder file-port bv
#:optional (start 0) (count (bytevector-length bv)))
"Read up to COUNT bytes from FILE-PORT into BV at offset START. Return the
number of uncompressed bytes actually read; it is zero if COUNT is zero or if
the end-of-stream has been reached."
;; WARNING: Because we don't alternate between lz-reads and lz-writes, we can't
- ;; process more than %lz-decompress-input-buffer-size from the file-port.
- (when (> count %lz-decompress-input-buffer-size)
- (set! count %lz-decompress-input-buffer-size))
- (let* ((written 0)
- (read 0)
- (file-bv (get-bytevector-n file-port count)))
+ ;; process more than lz-decompress-write-size from the file-port.
+ (when (> count (lz-decompress-write-size decoder))
+ (set! count (lz-decompress-write-size decoder)))
+ (let ((file-bv (get-bytevector-n file-port count)))
(unless (eof-object? file-bv)
- (begin
- (while (and (< 0 (lz-decompress-write-size decoder))
- (< written (bytevector-length file-bv)))
- (set! written (+ written
- (lz-decompress-write decoder file-bv written
- (- (bytevector-length file-bv) written)))))))
+ (lz-decompress-write decoder file-bv 0 (bytevector-length file-bv))))
+ (let ((read 0))
(let loop ((rd 0))
(if (< start (bytevector-length bv))
(begin