Adding maybe-gunzip utility for optionally compressed inputs.

This commit is contained in:
Alex Shinn 2014-06-03 23:09:44 +09:00
parent c3b265f990
commit a21e391f15
2 changed files with 11 additions and 1 deletions

View file

@ -35,3 +35,13 @@
(define (gunzip bvec)
(process-pipe-bytevector '("gzip" "-c" "-d") bvec))
;;> Gunzip decompress a bytevector in memory if it has been
;;> compressed, or return as-is otherwise.
(define (maybe-gunzip bvec)
(if (and (>= (bytevector-length bvec) 10)
(eqv? #x1f (bytevector-u8-ref bvec 0))
(eqv? #x8b (bytevector-u8-ref bvec 1)))
(gunzip bvec)
bvec))

View file

@ -1,5 +1,5 @@
(define-library (chibi zlib)
(export gzip-file gunzip-file gzip gunzip)
(export gzip-file gunzip-file gzip gunzip maybe-gunzip)
(import (scheme base) (chibi io) (chibi process))
(include "zlib.scm"))