aboutsummaryrefslogtreecommitdiff
path: root/guix/utils.scm
diff options
context:
space:
mode:
Diffstat (limited to 'guix/utils.scm')
-rw-r--r--guix/utils.scm25
1 files changed, 24 insertions, 1 deletions
diff --git a/guix/utils.scm b/guix/utils.scm
index 15a4390074..f786c83f47 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -70,7 +70,10 @@
call-with-temporary-output-file
with-atomic-file-output
fold2
- filtered-port))
+
+ filtered-port
+ compressed-port
+ decompressed-port))
;;;
@@ -200,6 +203,26 @@ buffered data is lost."
(close-port out)
(loop in (cons child pids)))))))))
+(define (decompressed-port compression input)
+ "Return an input port where INPUT is decompressed according to COMPRESSION,
+a symbol such as 'xz."
+ (match compression
+ ((or #f 'none) (values input '()))
+ ('bzip2 (filtered-port `(,%bzip2 "-dc") input))
+ ('xz (filtered-port `(,%xz "-dc") input))
+ ('gzip (filtered-port `(,%gzip "-dc") input))
+ (else (error "unsupported compression scheme" compression))))
+
+(define (compressed-port compression input)
+ "Return an input port where INPUT is decompressed according to COMPRESSION,
+a symbol such as 'xz."
+ (match compression
+ ((or #f 'none) (values input '()))
+ ('bzip2 (filtered-port `(,%bzip2 "-c") input))
+ ('xz (filtered-port `(,%xz "-c") input))
+ ('gzip (filtered-port `(,%gzip "-c") input))
+ (else (error "unsupported compression scheme" compression))))
+
;;;
;;; Nixpkgs.