package tiny_httpd

  1. Overview
  2. Docs

Module IO.InputSource

Input channel (byte source)

include module type of struct include Iostream.In_buf end
Sourceclass type t = object ... end

The implementation of buffered input streams.

Sourceclass virtual t_from_refill : ?bytes:bytes -> unit -> object ... end

A mixin to implement a buffered input by only providing a refill method. Add a close method and it's good to go.

Sourceval create : ?bytes:bytes -> ?close:(unit -> unit) -> refill:(bytes -> int) -> unit -> t

Create a new buffered input stream.

  • parameter refill

    will be called to refill the content of the bytes, returning how many bytes were added (starting at offset 0).

  • parameter buf

    the underlying buffer

Sourceclass of_bytes : ?off:int -> ?len:int -> bytes -> t
Sourceval of_bytes : ?off:int -> ?len:int -> bytes -> t
Sourceclass of_string : ?off:int -> ?len:int -> string -> t
Sourceval of_string : ?off:int -> ?len:int -> string -> t
Sourceclass bufferized : ?bytes:bytes -> Iostream.In.t -> t
Sourceval bufferized : ?bytes:bytes -> Iostream.In.t -> t

Read from the given buffer.

  • parameter off

    initial offset (default 0)

  • parameter len

    length of the slice in the bytes. (default all available bytes from offset)

Sourceclass of_in_channel : ?bytes:bytes -> in_channel -> t
Sourceval of_in_channel : ?bytes:bytes -> in_channel -> t

Wrap a standard input channel.

Sourceclass open_file : ?bytes:bytes -> ?mode:int -> ?flags:open_flag list -> string -> t
Sourceval open_file : ?bytes:bytes -> ?mode:int -> ?flags:open_flag list -> string -> t
Sourceval with_open_file : ?bytes:bytes -> ?mode:int -> ?flags:open_flag list -> string -> (t -> 'a) -> 'a
Sourceval fill_buf : t -> Iostream.Slice.t

fill_buffer bic returns a slice into bic's internal buffer, and ensures it's empty only if bic.ic is empty.

Sourceval of_in : ?bytes:bytes -> Iostream.In.t -> t

Make a buffered version of the input stream.

  • parameter bytes

    the buffer to use.

Sourceval consume : t -> int -> unit

consume bic n consumes n bytes from bic. Precondition: n <= get_len bic, ie. one cannot consume bytes that have not yet been obtained via fill_buffer or fill_and_get.

Sourceval into_in : t -> Iostream.In.t

Cast into a In.t. This doesn't allocate.

Sourceval input_all_into_buffer : t -> Buffer.t -> unit

Read the whole content into the given buffer.

Sourceval input_all : ?buf:bytes -> t -> string

input_all ic reads the whole content of ic into a string.

  • parameter buf

    the initial buffer to use internally.

  • since 0.2
Sourceval copy_into : t -> Iostream.Out.t -> unit

Copy the entire stream into the given output.

Sourceval skip : t -> int -> unit

skip ic n reads and dicards the next n bytes in ic.

Sourceval input_line : ?buffer:Buffer.t -> t -> string option

Read a line from the input. Return None if the stream is empty.

  • parameter buffer

    a buffer to use to hold the line.

Sourceval input_lines : ?buffer:Buffer.t -> t -> string list

Read all lines from the input.

Sourceval to_iter : t -> (char -> unit) -> unit
Sourceval to_seq : t -> char Seq.t
Sourceval of_seq : ?bytes:bytes -> char Seq.t -> t
Sourceval of_unix_fd : ?close_noerr:bool -> closed:bool ref -> buf:Slice.t -> Unix.file_descr -> t
Sourceval of_slice : Slice.t -> t
Sourceval input : t -> bytes -> int -> int -> int

Read into the given slice.

  • returns

    the number of bytes read, 0 means end of input.

Sourceval close : < close : unit -> unit.. > -> unit

Close the channel.

Sourceval really_input : t -> bytes -> int -> int -> unit

Read exactly len bytes.

  • raises End_of_file

    if the input did not contain enough data.

Sourceval iter_slice : (Slice.t -> unit) -> t -> unit
Sourceval iter : (bytes -> int -> int -> unit) -> t -> unit
Sourceval to_chan : out_channel -> t -> unit
Sourceval to_chan' : Iostream.Out.t -> t -> unit
Sourceval read_all_using : buf:Buf.t -> t -> string
Sourceval read_exactly_ : too_short:(unit -> unit) -> t -> bytes -> int -> unit

Read n bytes from the input into bytes.

Sourceval read_line_into : t -> buf:Buf.t -> unit

read a line into the buffer, after clearing it.

Sourceval read_line_using : buf:Buf.t -> t -> string
Sourceval read_line_using_opt : buf:Buf.t -> t -> string option
Sourceval reading_exactly_ : skip_on_close:bool -> close_rec:bool -> size:int -> bytes:bytes -> t -> t
Sourceval limit_size_to : close_rec:bool -> max_size:int -> bytes:bytes -> t -> t

new stream with maximum size max_size.

  • parameter close_rec

    if true, closing this will also close the input stream

Sourceval reading_exactly : close_rec:bool -> size:int -> bytes:bytes -> t -> t

New stream that consumes exactly size bytes from the input. If fewer bytes are read before close is called, we read and discard the remaining quota of bytes before close returns.

  • parameter close_rec

    if true, closing this will also close the input stream

Sourceval read_chunked : bytes:bytes -> fail:(string -> exn) -> t -> t
Sourceval output_chunked' : ?buf:Buf.t -> Iostream.Out_buf.t -> t -> unit

Output a stream using chunked encoding

Sourceval output_chunked : ?buf:Buf.t -> out_channel -> t -> unit

print a stream as a series of chunks