From bb03b78fab03e9eb7186c45d33d23735650351ec Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Mon, 26 Feb 2024 13:12:08 -0500 Subject: [PATCH] add In_buf.skip --- src/core/in_buf.ml | 9 +++++++++ src/core/in_buf.mli | 3 +++ 2 files changed, 12 insertions(+) diff --git a/src/core/in_buf.ml b/src/core/in_buf.ml index 7fd6be2f..34ec6a29 100644 --- a/src/core/in_buf.ml +++ b/src/core/in_buf.ml @@ -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 diff --git a/src/core/in_buf.mli b/src/core/in_buf.mli index 219dc974..2f89bf6c 100644 --- a/src/core/in_buf.mli +++ b/src/core/in_buf.mli @@ -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. *)