Skip to content

Commit

Permalink
add In_buf.skip
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Feb 26, 2024
1 parent 907e5ac commit bb03b78
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/core/in_buf.ml
Expand Up @@ -255,3 +255,12 @@ let of_seq ?(bytes = Bytes.create _default_buf_size) seq : t =
bs.len <- loop 0
end
:> t)

let skip (self : #t) (n : int) : unit =
let n = ref n in
while !n > 0 do
let slice = fill_buf self in
let len = min !n slice.len in
Slice.consume slice len;
n := !n - len
done
3 changes: 3 additions & 0 deletions src/core/in_buf.mli
Expand Up @@ -113,6 +113,9 @@ val input_all : ?buf:bytes -> #t -> string
val copy_into : #t -> #Out.t -> unit
(** Copy the entire stream into the given output. *)

val skip : #t -> int -> unit
(** [skip ic n] reads and dicards the next [n] bytes in [ic]. *)

val input_line : ?buffer:Buffer.t -> #t -> string option
(** Read a line from the input. Return [None] if the stream is empty.
@param buffer a buffer to use to hold the line. *)
Expand Down

0 comments on commit bb03b78

Please sign in to comment.