package tar

  1. Overview
  2. Docs

Parameters

module Async : Tar.ASYNC
module Writer : Tar.WRITER with type 'a t = 'a Async.t
module Reader : READER with type 'a t = 'a Async.t

Signature

type in_channel
val of_in_channel : internal:Cstruct.t -> Reader.in_channel -> in_channel
val get_next_header : ?level:Tar.Header.compatibility -> in_channel -> Tar.Header.t Async.t

Returns the next header block or fails with Tar.Header.End_of_stream if two consecutive zero-filled blocks are discovered. Assumes stream is positioned at the possible start of a header block.

  • raises Stdlib.End_of_file

    if the stream unexpectedly fails.

val really_read : in_channel -> Cstruct.t -> unit Async.t

really_read fd buf fills buf with data from fd or raises Stdlib.End_of_file.

val skip : in_channel -> int -> unit Async.t
type out_channel
val of_out_channel : ?bits:int -> ?q:int -> level:int -> mtime:int32 -> Gz.os -> Writer.out_channel -> out_channel
val write_block : ?level:Tar.Header.compatibility -> Tar.Header.t -> out_channel -> (unit -> string option Async.t) -> unit Async.t

write_block hdr oc stream writes hdr, then deflate the given stream, then zero-pads so the stream is positionned for the next block.

A simple usage to write a file:

let stream_of_fd fd =
  let buf = Bytes.create 0x1000 in
  fun () -> match Unix.read fd buf 0 (Bytes.length buf) with
  | 0 -> None
  | len -> Some (Bytes.sub_string buf 0 len)
  | exception End_of_file -> None

let add_file oc filename =
  let fd = Unix.openfile filename Unix.[ O_RDONLY ] 0o644 in
  let hdr = Tar.Header.make ... in
  write_block hdr oc (stream_of_fd fd) ;
  Unix.close fd
val write_end : out_channel -> unit Async.t

write_end oc writes a stream terminator to oc.