package bytream

  1. Overview
  2. Docs
A streaming bytes and crunching them library

Install

dune-project
 Dependency

Authors

Maintainers

Sources

0.2.tar.gz
md5=86080ca17c645960050642fe02d03e41
sha512=f6bc5dfb5c5a9cc2c719bbff4eb66e587e0cbafd1b45a6b7c207df4f810f46466a93508339fd54e5f1c8ee0691e270060bf7535996b1d84d6724b5494de9de1f

doc/src/bytream.unix/bytream_unix.ml.html

Source file bytream_unix.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module In = struct
  let of_file_descr ?(io_buffer_size = 4096) fd =
    let buffer = Bstr.create io_buffer_size in

    let reader () =
      match Unix.read_bigarray fd buffer 0 io_buffer_size with
      | 0 -> raise End_of_file
      | length -> (~buffer, ~offset:0, ~length)
    in

    Bytream.In.make' reader
end

module Out = struct
  let of_file_descr fd =
    let rec really_write_bigarray buffer offset = function
      | 0 -> ()
      | length ->
          let written_bytes = Unix.write_bigarray fd buffer 0 length in

          really_write_bigarray buffer (offset + written_bytes)
            (length - written_bytes)
    in

    let writer ((~buffer, ~length, ..) : Bytream.Out.chunk) =
      really_write_bigarray buffer 0 length
    in

    Bytream.Out.make writer
end