package tar

  1. Overview
  2. Docs

Process and create tar file headers.

type compatibility =
  1. | OldGNU
    (*

    GNU tar < 1.12

    *)
  2. | GNU
    (*

    GNU tar 1.12 - 1.13.25

    *)
  3. | V7
    (*

    Origin 7th Release format

    *)
  4. | Ustar
    (*

    POSIX.1-1988

    *)
  5. | Posix
    (*

    POSIX.1-2001

    *)

tar format assumptions. Default is V7 (for compatibility with versions of ocaml-tar before this type was introduced).

val compatibility_level : compatibility Stdlib.ref

Default compatibility if ?level is omitted. Defaults to V7.

module Extended : sig ... end
type t = {
  1. file_name : string;
  2. file_mode : int;
  3. user_id : int;
  4. group_id : int;
  5. file_size : int64;
  6. mod_time : int64;
  7. uname : string;
  8. gname : string;
  9. devmajor : int;
  10. devminor : int;
  11. extended : Extended.t option;
}

Represents a standard archive (note checksum not stored).

Helper function to make a simple header.

val make : ?file_mode:int -> ?user_id:int -> ?group_id:int -> ?mod_time:int64 -> ?link_indicator:Link.t -> ?link_name:string -> ?uname:string -> ?gname:string -> ?devmajor:int -> ?devminor:int -> string -> int64 -> t

make file_name file_size creates a simple header. file_mode defaults to 0o400, user_id, group_id default to 0, mod_time defaults to 0L (epoch), link_indicator defaults to Normal, link_name, uname and gname default to "", and devmajor and devminor default to 0.

val length : int

Length of a header block.

val zero_block : Cstruct.t

A blank header block (two of these in series mark the end of the tar).

val to_detailed_string : t -> string

Pretty-print the header record.

val to_hex : string -> string

For debugging: pretty-print a string as hex.

exception Checksum_mismatch

Thrown when unmarshalling a header if the checksums don't match.

exception End_of_stream

Thrown if we detect the end of the tar (at least two zero blocks in sequence).

val unmarshal : ?level:compatibility -> ?extended:Extended.t -> Cstruct.t -> t option

Unmarshal a header block, returning None if it's all zeroes. This header block may be preceded by an ?extended block which will override some fields.

val marshal : ?level:compatibility -> Cstruct.t -> t -> unit

Marshal a header block, computing and inserting the checksum.

val compute_zero_padding_length : t -> int

Compute the amount of zero-padding required to round up the file size to a whole number of blocks.

val zero_padding : t -> Cstruct.t

Return the required zero-padding as a string.

val to_sectors : t -> int64

to_sectors t is the number of sectors occupied by the data.

OCaml

Innovation. Community. Security.