-
Notifications
You must be signed in to change notification settings - Fork 0
stdfiles
Provides file handling services.
Opaque type representing file instance.
Opaque type containing file information.
Following values represent file open modes:
- stdfiles.w: write mode
- stdfiles.r: read mode
- stdfiles.a: append mode
These can be summed:
- plus(stdfiles.w stdfiles.r) : read-write mode
- stdfiles.r : read-only mode
- stdfiles.w : write only mode
Creates file. File name (and path) is given as argument.
type: procedure
Format:
call(stdfiles.create <filename-string>) -> <opaque:file> or <error-string>
Return value:
- if success, opaque:file
- if failure, error string
Opens file.
Arguments:
- file name (and path)
- open mode
- stdfiles.w (write-only)
- stdfiles.r (read-only)
- plus(stdfiles.w stdfiles.r) (read-write)
- stdfiles.a (append -> writes are appending to file end instead of overwriting)
type: procedure
Format:
call(stdfiles.open <filename-string> <open-mode-int>) -> <opaque:file> or <error-string>
Return value:
- if success, opaque:file
- if failure, error string
Writes bytearray (defined in stdbytes) to file.
type: procedure
Format:
call(stdfiles.write <opaque:file> <data-to-write-bytearray>) -> <number-of-bytes-written-int> or <error-string>
Return value:
- if success, number of bytes written (int)
- if failure, error string
Writes bytearray (defined in stdbytes) to file starting from given offset (int) in file.
type: procedure
Format:
call(stdfiles.write-at <opaque:file> <data-to-write-bytearray> <offset-int>) -> <number-of-bytes-written-int> or <error-string>
Return value:
- if success, number of bytes written (int)
- if failure, error string
Writes string to file and puts newline in the end.
type: procedure
Format:
call(stdfiles.writeln <opaque:file> <data-to-write-string>) -> <number-of-bytes-written-int> or <error-string>
Return value:
- if success, number of bytes written (int)
- if failure, error string
Reads file. Maximum count of bytes to be read is given as argument (int).
type: procedure
Format:
call(stdfiles.read <opaque:file> <max-bytes-int>) -> <list>
Return value: list, conatins following values
- bool value which is true if EOF was reached, false otherwise
- bytearray containing data read
Reads file. Maximum count of bytes to be read is given as argument (int). Read starts from given offset (int) in file.
type: procedure
Format:
call(stdfiles.read <opaque:file> <max-bytes-int> <offset-int>) -> <list>
Return value: list, conatins following values
- bool value which is true if EOF was reached, false otherwise
- bytearray containing data read
Reads whole file content. Content returned as bytearray.
type: procedure
Format:
call(stdfiles.read-all <opaque:file>) -> bytearray (file content)
Return value: bytearray (whole file content)
Reads whole file content (as text). Content returned as list of strings (splitted by newlines).
type: procedure
Format:
call(stdfiles.readlines <opaque:file>) -> list (of strings) or <error-string>
Return value:
- if success: list of strings (splitted by newlines in file)
- if failure: error string
Sets the offset (2nd argument) for the next read or write on file to offset, interpreted according to whence (3rd argument). Whence 0 means relative to the origin of the file, 1 means relative to the current offset, and 2 means relative to the end.
type: procedure
Arguments:
- opaque: file
- offset (int)
- whence (int)
Format:
call(stdfiles.seek <opaque:file> <offset> <whence>) -> <new-offset-int> or <error-string>
Return value:
- if success: new offset (int)
- if failure: error string
Removes file. Name (and path) is given as arguemnt (string).
type: procedure
Format:
call(stdfiles.remove <filename-string>) -> <string>
Return value: string
- if success: ''
- if failure: error description (string)
Renames file. Old name is 1st argument (string), new name is 2nd argument (string).
type: procedure
Format:
call(stdfiles.rename <old-name-string> <new-name-string>) -> string
Return value: string
- if success: ''
- if failure: error description (string)
Closes file.
type: procedure
Format:
call(stdfiles.close <opaque:file>) -> true or <error-string>
Return value: true (bool) or string (describing error)
- if success: true
- if failure: error description (string)
Returns file informations of certain directory (as map: filename -> file-info).
Format:
call(stdfiles.read-dir <directory-string>) -> map or <error-string>
Return value: map or string (describing error)
Map contains file names as keys and file infos as values (opaque:fileinfo)
Creates file information from opaque:fileinfo (given as argument) to map.
type: procedure
Format:
call(stdfiles.finfo-map <opaque:fileinfo>) -> map or <error-string>
Return value: map or string (describing error)
Map contains follwoign information:
Key | Value |
---|---|
'name' | file name (string) |
'size' | length in bytes (int) |
'mode' | file mode bits (string), example: '-rw-rw-rw-' |
'modtime' | modification time (string) |
'is-dir' | bool, true if is directory, false otherwise |
Returns current working directory as string.
type: procedure
Format:
call(stdfiles.cwd) -> string
Return value: string
Change current working directory.
type: procedure
Format:
call(stdfiles.chdir <new-directory-string>) -> string
Return value: string
- if success: ''
- if failure: error description (string)
Create new directory. Directory name (and path) is given as argument.
type: procedure
Format:
call(stdfiles.mkdir) -> <string>
Return value: string
- if success: ''
- if failure: error description (string)