compression.scm 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2022 Mathieu Othacehe <othacehe@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (gnu compression)
  19. #:use-module (guix gexp)
  20. #:use-module (guix ui)
  21. #:use-module ((gnu packages compression) #:hide (zip))
  22. #:use-module (srfi srfi-1)
  23. #:use-module (srfi srfi-9)
  24. #:use-module (ice-9 match)
  25. #:export (compressor
  26. compressor?
  27. compressor-name
  28. compressor-extension
  29. compressor-command
  30. %compressors
  31. lookup-compressor))
  32. ;; Type of a compression tool.
  33. (define-record-type <compressor>
  34. (compressor name extension command)
  35. compressor?
  36. (name compressor-name) ;string (e.g., "gzip")
  37. (extension compressor-extension) ;string (e.g., ".lz")
  38. (command compressor-command)) ;gexp (e.g., #~(list "/gnu/store/…/gzip"
  39. ; "-9n" ))
  40. (define %compressors
  41. ;; Available compression tools.
  42. (list (compressor "gzip" ".gz"
  43. #~(list #+(file-append gzip "/bin/gzip") "-9n"))
  44. (compressor "lzip" ".lz"
  45. #~(list #+(file-append lzip "/bin/lzip") "-9"))
  46. (compressor "xz" ".xz"
  47. #~(append (list #+(file-append xz "/bin/xz")
  48. "-e")
  49. (%xz-parallel-args)))
  50. (compressor "bzip2" ".bz2"
  51. #~(list #+(file-append bzip2 "/bin/bzip2") "-9"))
  52. (compressor "zstd" ".zst"
  53. ;; The default level 3 compresses better than gzip in a
  54. ;; fraction of the time, while the highest level 19
  55. ;; (de)compresses more slowly and worse than xz.
  56. #~(list #+(file-append zstd "/bin/zstd") "-3"))
  57. (compressor "none" "" #f)))
  58. (define (lookup-compressor name)
  59. "Return the compressor object called NAME. Error out if it could not be
  60. found."
  61. (or (find (match-lambda
  62. (($ <compressor> name*)
  63. (string=? name* name)))
  64. %compressors)
  65. (leave (G_ "~a: compressor not found~%") name)))