package MlFront_Thunk

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module MlFront_Thunk.ThunkLuaTypFileSource

A Lua type for a file or directory handle for use with the "request.io" module.

At present the directory operation is only list_all which is the directory analog to read_all for files. Iterating over large directories may be supported at a later date. Regardless, directories must be closed just like files.

Lua User Type

Sourcetype stats = {
  1. stats_size : int64;
  2. stats_sha256 : string;
}
Sourcetype 'a t

A type representing a file handle.

Sourceval tname : string
Sourceval eq : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
Sourceval to_string : ('a -> string) -> 'a t -> string

File Operations

Sourceval open_readonly_file : absfile:MlFront_Core.FilePath.t -> (module ThunkIo.READ_CHANNEL_IO with type file_object = 'b) -> peer_file_object:'b -> unit -> ('a t, string) result

open_readonly_file ~absfile channel ~peer_file_object () opens the file absfile in read-only mode.

The file absfile must be an absolute path to the file.

peer_file_object must be a file object on the same file system as absfile.

Sourceval open_writeonly_file : absfile:MlFront_Core.FilePath.t -> (module ThunkIo.WRITE_CHANNEL_IO_WITH_FILEOPS with type file_object = 'b) -> peer_file_object:'b -> unit -> ('a t, string) result

open_writeonly_file ~absfile channel ~peer_file_object () opens the file absfile in write-only mode.

The file absfile must be an absolute path to the file.

peer_file_object must be a file object on the same file system as absfile. That is, renaming the file peer_file_object to absfile must be possible.

Sourceval read_all : 'a t -> (string, string) result

read_all fh reads all bytes from the file handle fh.

On end-of-file Ok "" is returned.

Sourceval read_some : 'a t -> bytes -> int -> int -> ([ `Eof | `BytesRead of int ], string) result

read_some fh bytes pos len reads up to len bytes from the file handle fh into bytes starting at position pos.

Reading zero bytes will check for end-of-file and return `Eof if necessary.

Sourceval read_exactly : 'a t -> int -> (string, string) result

read_exactly fh len reads exactly len bytes from the file handle fh. If end-of-file is reached before len bytes are read, an error is returned.

Sourceval read_line : 'a t -> ([ `Eof | `Line of string ], string) result

read_line fh reads a line including any trailing newline from the file handle fh.

Sourceval write : 'a t -> string -> (unit, string) result

write fh str writes the string str to the file handle fh.

Sourceval move : 'a t -> dest_absfile:MlFront_Core.FilePath.t -> (unit, string) result

move fh ~dest_absfile moves the file associated with the closed file handle fh to the destination dest_absfile.

Directory Operations

Sourceval open_readonly_directory : absdir:MlFront_Core.FilePath.t -> (module ThunkIo.READ_CHANNEL_IO with type file_object = 'f) -> (module ThunkIo.READ_DIRECTORY_IO with type directory_object = 'd and type file_object = 'f) -> peer_dir_object:'d -> peer_file_object:'f -> unit -> ('a t, string) result

open_readonly_directory ~absdir channelio dirio ~peer_dir_object ~peer_file_object () opens the directory absdir in read-only mode.

The directory absdir must be an absolute path to the directory.

peer_dir_object and peer_file_object must be directory and file objects on the same file system as absdir. That is, renaming the directory peer_dir_object to absdir must be possible, and renaming the file peer_file_object to a file within absdir must be possible.

Sourceval list_all : 'a t -> ('a t list, string) result

list_all dh lists all of the remaining entries in the directory handle dh.

Each entry is returned as a file handle or a directory handle. The file handles are lazily opened; that is, the underlying file is not opened until there is a read operation like read_line. Once read, the file handle must be closed.

Sourceval zip : dest_absfile:MlFront_Core.FilePath.t -> 'a t -> (ThunkIo.file_digest, string) result

zip ~dest_absfile dh atomically zips the contents of the directory handle dh into the zip file at dest_absfile.

The zip operation is only supported when dest_absfile is on the same file system as the directory handle dh.

Path Operations

Sourceval open_readonly_path : abs_path:MlFront_Core.FilePath.t -> (module ThunkIo.READ_CHANNEL_IO with type file_object = 'b) -> (module ThunkIo.READ_DIRECTORY_IO with type directory_object = 'd and type file_object = 'b) -> peer_dir_object:'d -> peer_file_object:'b -> unit -> ('a t, string) result

open_readonly_path ~abs_path channel dirio ~peer_dir_object ~peer_file_object () opens the path abs_path in read-only mode.

The path abs_path must be an absolute path to either a file or a directory.

Common Operations

Sourceval filetype : 'a t -> [ `RegularFile | `Directory ]

filetype fh returns the type of the handle fh.

Sourceval realpath : 'a t -> MlFront_Core.FilePath.t

realpath fh returns the path of the file or directory for the handle fh.

Sourceval close : 'a t -> (unit, string) result

close fh closes the file handle fh.

Sourceval close_with_stats : 'a t -> (stats, string) result

close_with_stats fh closes the file handle fh and returns statistics about the written file.

Sourceval is_closed : 'a t -> bool

is_closed fh is true if and only if the file handle fh is closed.