diff --git a/.merlin b/.merlin index e0b470512..dcba6fdd1 100644 --- a/.merlin +++ b/.merlin @@ -1,5 +1,5 @@ PKG cstruct logs ocamlgraph re zip uri lwt mstruct cmdliner mirage-types PKG nocrypto hex cohttp.lwt mirage-flow tcpip mirage-http alcotest fmt -PKG crc mirage-fs-unix astring mtime.os +PKG crc mirage-fs-unix astring mtime.os decompress B _build/** -S lib/ \ No newline at end of file +S lib/ diff --git a/_oasis b/_oasis index 52862b198..9cd550c71 100644 --- a/_oasis +++ b/_oasis @@ -26,7 +26,7 @@ Library git Sync, Gri, Search, Global_graph, User, Store, Memory, FS, Version BuildDepends: mstruct, logs, ocamlgraph, uri, lwt, hex, astring, - crc, fmt + crc, fmt, decompress Library git_top Path: lib/top diff --git a/_tags b/_tags index e138e1355..3124ff563 100644 --- a/_tags +++ b/_tags @@ -1,5 +1,5 @@ # OASIS_START -# DO NOT EDIT (digest: 1f887a5c66fe18fa975c85eb35845de1) +# DO NOT EDIT (digest: 90381a679a56d9478299f2b1bc256f13) # Ignore VCS directories, you can use the same kind of rule outside # OASIS_START/STOP if you want to exclude directories that contains # useless stuff for the build process @@ -44,6 +44,7 @@ true: annot, bin_annot "lib/LRU.cmx": for-pack(Git) : pkg_astring : pkg_crc +: pkg_decompress : pkg_fmt : pkg_hex : pkg_logs @@ -59,6 +60,7 @@ true: annot, bin_annot : pkg_astring : pkg_cohttp.lwt : pkg_crc +: pkg_decompress : pkg_fmt : pkg_hex : pkg_logs @@ -74,6 +76,7 @@ true: annot, bin_annot : pkg_cohttp.lwt : pkg_conduit.lwt-unix : pkg_crc +: pkg_decompress : pkg_fmt : pkg_hex : pkg_logs @@ -94,6 +97,7 @@ true: annot, bin_annot : pkg_cohttp.lwt : pkg_conduit.mirage : pkg_crc +: pkg_decompress : pkg_dns.mirage : pkg_fmt : pkg_hex @@ -115,6 +119,7 @@ true: annot, bin_annot : pkg_cohttp.lwt : pkg_conduit.lwt-unix : pkg_crc +: pkg_decompress : pkg_fmt : pkg_fmt.cli : pkg_fmt.tty @@ -139,6 +144,7 @@ true: annot, bin_annot : pkg_cohttp.lwt : pkg_conduit.lwt-unix : pkg_crc +: pkg_decompress : pkg_fmt : pkg_fmt.cli : pkg_fmt.tty @@ -166,6 +172,7 @@ true: annot, bin_annot : pkg_conduit.lwt-unix : pkg_conduit.mirage : pkg_crc +: pkg_decompress : pkg_dns.mirage : pkg_fmt : pkg_fmt.tty @@ -198,6 +205,7 @@ true: annot, bin_annot : pkg_conduit.lwt-unix : pkg_conduit.mirage : pkg_crc +: pkg_decompress : pkg_dns.mirage : pkg_fmt : pkg_fmt.tty diff --git a/lib/META b/lib/META index 52cc8a584..a32909db3 100644 --- a/lib/META +++ b/lib/META @@ -1,8 +1,8 @@ # OASIS_START -# DO NOT EDIT (digest: a01af07d306c69a55a64dfda6f7e4240) +# DO NOT EDIT (digest: 5b0fd45ae655f8f13a94f5d02d4681e8) version = "1.8.0" description = "A low-level interface to Git in pure OCaml" -requires = "mstruct logs ocamlgraph uri lwt hex astring crc fmt" +requires = "mstruct logs ocamlgraph uri lwt hex astring crc fmt decompress" archive(byte) = "git.cma" archive(byte, plugin) = "git.cma" archive(native) = "git.cmxa" diff --git a/lib/inflate.ml b/lib/inflate.ml index c5ec24186..fcdc86a6d 100644 --- a/lib/inflate.ml +++ b/lib/inflate.ml @@ -156,3 +156,84 @@ module Make (Zlib: ZLIB) = struct None end + +module Decompress : S = +struct + module Inflate = Decompress.Inflate.Make(Decompress.ExtString)(Decompress.ExtBytes) + module Deflate = Decompress.Deflate.Make(Decompress.ExtString)(Decompress.ExtBytes) + + let deflate ?level buff = + let len = Cstruct.len buff in + let position = ref 0 in + + let input = Bytes.create 1024 in + let output = Bytes.create 1024 in + let buffer = Buffer.create (Cstruct.len buff) in + + let refill' _ = + let n = min (len - !position) 1024 in + Cstruct.blit_to_bytes buff !position input 0 n; + position := !position + n; + if !position >= len then true, n else false, n + in + + let flush' _ len = + Buffer.add_subbytes buffer output 0 len; + len + in + + Deflate.compress ?level (Bytes.unsafe_to_string input) output refill' flush'; + Cstruct.of_string (Buffer.contents buffer) + + let inflate ?output_size orig = + let buff = Mstruct.clone orig in + let output_size = + match output_size with + | None -> Mstruct.length orig + | Some s -> s + in + let input = Bytes.create 1024 in + let output = Bytes.create 1024 in + let buffer = Buffer.create output_size in + let s = ref 0 in + + let inflater = Inflate.make input output in + + let refill' () = + let n = min (Mstruct.length buff) 1024 in + let i = Mstruct.get_string buff n in + Bytes.blit i 0 input 0 n; + n + in + + let flush' len = + Buffer.add_subbytes buffer output 0 len; + len + in + + let len = refill' () in + Inflate.refill inflater len; + Inflate.flush inflater 1024; + + let rec aux () = match Inflate.eval inflater with + | `Ok -> + let drop = flush' (Inflate.contents inflater) in + s := !s + Inflate.used_in inflater; + Inflate.flush inflater drop + | `Flush -> + let drop = flush' (Inflate.contents inflater) in + Inflate.flush inflater drop; + aux () + | `Wait -> + let len = refill' () in + s := !s + Inflate.used_in inflater; + Inflate.refill inflater len; + aux () + | `Error -> failwith "Inflate.inflate" + in + + try aux (); + Mstruct.shift orig !s; + Some (Mstruct.of_string (Buffer.contents buffer)) + with _ -> None +end diff --git a/lib/inflate.mli b/lib/inflate.mli index 9132b09ce..8d74c0c15 100644 --- a/lib/inflate.mli +++ b/lib/inflate.mli @@ -49,3 +49,4 @@ module type ZLIB = sig end module Make (Z: ZLIB): S +module Decompress : S diff --git a/lib/unix/git_unix.ml b/lib/unix/git_unix.ml index f58a5a457..8d5f841e9 100644 --- a/lib/unix/git_unix.ml +++ b/lib/unix/git_unix.ml @@ -384,7 +384,7 @@ module IO_FS = struct end -module Zlib = Git.Inflate.Make(Zlib) +module Zlib = Git.Inflate.Decompress module SHA1 = struct @@ -440,7 +440,7 @@ module Make (D: Git.Hash.DIGEST) (I: Git.Inflate.S) = struct end -module M = Make(SHA1)(Zlib) +module M = Make(SHA1)(Git.Inflate.Decompress) include M module type S = sig diff --git a/opam b/opam index 4fc4e2777..b817ec04d 100644 --- a/opam +++ b/opam @@ -32,6 +32,7 @@ depends: [ "hex" "astring" "crc" + "decompress" {>= "0.4"} "alcotest" {test} "mirage-types-lwt" {test} "mirage-http" {test} diff --git a/setup.ml b/setup.ml index 84219c4dc..cfce47b03 100644 --- a/setup.ml +++ b/setup.ml @@ -1,7 +1,7 @@ (* setup.ml generated for the first time by OASIS v0.4.1 *) (* OASIS_START *) -(* DO NOT EDIT (digest: 72320e11d60d8e8c46b5b7f061dd57d1) *) +(* DO NOT EDIT (digest: 78a50bff56837dc12f31fd1a4a0bd3d1) *) (* Regenerated by OASIS v0.4.5 Visit http://oasis.forge.ocamlcore.org for more information and @@ -6955,7 +6955,8 @@ let setup_t = FindlibPackage ("hex", None); FindlibPackage ("astring", None); FindlibPackage ("crc", None); - FindlibPackage ("fmt", None) + FindlibPackage ("fmt", None); + FindlibPackage ("decompress", None) ]; bs_build_tools = [ExternalTool "ocamlbuild"]; bs_c_sources = []; @@ -7313,7 +7314,7 @@ let setup_t = }; oasis_fn = Some "_oasis"; oasis_version = "0.4.5"; - oasis_digest = Some ")ñq§T%2~¦ç\005\018)Úâ°"; + oasis_digest = Some "\146\255\227\198=\005aB\025VD\017\241o;I"; oasis_exec = None; oasis_setup_args = []; setup_update = false @@ -7321,6 +7322,6 @@ let setup_t = let setup () = BaseSetup.setup setup_t;; -# 7325 "setup.ml" +# 7326 "setup.ml" (* OASIS_STOP *) let () = setup ();;