diff options
| author | Andreas Enge <andreas@enge.fr> | 2016-07-28 11:08:55 +0200 |
|---|---|---|
| committer | Andreas Enge <andreas@enge.fr> | 2016-07-28 11:08:55 +0200 |
| commit | e309c7561043361afe63cc9435e620323f870a61 (patch) | |
| tree | cd6fe073ba840bb68f446933ece44b45d8eb5ec7 /guix/zlib.scm | |
| parent | 1bb163b0dd07c8f2cfd7e91f1e428075cd3d5ed2 (diff) | |
| parent | e335b82c4eba13fe873db2d680d399469931c10f (diff) | |
Merge remote-tracking branch 'origin/master' into core-updates
Diffstat (limited to 'guix/zlib.scm')
| -rw-r--r-- | guix/zlib.scm | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/guix/zlib.scm b/guix/zlib.scm index 51e5e9e426..74420129f6 100644 --- a/guix/zlib.scm +++ b/guix/zlib.scm @@ -92,7 +92,8 @@ closes FD." (let ((proc (zlib-procedure int "gzread" (list '* '* unsigned-int)))) (lambda* (gzfile bv #:optional (start 0) (count (bytevector-length bv))) "Read up to COUNT bytes from GZFILE into BV at offset START. Return the -number of uncompressed bytes actually read." +number of uncompressed bytes actually read; it is zero if COUNT is zero or if +the end-of-stream has been reached." (let ((ret (proc (gzip-file->pointer gzfile) (bytevector->pointer bv start) count))) @@ -167,12 +168,20 @@ closed even if closing GZFILE triggers an exception." "Return an input port that decompresses data read from PORT, a file port. PORT is automatically closed when the resulting port is closed. BUFFER-SIZE is the size in bytes of the internal buffer, 8 KiB by default; using a larger -buffer increases decompression speed." +buffer increases decompression speed. An error is thrown if PORT contains +buffered input, which would be lost (and is lost anyway)." (define gzfile - (gzdopen (fileno port) "r")) + (match (drain-input port) + ("" ;PORT's buffer is empty + (gzdopen (fileno port) "r")) + (_ + ;; This is unrecoverable but it's better than having the buffered input + ;; be lost, leading to unclear end-of-file or corrupt-data errors down + ;; the path. + (throw 'zlib-error 'make-gzip-input-port + "port contains buffered input" port)))) (define (read! bv start count) - ;; XXX: Can 'gzread!' return zero even though we haven't reached the EOF? (gzread! gzfile bv start count)) (unless (= buffer-size %default-buffer-size) @@ -189,8 +198,10 @@ buffer increases decompression speed." a file port, as its sink. PORT is automatically closed when the resulting port is closed." (define gzfile - (gzdopen (fileno port) - (string-append "w" (number->string level)))) + (begin + (force-output port) ;empty PORT's buffer + (gzdopen (fileno port) + (string-append "w" (number->string level))))) (define (write! bv start count) (gzwrite gzfile bv start count)) |
