mirror of
https://codeberg.org/guix/guix.git
synced 2025-10-02 02:15:12 +00:00
utils: Add 'call-with-decompressed-port' and 'call-with-compressed-output-port'.
* guix/utils.scm (call-with-decompressed-port, call-with-compressed-output-port): New procedures. * tests/utils.scm ("compressed-output-port + decompressed-port"): Rewrite to use them.
This commit is contained in:
parent
80dea563a3
commit
01ac19dca4
3 changed files with 48 additions and 18 deletions
|
@ -162,23 +162,16 @@
|
|||
(equal? (get-bytevector-all decompressed) data)))))
|
||||
|
||||
(false-if-exception (delete-file temp-file))
|
||||
(test-equal "compressed-output-port + decompressed-port"
|
||||
'((0) "Hello, compressed port!")
|
||||
(let ((text "Hello, compressed port!")
|
||||
(output (open-file temp-file "w0b")))
|
||||
(let-values (((compressed pids)
|
||||
(compressed-output-port 'xz output)))
|
||||
(display text compressed)
|
||||
(close-port compressed)
|
||||
(close-port output)
|
||||
(and (every (compose zero? cdr waitpid) pids)
|
||||
(let*-values (((input)
|
||||
(open-file temp-file "r0b"))
|
||||
((decompressed pids)
|
||||
(decompressed-port 'xz input)))
|
||||
(let ((str (get-string-all decompressed)))
|
||||
(list (map (compose cdr waitpid) pids)
|
||||
str)))))))
|
||||
(test-assert "compressed-output-port + decompressed-port"
|
||||
(let* ((file (search-path %load-path "guix/derivations.scm"))
|
||||
(data (call-with-input-file file get-bytevector-all)))
|
||||
(call-with-compressed-output-port 'xz (open-file temp-file "w0b")
|
||||
(lambda (compressed)
|
||||
(put-bytevector compressed data)))
|
||||
|
||||
(bytevector=? data
|
||||
(call-with-decompressed-port 'xz (open-file temp-file "r0b")
|
||||
get-bytevector-all))))
|
||||
|
||||
(false-if-exception (delete-file temp-file))
|
||||
(test-equal "fcntl-flock wait"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue