Skip to content

Commit

Permalink
Support eio>=0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
samoht committed Nov 3, 2023
1 parent a1cbf1e commit fdd7302
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
16 changes: 8 additions & 8 deletions eio/tar_eio.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Monad = struct
end

module Reader = struct
type in_channel = Flow.source
type in_channel = Flow.source_ty Resource.t
type 'a t = 'a
let really_read f b = Flow.read_exact f b
let skip f (n: int) =
Expand All @@ -43,7 +43,7 @@ end
let really_read = Reader.really_read

module Writer = struct
type out_channel = Flow.sink
type out_channel = Flow.sink_ty Resource.t
type 'a t = 'a
let really_write f b = Flow.write f [ b ]
end
Expand All @@ -66,7 +66,7 @@ module HR = Tar.HeaderReader(Monad)(Reader)
module HW = Tar.HeaderWriter(Monad)(Writer)

let get_next_header ?level ~global ic =
match HR.read ?level ~global (ic :> Flow.source) with
match HR.read ?level ~global ic with
| Error `Eof -> None
| Ok hdrs -> Some hdrs

Expand Down Expand Up @@ -95,8 +95,8 @@ let header_of_file ?level ?getpwuid ?getgrgid filepath : Tar.Header.t =
Tar.Header.make ~file_mode ~user_id ~group_id ~mod_time ~link_indicator ~link_name
?uname ?gname ~devmajor ~devminor (snd filepath) file_size

let write_block ?level ?global (header: Tar.Header.t) (body: #Flow.sink -> unit) sink =
HW.write ?level ?global header (sink :> Flow.sink);
let write_block ?level ?global (header: Tar.Header.t) body sink =
HW.write ?level ?global header sink;
body sink;
really_write sink (Tar.Header.zero_padding header)

Expand All @@ -111,7 +111,7 @@ module Archive = struct
should leave the fd positioned immediately after the datablock. Finally the function
skips past the zero padding to the next header *)
let with_next_file src ~(global: Tar.Header.Extended.t option)
(f: Eio.Flow.source -> Tar.Header.Extended.t option -> Tar.Header.t -> 'a) =
(f: _ -> Tar.Header.Extended.t option -> Tar.Header.t -> 'a) =
match get_next_header ~global src with
| Some (hdr, global) ->
let result = f src global hdr in
Expand All @@ -123,7 +123,7 @@ module Archive = struct
(** List the contents of a tar *)
let list ?level fd =
let rec loop global acc =
match get_next_header ?level ~global (fd :> Flow.source) with
match get_next_header ?level ~global fd with
| None -> List.rev acc
| Some (hdr, global) ->
Reader.skip fd (Int64.to_int hdr.Tar.Header.file_size);
Expand All @@ -145,7 +145,7 @@ module Archive = struct
in
loop None ()

let transform ?level f (ifd : #Flow.source) (ofd : #Flow.sink) =
let transform ?level f ifd ofd =
let rec loop global () =
match get_next_header ~global ifd with
| None -> ()
Expand Down
18 changes: 9 additions & 9 deletions eio/tar_eio.mli
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
zero-filled blocks are discovered. Assumes stream is positioned at the
possible start of a header block.
@raise End_of_file if the stream unexpectedly fails. *)
val get_next_header : ?level:Tar.Header.compatibility -> global:Tar.Header.Extended.t option -> Eio.Flow.source ->
val get_next_header : ?level:Tar.Header.compatibility -> global:Tar.Header.Extended.t option -> Eio.Flow.source_ty Eio.Resource.t ->
(Tar.Header.t * Tar.Header.Extended.t option) option

(** Return the header needed for a particular file on disk. [getpwuid] and [getgrgid] are optional
Expand All @@ -30,7 +30,7 @@ val header_of_file :
?level:Tar.Header.compatibility ->
?getpwuid:(int64 -> string) ->
?getgrgid:(int64 -> string) ->
Eio.Fs.dir Eio.Path.t ->
Eio.Fs.dir_ty Eio.Path.t ->
Tar.Header.t

module Archive : sig
Expand All @@ -39,31 +39,31 @@ module Archive : sig
(** Read the next header, apply the function 'f' to the source and the header. The function
should leave the source positioned immediately after the datablock. Finally the function
skips past the zero padding to the next header. *)
val with_next_file : Eio.Flow.source -> global:Tar.Header.Extended.t option ->
(Eio.Flow.source -> Tar.Header.Extended.t option -> Tar.Header.t -> 'a) -> 'a option
val with_next_file : Eio.Flow.source_ty Eio.Resource.t -> global:Tar.Header.Extended.t option ->
(Eio.Flow.source_ty Eio.Resource.t -> Tar.Header.Extended.t option -> Tar.Header.t -> 'a) -> 'a option

(** List the contents of a tar to stdout. *)
val list : ?level:Tar.Header.compatibility -> #Eio.Flow.source -> Tar.Header.t list
val list : ?level:Tar.Header.compatibility -> Eio.Flow.source_ty Eio.Resource.t -> Tar.Header.t list

(** [extract dest] extract the contents of a tar.
Apply [dest] on each source filename to change the destination
filename. It only supports extracting regular files from the
top-level of the archive. *)
val extract : (string -> Eio.Fs.dir Eio.Path.t) -> Eio.Flow.source -> unit
val extract : (string -> Eio.Fs.dir_ty Eio.Path.t) -> Eio.Flow.source_ty Eio.Resource.t -> unit

(** [transform f src sink] applies [f] to the header of each
file in the tar inputted in [src], and writes the resulting
headers to [sink] preserving the content and structure of the
archive. *)
val transform : ?level:Tar.Header.compatibility -> (Tar.Header.t -> Tar.Header.t) -> #Eio.Flow.source -> #Eio.Flow.sink -> unit
val transform : ?level:Tar.Header.compatibility -> (Tar.Header.t -> Tar.Header.t) -> Eio.Flow.source_ty Eio.Resource.t -> Eio.Flow.sink_ty Eio.Resource.t -> unit

(** Create a tar in the sink from a list of file paths. It only supports regular files.
See {! header_of_file} for the meaning of [getpwuid] and [getgrgid]. *)
val create :
?getpwuid:(int64 -> string) ->
?getgrgid:(int64 -> string) ->
Eio.Fs.dir Eio.Path.t list ->
#Eio.Flow.sink ->
Eio.Fs.dir_ty Eio.Path.t list ->
Eio.Flow.sink_ty Eio.Resource.t ->
unit
end
2 changes: 1 addition & 1 deletion tar-eio.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bug-reports: "https://github.com/mirage/ocaml-tar/issues"
depends: [
"dune" {>= "2.9"}
"ocaml" {>= "4.08.0"}
"eio" {>= "0.10.0" & < "0.12"}
"eio" {>= "0.12"}
"tar" {= version}
"odoc" {with-doc}
]
Expand Down

0 comments on commit fdd7302

Please sign in to comment.