On Monday, 19 June 2017 10:48:37 CEST Cédric Bosdonnat wrote:
+let compress_to file outdir =
+ let outimg = outdir // (Filename.basename file) ^ ".xz" in
+
+ info "Compressing ...%!";
+ let cmd = sprintf "cat \"%s\" | xz -f --best --block-size=16777216 -
>\"%s\""
+ file outimg in
+ if shell_command cmd <> 0 then
+ exit 1;
This finally can now be:
let cmd = [ "xz"; "-f"; "--best";
"--block-size=16777216"; "-c"; file ] in
let file_flags = [ Unix.O_WRONLY; Unix.O_CREAT; Unix.O_TRUNC; ] in
let outfd = Unix.openfile outimg file_flags 0o666 in
let res = run_command cmd ~stdout_chan:outfd in
if res <> 0 then
error (f_"'xz' command failed");
Yes, slightly more verbose, but it avoids the shell, and the need for
proper quoting. It's also logged, and faster (since the whole data of
the disk is not read twice, once by cat, and once by xz via stdin).
Thanks,
--
Pino Toscano