Merge pull request 'Add the compression level argument into to_octets' (#31) from level into main
Reviewed-on: #31
This commit is contained in:
commit
08a8a8a399
3 changed files with 10 additions and 7 deletions
|
@ -12,7 +12,8 @@ depends: [
|
||||||
"dune" {>= "2.9.0"}
|
"dune" {>= "2.9.0"}
|
||||||
"git" {>= "3.10.0"}
|
"git" {>= "3.10.0"}
|
||||||
"mirage-kv" {>= "6.0.0"}
|
"mirage-kv" {>= "6.0.0"}
|
||||||
"carton" {>= "0.6.0"}
|
"carton" {>= "0.7.0"}
|
||||||
|
"carton-lwt" {>= "0.7.0"}
|
||||||
"fmt" {>= "0.8.7"}
|
"fmt" {>= "0.8.7"}
|
||||||
"mirage-clock" {>= "2.0.0"}
|
"mirage-clock" {>= "2.0.0"}
|
||||||
"ptime"
|
"ptime"
|
||||||
|
|
|
@ -183,7 +183,7 @@ let ( >>? ) x f = let open Lwt.Infix in match x with
|
||||||
| None -> Lwt.return_none
|
| None -> Lwt.return_none
|
||||||
let ( >>! ) x f = Lwt.Infix.(x >>= f)
|
let ( >>! ) x f = Lwt.Infix.(x >>= f)
|
||||||
|
|
||||||
let pack t ~commit stream =
|
let pack t ?(level= 4) ~commit stream =
|
||||||
let open Lwt.Infix in
|
let open Lwt.Infix in
|
||||||
let load t hash =
|
let load t hash =
|
||||||
Store.read_inflated t hash >|= function
|
Store.read_inflated t hash >|= function
|
||||||
|
@ -227,7 +227,7 @@ let pack t ~commit stream =
|
||||||
| Some None -> failwith "Try to encode an OBJ_REF object" (* XXX(dinosaure): should never occur! *)
|
| Some None -> failwith "Try to encode an OBJ_REF object" (* XXX(dinosaure): should never occur! *)
|
||||||
| Some (Some (_ (* offset *) : int)) | None ->
|
| Some (Some (_ (* offset *) : int)) | None ->
|
||||||
Hashtbl.add offsets (Carton.Enc.target_uid targets.(idx)) !cursor ;
|
Hashtbl.add offsets (Carton.Enc.target_uid targets.(idx)) !cursor ;
|
||||||
Carton_lwt.Enc.encode_target ~b ~find ~load:(load t) ~uid targets.(idx) ~cursor:(Int64.to_int !cursor)
|
Carton_lwt.Enc.encode_target ~level ~b ~find ~load:(load t) ~uid targets.(idx) ~cursor:(Int64.to_int !cursor)
|
||||||
>>= fun (len, encoder) ->
|
>>= fun (len, encoder) ->
|
||||||
let payload = Bigstringaf.substring b.o ~off:0 ~len in
|
let payload = Bigstringaf.substring b.o ~off:0 ~len in
|
||||||
stream (Some payload) ;
|
stream (Some payload) ;
|
||||||
|
@ -254,7 +254,7 @@ let pack t ~commit stream =
|
||||||
stream None ;
|
stream None ;
|
||||||
Lwt.return_unit
|
Lwt.return_unit
|
||||||
|
|
||||||
let to_octets t = match t.head with
|
let to_octets ?level t = match t.head with
|
||||||
| None ->
|
| None ->
|
||||||
Lwt.return "PACK\000\000\000\002\000\000\000\000\
|
Lwt.return "PACK\000\000\000\002\000\000\000\000\
|
||||||
\x02\x9d\x08\x82\x3b\xd8\xa8\xea\xb5\x10\xad\x6a\xc7\x5c\x82\x3c\xfd\x3e\xd3\x1e"
|
\x02\x9d\x08\x82\x3b\xd8\xa8\xea\xb5\x10\xad\x6a\xc7\x5c\x82\x3c\xfd\x3e\xd3\x1e"
|
||||||
|
@ -262,7 +262,7 @@ let to_octets t = match t.head with
|
||||||
let buf = Buffer.create 0x100 in
|
let buf = Buffer.create 0x100 in
|
||||||
let stream = Option.iter (Buffer.add_string buf) in
|
let stream = Option.iter (Buffer.add_string buf) in
|
||||||
let open Lwt.Infix in
|
let open Lwt.Infix in
|
||||||
pack t.store ~commit stream >|= fun () ->
|
pack ?level t.store ~commit stream >|= fun () ->
|
||||||
Buffer.contents buf
|
Buffer.contents buf
|
||||||
|
|
||||||
(* XXX(dinosaure): we have the full-control between [to_octets]/[of_octets]
|
(* XXX(dinosaure): we have the full-control between [to_octets]/[of_octets]
|
||||||
|
|
|
@ -43,8 +43,10 @@ val connect : Mimic.ctx -> string -> t Lwt.t
|
||||||
val branch : t -> Git.Reference.t
|
val branch : t -> Git.Reference.t
|
||||||
(** [branch t] returns the branch used by the given [t]. *)
|
(** [branch t] returns the branch used by the given [t]. *)
|
||||||
|
|
||||||
val to_octets : t -> string Lwt.t
|
val to_octets : ?level:int -> t -> string Lwt.t
|
||||||
(** [to_octets store] returns a serialized version of the given [store]. *)
|
(** [to_octets ?level store] returns a serialized version of the given [store].
|
||||||
|
[level] is the {i zlib} level compression used for Git object (between [0]
|
||||||
|
and [9] including), defaults to [4]. *)
|
||||||
|
|
||||||
val of_octets : Mimic.ctx -> remote:string -> string ->
|
val of_octets : Mimic.ctx -> remote:string -> string ->
|
||||||
(t, [> `Msg of string]) result Lwt.t
|
(t, [> `Msg of string]) result Lwt.t
|
||||||
|
|
Loading…
Reference in a new issue