Page
Library
Module
Module type
Parameter
Class
Class type
Source
Bytream.OutSourceOutgoing bytes stream module for streaming bytes to a sink in chunks.
Outgoing byte stream type.
Flatten bytes-oriented Bigarray buffer.
Note. The rationale for using bytes instead of BA is to transparently transfer memory between the OCaml runtime and external functions, which are necessary for working with input/output.
A byte chunk is a non-empty consecutive range of bytes in a buffer value.
make ?buffer_size writer
Construct an outgoing byte stream using the writer function to output chunks to a bytes sink.
Example
This example illustrates the basic concept of chunking.
(* Queue as a byte chunk sink. *)
let queue = Queue.create () in
(* Writer function that outputs chunks of text to the sink. *)
let writer (~buffer, ~length:len, ..) =
Queue.add Bstr.(sub_string ~off:0 ~len buffer) queue
in
Bytream.Out.make writerof_channel ?io_buffer_size oc make an outgoing stream from the channel.
Note. You can disable internal buffering for the channels to get the expected behavior: Out_channel.set_buffered oc false v.
with_into_string f make a stream that outgoing to buffer.
with_into_string f make a stream that outgoing to buffer and returns string value.
shift out_stream n
Shift the buffer's offset by n bytes to account for the written bytes.
writable_guard_bytes_at out_stream len
Guarantees that the buffer has enough space to write len bytes into it.
Example
let write_hello_record out_stream hello =
let off = Out.writable_guard_bytes_at out_stream 6 in
Out.output_byte out_stream 5;
Out.output_string out_stream "hello"with_flush out_stream f same as flush but with with-function.
output out_stream buffer off len
Output the buffer into outgoing byte stream.
output out_stream string
Output the string into outgoing byte stream.
output out_stream buffer off len
Output the buffer into outgoing byte stream with flushing.