package iostream

  1. Overview
  2. Docs
Generic, composable IO input and output streams

Install

Dune Dependency

Authors

Maintainers

Sources

iostream-0.3.tbz
sha256=0bf255c06593a3cd72a44eaf3fb4568fc42c8771afe5bcee8d63ea662ee7f009
sha512=68ff56d48b2fcbd34ef2c15f6a8969543caa5c5e6b14177a0fde1e2b12d2fe52448d233e02cd1ab2529f74f48b31954ae8ec9e22601cfda6d3c38ce667c1b851

doc/src/iostream.unix/iostream_unix.ml.html

Source file iostream_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
31
32
33
34
35
36
open Iostream

module In : sig
  open In

  val of_unix_fd : ?close_noerr:bool -> Unix.file_descr -> t_seekable
  (** Create an in stream from a raw Unix file descriptor. The file descriptor
      must be opened for reading. *)
end = struct
  open In

  let of_unix_fd ?(close_noerr = false) (fd : Unix.file_descr) : t_seekable =
    object
      method input buf i len = Unix.read fd buf i len

      method close () =
        if close_noerr then (
          try Unix.close fd with _ -> ()
        ) else
          Unix.close fd

      method seek i = ignore (Unix.lseek fd i Unix.SEEK_SET : int)
      method pos () : int = Unix.lseek fd 0 Unix.SEEK_CUR
    end
end

module Out : sig
  open Out

  val of_unix_fd : Unix.file_descr -> t_seekable
  (** Output stream directly writing into the given Unix file descriptor. *)
end = struct
  open Out

  let of_unix_fd fd : t_seekable = of_out_channel (Unix.out_channel_of_descr fd)
end
OCaml

Innovation. Community. Security.