From: Ralf Treinen <treinen@debian.org>
Date: Sun, 3 Jun 2018 10:47:27 +0200
Subject: Accept input from xz-compressed files

---
 common/input.ml            | 13 +++++++++++--
 doc/manpages/distcheck.pod |  4 ++--
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/common/input.ml b/common/input.ml
index 9bd639b..49f8fc4 100644
--- a/common/input.ml
+++ b/common/input.ml
@@ -29,7 +29,16 @@ let gzip_open_file file =
     fatal "gzip not supported. re-configure with --with-zip"
 #endif
 ;;
-
+    
+let xz_open_file file =
+  let ch = Unix.open_process_in ("xzcat "^ file) in
+  let read ch = try input ch with End_of_file -> raise IO.No_more_input in
+  IO.create_in
+  ~read:(fun () -> input_char ch)
+  ~input:(read ch)
+  ~close:(fun () -> close_in ch)
+;;
+  
 let bzip_open_file file =
 #ifdef HASBZ2
   (* workaround to avoid segfault :
@@ -85,7 +94,7 @@ let open_file file =
               | 0x37 -> (match input_byte ch with
                   | 0x7a -> (match input_byte ch with
                       | 0x58 -> (match input_byte ch with
-                          | 0x5a -> fatal "xz not supported."
+                          | 0x5a -> xz_open_file
                           | _ -> std_open_file)
                       | _ -> std_open_file)
                   | _ -> std_open_file)
diff --git a/doc/manpages/distcheck.pod b/doc/manpages/distcheck.pod
index 54c160a..c212e2a 100644
--- a/doc/manpages/distcheck.pod
+++ b/doc/manpages/distcheck.pod
@@ -231,13 +231,13 @@ B<opam>
 =item .
 
 B<deb> for Debian binary package files, also known as Packages files. Possibly
-compressed with L<gzip(1)> or L<bzip2(1)>, depending on compile-time options
+compressed with L<gzip(1)>, L<bzip2(1)> or L<xz(1)>, depending on compile-time options
 for dose3.
 
 =item .
 
 B<debsrc> for Debian source package files, also knows as Sources files.
-Possibly compressed with L<gzip(1)> or L<bzip2(1)>, depending on compile-time
+Possibly compressed with L<gzip(1)>, L<bzip2(1)> or L<xz>(1), depending on compile-time
 options for dose3.
 
 =item .
