From ecfc54403e2a1934b4f6e84ddad429b7970091fa Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Tue, 7 May 2019 18:40:40 +0200 Subject: 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). --- guix/lzlib.scm | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'guix/lzlib.scm') 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 -- cgit v1.2.3