Module Bi_inbuf
Input buffer
type t={mutable i_s : bytes;This is the buffer string. It can be accessed for reading but should normally only be written to or replaced only by the
i_refillfunction.mutable i_pos : int;This is the current position in the input buffer. All data before that may be erased at anytime.
mutable i_len : int;This is the position of the first byte of invalid input data. Data starting at
i_posand ending ati_len-1is considered valid input data that is available to the user. Beware that calls totry_preread,readand other read functions may move data around and therefore modify the values ofi_posandi_lenin order to keep pointing to the correct data segment.mutable i_offs : int;Length of data read and discarded from the buffer. This indicates the position in the input stream of the first byte of the buffer. The current position in the input stream is
i_offs + i_pos. The total length of input stream data put into the buffer isi_offs + i_len.mutable i_max_len : int;This is the length of
i_s.i_refill : t -> int -> unit;Function called when not enough data is available in the buffer. The int argument is the total number of bytes that must be available starting at position
i_poswhen the function returns. This function typically does nothing if all input data already has been placed into the buffer. Thei_posandi_lenfields can be modified thei_refillfunction, as long as the available data that was starting fromi_posstill starts from the new value ofi_pos. All the other fields can be modified as well.i_shared : Bi_share.Rd.tbl;Hash table used to map positions in the input stream to shared objects (if any).
}
exceptionEnd_of_inputException raised by all the functions of this module when it is not possible to return a valid result because there is not enough data to read from the buffer.
val try_preread : t -> int -> inttry_preread ib nmake at leastnbytes available for reading inib.i_s, unless the end of the input is reached. The result indicates how many bytes were made available. If smaller thann, the result indicates that the end of the input was reached.ib.i_posis set to point to the first available byte.
val read : t -> int -> intread ib nmakes at leastnbytes available for reading or raises theEnd_of_inputexception. The result is the position of the first available byte.ib.i_posis moved to point to the next position after thenbytes.- raises End_of_input
if there is less than
nbytes before the end of input.
val read_char : t -> charRead just one byte.
- raises End_of_input
if the end of input has already been reached.
val peek : t -> charReturn the next byte without moving forward.
- raises End_of_input
if the end of input has already been reached.
val from_string : ?pos:int -> ?shrlen:int -> string -> tCreate an input buffer from a string.
- parameter pos
position to start from. Default: 0.
- parameter shrlen
initial length of the table used to store shared values.
val from_bytes : ?pos:int -> ?shrlen:int -> bytes -> tCreate an input buffer from bytes.
- parameter pos
position to start from. Default: 0.
- parameter shrlen
initial length of the table used to store shared values.
- since
- 1.2.0
val from_channel : ?len:int -> ?shrlen:int -> Stdlib.in_channel -> tCreate an input buffer from an in_channel. Such a buffer is not extensible and
readrequests may not exceedlen.- parameter len
buffer length.
- parameter shrlen
initial length of the table used to store shared values.