11open Std
22
3+ (* * {2 Types} *)
4+
35(* * Traditional Unix permissions. *)
46module Unix_perm : sig
57 type t = int
@@ -54,37 +56,16 @@ type rw_ty = [ro_ty | Flow.sink_ty]
5456type 'a rw = ([> rw_ty ] as 'a ) r
5557(* * A file opened for reading and writing. *)
5658
57- module Pi : sig
58- module type READ = sig
59- include Flow.Pi. SOURCE
60-
61- val pread : t -> file_offset :Optint .Int63 .t -> Cstruct .t list -> int
62- val stat : t -> Stat .t
63- val close : t -> unit
64- end
65-
66- module type WRITE = sig
67- include Flow.Pi. SINK
68- include READ with type t := t
69-
70- val pwrite : t -> file_offset :Optint .Int63 .t -> Cstruct .t list -> int
71- end
72-
73- type (_, _, _) Resource.pi + =
74- | Read : ('t , (module READ with type t = 't ), [> ro_ty ]) Resource .pi
75- | Write : ('t , (module WRITE with type t = 't ), [> rw_ty ]) Resource .pi
76-
77- val ro : (module READ with type t = 't ) -> ('t , ro_ty ) Resource .handler
78-
79- val rw : (module WRITE with type t = 't ) -> ('t , rw_ty ) Resource .handler
80- end
59+ (* * {2 Metadata} *)
8160
8261val stat : _ ro -> Stat .t
8362(* * [stat t] returns the {!Stat.t} record associated with [t]. *)
8463
8564val size : _ ro -> Optint.Int63 .t
8665(* * [size t] returns the size of [t]. *)
8766
67+ (* * {2 Reading and writing} *)
68+
8869val pread : _ ro -> file_offset :Optint .Int63 .t -> Cstruct .t list -> int
8970(* * [pread t ~file_offset bufs] performs a single read of [t] at [file_offset] into [bufs].
9071
@@ -108,3 +89,48 @@ val pwrite_single : _ rw -> file_offset:Optint.Int63.t -> Cstruct.t list -> int
10889
10990val pwrite_all : _ rw -> file_offset :Optint .Int63 .t -> Cstruct .t list -> unit
11091(* * [pwrite_all t ~file_offset bufs] writes all the data in [bufs] to location [file_offset] in [t]. *)
92+
93+ val seek : _ ro -> Optint.Int63 .t -> [`Set | `Cur | `End ] -> Optint.Int63 .t
94+ (* * Set and/or get the current file position.
95+
96+ Like {!Unix.lseek}. *)
97+
98+ val sync : _ rw -> unit
99+ (* * Flush file buffers to disk.
100+
101+ Like {!Unix.fsync}. *)
102+
103+ val truncate : _ rw -> Optint.Int63 .t -> unit
104+ (* * Set the length of a file.
105+
106+ Like {!Unix.ftruncate}. *)
107+
108+ (* * {2 Provider Interface} *)
109+
110+ module Pi : sig
111+ module type READ = sig
112+ include Flow.Pi. SOURCE
113+
114+ val pread : t -> file_offset :Optint .Int63 .t -> Cstruct .t list -> int
115+ val stat : t -> Stat .t
116+ val seek : t -> Optint.Int63 .t -> [`Set | `Cur | `End ] -> Optint.Int63 .t
117+ val close : t -> unit
118+ end
119+
120+ module type WRITE = sig
121+ include Flow.Pi. SINK
122+ include READ with type t := t
123+
124+ val pwrite : t -> file_offset :Optint .Int63 .t -> Cstruct .t list -> int
125+ val sync : t -> unit
126+ val truncate : t -> Optint.Int63 .t -> unit
127+ end
128+
129+ type (_, _, _) Resource.pi + =
130+ | Read : ('t , (module READ with type t = 't ), [> ro_ty ]) Resource .pi
131+ | Write : ('t , (module WRITE with type t = 't ), [> rw_ty ]) Resource .pi
132+
133+ val ro : (module READ with type t = 't ) -> ('t , ro_ty ) Resource .handler
134+
135+ val rw : (module WRITE with type t = 't ) -> ('t , rw_ty ) Resource .handler
136+ end
0 commit comments