Prajna


FileTools

A set of helper routine for file operations

Functions and values

Function or valueDescription
AppendToFile filename content
Signature: filename:string -> content:string -> unit

Append a string to file

CreateFileStreamForRead fname
Signature: fname:string -> FileStream

Create a file stream to read

CreateFileStreamForWrite fname
Signature: fname:string -> FileStream

Create a file stream to write, and make the file accessible to everyone (for shared use in a cluster) Caller should be responsible for dispose the returned stream.

DirectoryInfoCreateIfNotExists dir
Signature: dir:string -> DirectoryInfo

Return DirectoryInfo, create the directory if it doesn't exist. The directory created this way will allow access control by everyone to ease use in cluster scenario.

GetDrive dir
Signature: dir:string -> string

Get drive letter

ReadBytesFromFile filename
Signature: filename:string -> byte []

Read a byte[] from files

ReadFromFile filename
Signature: filename:string -> string

read a string from file

SaveToFile filename content
Signature: filename:string -> content:string -> unit

save a string to file, do not write if we find that the file is not writable.

TouchFile fileName
Signature: fileName:string -> unit

Touch a file, change its last write time to now.

WriteBytesToFile filename bytes
Signature: filename:string -> bytes:byte [] -> unit

Write a byte[] to file

WriteBytesToFileConcurrent (...)
Signature: filename:string -> bytes:byte [] -> unit

Write a byte[] to file, with possibility of multiple processes are writing to the exact same file at the same time. Such situation occurs for the Prajna daemon to write cluster metadata, DKV metadata, Assembly, dependencies file, etc.. WriteBytesToFileConcurrent checks if the file has been written concurrently, if that is the case, one of the process will verify (read) the file and make sure that is the same content that is to be written.

WriteBytesToFileConcurrentCreate (...)
Signature: filename:string -> bytes:byte [] -> unit

Write a byte[] to file, create the directory of the file if it doesn't exist. The call deal with possibility of multiple processes are writing to the exact same file at the same time. Such situation occurs for the Prajna daemon to write cluster metadata, DKV metadata, Assembly, dependencies file, etc.. WriteBytesToFileConcurrent checks if the file has been written concurrently, if that is the case, one of the process will verify (read) the file and make sure that is the same content that is to be written.

WriteBytesToFileCreate filename bytes
Signature: filename:string -> bytes:byte [] -> unit

Write a byte[] to file, create the directory of the file if it doesn't exist

Fork me on GitHub