Skip to content

Commit

Permalink
Add Tar_cstruct.read_zerocopy
Browse files Browse the repository at this point in the history
  • Loading branch information
reynir committed Jun 30, 2023
1 parent 7c20829 commit 1583f71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/tar_cstruct.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ module Cstruct_io = struct
let check_available ch len =
min (Cstruct.length ch.data - ch.pos) len

let read_zerocopy ic len =
if check_available ic len <> len then raise End_of_file;
let r = Cstruct.sub ic.data ic.pos len in
ic.pos <- ic.pos + len;
r

let really_read ic buf =
let len = Cstruct.length buf in
if check_available ic len <> len then raise End_of_file;
Expand Down
4 changes: 4 additions & 0 deletions lib/tar_cstruct.mli
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ val really_read : in_channel -> Cstruct.t -> unit
(** [really_read ic buf] fills [buf] with data from [ic] or raises
{!Stdlib.End_of_file} *)

val read_zerocopy : in_channel -> int -> Cstruct.t
(** [read_zerocopy ic len] updates the position and returns a sub cstruct of
[ic] or raises {!Stdlib.End_of_file} *)

val skip : in_channel -> int -> unit

val really_write : out_channel -> Cstruct.t -> unit
Expand Down

0 comments on commit 1583f71

Please sign in to comment.