12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697(** Tranditional Unix permissions. *)moduleUnix_perm=structtypet=int(** This is the same as {!Unix.file_perm}, but avoids a dependency on [Unix]. *)end(** Portable file stats. *)moduleStat=struct(** Kind of file from st_mode. **)typekind=[|`Unknown|`Fifo|`Character_special|`Directory|`Block_device|`Regular_file|`Symbolic_link|`Socket](** Like stat(2). *)typet={dev:Int64.t;ino:Int64.t;kind:kind;perm:Unix_perm.t;nlink:Int64.t;uid:Int64.t;gid:Int64.t;rdev:Int64.t;size:Optint.Int63.t;atime:float;mtime:float;ctime:float;}end(** A file opened for reading. *)classvirtualro=object(_:<Generic.t;Flow.source;..>)methodprobe_=Nonemethodread_methods=[]methodvirtualpread:file_offset:Optint.Int63.t->Cstruct.tlist->intmethodvirtualstat:Stat.tend(** A file opened for reading and writing. *)classvirtualrw=object(_:<Generic.t;Flow.source;Flow.sink;..>)inheritromethodvirtualpwrite:file_offset:Optint.Int63.t->Cstruct.tlist->intend(** [stat t] returns the {!Stat.t} record associated with [t]. *)letstat(t:#ro)=t#stat(** [size t] returns the size of [t]. *)letsizet=(statt).size(** [pread t ~file_offset bufs] performs a single read of [t] at [file_offset] into [bufs].
It returns the number of bytes read, which may be less than the space in [bufs],
even if more bytes are available. Use {!pread_exact} instead if you require
the buffer to be filled.
To read at the current offset, use {!Flow.single_read} instead. *)letpread(t:#ro)~file_offsetbufs=letgot=t#pread~file_offsetbufsinassert(got>0&&got<=Cstruct.lenvbufs);got(** [pread_exact t ~file_offset bufs] reads from [t] into [bufs] until [bufs] is full.
@raise End_of_file if the buffer could not be filled. *)letrecpread_exact(t:#ro)~file_offsetbufs=ifCstruct.lenvbufs>0then(letgot=t#pread~file_offsetbufsinletfile_offset=Optint.Int63.addfile_offset(Optint.Int63.of_intgot)inpread_exactt~file_offset(Cstruct.shiftvbufsgot))(** [pwrite_single t ~file_offset bufs] performs a single write operation, writing
data from [bufs] to location [file_offset] in [t].
It returns the number of bytes written, which may be less than the length of [bufs].
In most cases, you will want to use {!pwrite_all} instead. *)letpwrite_single(t:#rw)~file_offsetbufs=letgot=t#pwrite~file_offsetbufsinassert(got>0&&got<=Cstruct.lenvbufs);got(** [pwrite_all t ~file_offset bufs] writes all the data in [bufs] to location [file_offset] in [t]. *)letrecpwrite_all(t:#rw)~file_offsetbufs=ifCstruct.lenvbufs>0then(letgot=t#pwrite~file_offsetbufsinletfile_offset=Optint.Int63.addfile_offset(Optint.Int63.of_intgot)inpwrite_allt~file_offset(Cstruct.shiftvbufsgot))