From: "Ludovic Courtès" <ludo@gnu.org>
To: 35880@debbugs.gnu.org
Cc: Pierre Neidhardt <mail@ambrevar.xyz>
Subject: [bug#35880] [PATCH 3/7] utils: Support compression and decompression with lzip.
Date: Fri, 24 May 2019 15:42:34 +0200 [thread overview]
Message-ID: <20190524134238.22802-3-ludo@gnu.org> (raw)
In-Reply-To: <20190524134238.22802-1-ludo@gnu.org>
* guix/utils.scm (lzip-port): New procedure.
(decompressed-port, compressed-port, compressed-output-port): Add 'lzip
case.
* tests/utils.scm <top level>: Call 'test-compression/decompression' for
'lzip as well.
---
guix/utils.scm | 27 ++++++++++++++++++++++-----
tests/utils.scm | 5 +++--
2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/guix/utils.scm b/guix/utils.scm
index ed1a418cca..709cdf9353 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2013, 2014, 2015 Mark H Weaver <mhw@netris.org>
;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
;;; Copyright © 2014 Ian Denhardt <ian@zenhack.net>
@@ -169,6 +169,17 @@ buffered data is lost."
(close-port out)
(loop in (cons child pids)))))))))
+(define (lzip-port proc port . args)
+ "Return the lzip port produced by calling PROC (a symbol) on PORT and ARGS.
+Raise an error if lzlib support is missing."
+ (let* ((lzlib (false-if-exception (resolve-interface '(guix lzlib))))
+ (supported? (and lzlib
+ ((module-ref lzlib 'lzlib-available?)))))
+ (if supported?
+ (let ((make-port (module-ref lzlib proc)))
+ (values (make-port port) '()))
+ (error "lzip compression not supported" lzlib))))
+
(define (decompressed-port compression input)
"Return an input port where INPUT is decompressed according to COMPRESSION,
a symbol such as 'xz."
@@ -177,17 +188,21 @@ a symbol such as 'xz."
('bzip2 (filtered-port `(,%bzip2 "-dc") input))
('xz (filtered-port `(,%xz "-dc") input))
('gzip (filtered-port `(,%gzip "-dc") input))
- (else (error "unsupported compression scheme" compression))))
+ ('lzip (values (lzip-port 'make-lzip-input-port input)
+ '()))
+ (_ (error "unsupported compression scheme" compression))))
(define (compressed-port compression input)
- "Return an input port where INPUT is decompressed according to COMPRESSION,
+ "Return an input port where INPUT is compressed 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))))
+ ('lzip (values (lzip-port 'make-lzip-input-port/compressed input)
+ '()))
+ (_ (error "unsupported compression scheme" compression))))
(define (call-with-decompressed-port compression port proc)
"Call PROC with a wrapper around PORT, a file port, that decompresses data
@@ -244,7 +259,9 @@ program--e.g., '(\"--fast\")."
('bzip2 (filtered-output-port `(,%bzip2 "-c" ,@options) output))
('xz (filtered-output-port `(,%xz "-c" ,@options) output))
('gzip (filtered-output-port `(,%gzip "-c" ,@options) output))
- (else (error "unsupported compression scheme" compression))))
+ ('lzip (values (lzip-port 'make-lzip-output-port output)
+ '()))
+ (_ (error "unsupported compression scheme" compression))))
(define* (call-with-compressed-output-port compression port proc
#:key (options '()))
diff --git a/tests/utils.scm b/tests/utils.scm
index 7d55107fda..7c8f7c09d0 100644
--- a/tests/utils.scm
+++ b/tests/utils.scm
@@ -23,6 +23,7 @@
#:use-module (guix utils)
#:use-module ((guix store) #:select (%store-prefix store-path-package-name))
#:use-module ((guix search-paths) #:select (string-tokenize*))
+ #:use-module ((guix lzlib) #:select (lzlib-available?))
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-11)
#:use-module (srfi srfi-64)
@@ -213,8 +214,8 @@ skip these tests."
get-bytevector-all)))))
(for-each test-compression/decompression
- '(gzip xz)
- (list (const #t) (const #f)))
+ '(gzip xz lzip)
+ (list (const #t) (const #f) lzlib-available?))
;; This is actually in (guix store).
(test-equal "store-path-package-name"
--
2.21.0
next prev parent reply other threads:[~2019-05-24 13:43 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-24 13:31 [bug#35880] [PATCH 0/7] Lzip support for 'guix publish' and 'guix substitute' Ludovic Courtès
2019-05-24 13:42 ` [bug#35880] [PATCH 1/7] lzlib: Add 'make-lzip-input-port/compressed' Ludovic Courtès
2019-05-24 13:42 ` [bug#35880] [PATCH 2/7] utils: Test 'compressed-port' and 'decompressed-port' for both gzip and xz Ludovic Courtès
2019-05-24 13:42 ` Ludovic Courtès [this message]
2019-05-25 17:27 ` [bug#35880] [PATCH 3/7] utils: Support compression and decompression with lzip Pierre Neidhardt
2019-05-26 19:52 ` Ludovic Courtès
2019-05-24 13:42 ` [bug#35880] [PATCH 4/7] publish: Add support for lzip Ludovic Courtès
2019-05-24 13:42 ` [bug#35880] [PATCH 5/7] self: Add dependency on lzlib Ludovic Courtès
2019-05-24 13:42 ` [bug#35880] [PATCH 6/7] gnu: guix: " Ludovic Courtès
2019-05-24 13:42 ` [bug#35880] [PATCH 7/7] lzlib: 'lzread!' never returns more than it was asked for Ludovic Courtès
2019-05-25 17:31 ` Pierre Neidhardt
2019-05-26 19:54 ` Ludovic Courtès
2019-05-26 20:57 ` Pierre Neidhardt
2019-05-26 21:28 ` Ludovic Courtès
2019-05-27 7:00 ` Pierre Neidhardt
2019-05-27 10:00 ` Ludovic Courtès
2019-05-25 17:24 ` [bug#35880] [PATCH 1/7] lzlib: Add 'make-lzip-input-port/compressed' Pierre Neidhardt
2019-05-26 19:51 ` Ludovic Courtès
2019-05-27 15:45 ` Ludovic Courtès
2019-05-27 16:24 ` Pierre Neidhardt
2019-05-27 20:53 ` bug#35880: " Ludovic Courtès
2019-05-27 21:12 ` [bug#35880] " Pierre Neidhardt
2019-05-28 7:52 ` Ludovic Courtès
2019-05-28 8:46 ` Pierre Neidhardt
2019-05-28 13:47 ` Ludovic Courtès
2019-05-29 14:57 ` Pierre Neidhardt
2019-05-31 20:54 ` Ludovic Courtès
2019-06-01 6:02 ` Pierre Neidhardt
2019-06-01 9:41 ` Ludovic Courtès
2019-06-01 9:58 ` Pierre Neidhardt
2019-06-01 12:21 ` Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190524134238.22802-3-ludo@gnu.org \
--to=ludo@gnu.org \
--cc=35880@debbugs.gnu.org \
--cc=mail@ambrevar.xyz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).