mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-08 13:37:35 +02:00
Adding temporary zlib hack.
This commit is contained in:
parent
978aed4f60
commit
298e47e932
2 changed files with 42 additions and 0 deletions
37
lib/chibi/zlib.scm
Normal file
37
lib/chibi/zlib.scm
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
|
||||||
|
;; Temporary hack, need to rewrite in pure Scheme.
|
||||||
|
|
||||||
|
;;> Gzip compress a file in place, renaming with a .gz suffix.
|
||||||
|
|
||||||
|
(define (gzip-file path)
|
||||||
|
(system "gzip" path))
|
||||||
|
|
||||||
|
;;> Gunzip decompress a file in place, removing any .gz suffix.
|
||||||
|
|
||||||
|
(define (gunzip-file path)
|
||||||
|
(system "gzip" "-d" path))
|
||||||
|
|
||||||
|
;; Utility to filter a bytevector to a process and return the
|
||||||
|
;; accumulated output as a new bytevector.
|
||||||
|
(define (process-pipe-bytevector cmd bvec)
|
||||||
|
(call-with-process-io
|
||||||
|
cmd
|
||||||
|
(lambda (pid proc-in proc-out proc-err)
|
||||||
|
;; This could overflow the pipe.
|
||||||
|
(write-bytevector bvec proc-in)
|
||||||
|
(close-output-port proc-in)
|
||||||
|
(let ((res (port->bytevector proc-out)))
|
||||||
|
(waitpid pid 0)
|
||||||
|
res))))
|
||||||
|
|
||||||
|
;;> Gzip compress a string or bytevector in memory.
|
||||||
|
|
||||||
|
(define (gzip x)
|
||||||
|
(if (string? x)
|
||||||
|
(gzip (string->utf8 x))
|
||||||
|
(process-pipe-bytevector '("gzip" "-c") x)))
|
||||||
|
|
||||||
|
;;> Gunzip decompress a bytevector in memory.
|
||||||
|
|
||||||
|
(define (gunzip bvec)
|
||||||
|
(process-pipe-bytevector '("gzip" "-c" "-d") bvec))
|
5
lib/chibi/zlib.sld
Normal file
5
lib/chibi/zlib.sld
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
|
||||||
|
(define-library (chibi zlib)
|
||||||
|
(export gzip-file gunzip-file gzip gunzip)
|
||||||
|
(import (scheme base) (chibi io) (chibi process))
|
||||||
|
(include "zlib.scm"))
|
Loading…
Add table
Reference in a new issue