Skip to content

Commit

Permalink
proposed API
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesm committed Feb 3, 2024
1 parent 489bd71 commit d24ba4c
Showing 1 changed file with 37 additions and 11 deletions.
48 changes: 37 additions & 11 deletions unix/tar_unix.mli
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,44 @@

(** Unix I/O for tar-formatted data. *)

(** Return the header needed for a particular file on disk. *)
val header_of_file : ?level:Tar.Header.compatibility -> string -> Tar.Header.t

(** Fold over a tar archive. *)
val fold_tar :
((Tar.Header.t * Tar.Header.Extended.t option,
(** [fold f filename acc] folds over the tar archive. The function [f] is called
for each [hdr : Tar.Header.t]. It should forward the position in the file
descriptor by [hdr.Tar.Header.file_size]. *)
val fold :
((Unix.file_descr * Tar.Header.t * Tar.Header.Extended.t option,
[
| `Eof
| `Fatal of [ `Checksum_mismatch | `Corrupt_pax_header | `Unmarshal of string ]
| `Unix of Unix.error
| `Unix of Unix.error * string * string
| `End_of_file
]) result -> 'a -> 'a) ->
Unix.file_descr ->
'a -> 'a
string -> 'a -> 'a

(** [extract ~src ~dst] extracts the tar archive [src] into the directory [dst].
If [dst] does not exist, it is created. *)
val extract : src:string -> dst:string ->
(unit, [ `Fatal of [ `Checksum_mismatch | `Corrupt_pax_header | `Unmarshal of string ]
| `Unix of Unix.error ]) result

(** [create ~level ~src ~dst] creates a tar archive at [dst]. It uses [src], a
filename or directory name, as input. *)
val create : ?level:Tar.Header.compatibility -> src:string -> dst:string ->
(unit, [ `Msg of string | `Unix of Unix.error ]) result

(** [header_of_file ~level filename] returns the tar header of [filename]. *)
val header_of_file : ?level:Tar.Header.compatibility -> string -> Tar.Header.t

(** [append_file ~level ~header filename fd] appends the contents of [filename]
to the tar archive [fd]. If [header] is not provided, {header_of_file} is
used for constructing a header. *)
val append_file : ?level:Tar.Header.compatibility -> ?header:Tar.Header.t ->
string -> Unix.file_descr ->
(unit, [ `Msg of string | `Unix of Unix.error ]) result

(** [write_extended_header ~level hdr fd] writes the extended header [hdr] to
[fd]. *)
val write_extended_header : ?level:Tar.Header.compatibility ->
Tar.Header.Extended.t -> Unix.file_descr ->
(unit, [ `Msg of string | `Unix of Unix.error ]) result

val append_file : ?header:Tar.Header.t -> string ->
(** [write_end fd] writes the tar end marker to [fd]. *)
val write_end : Unix.file_descr -> (unit, Unix.error) result

0 comments on commit d24ba4c

Please sign in to comment.