package bytream

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

Install

dune-project
 Dependency

Authors

Maintainers

Sources

0.3.tar.gz
md5=d2615a292141aaf946dcea092469ecc3
sha512=83458d536e8e8e562d7228662c9fabb86c276b94e4cd20bc84729106518f7955771486c098c7eea4149fa3b8e6a188d887cecd1cf23d93a31a9b84d95dfacc3a

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_fd ?(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_fd 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