class File
class File
lib/file.tya:2
File reads, writes, and inspects filesystem paths.
Source
# File reads, writes, and inspects filesystem paths.
class File
# File.path stores instance state.
# @type Nil
path: nil
# File.append appends text to path and creates the file when needed.
# @param path String path value.
# @param text String text value.
# @return Any the resulting value.
static append: path, text ->
file_append(path, text)
# File.chmod changes POSIX-like permissions where supported.
# @param path String path value.
# @param mode Any mode value.
# @return Any the resulting value.
static chmod: path, mode ->
file_chmod(path, mode)
# File.copy copies file contents as bytes.
# @param src String src value.
# @param dst Any dst value.
# @param options Dict options value.
# @return Any the resulting value.
static copy: src, dst, options = {} ->
file_copy(src, dst, options)
# File.exists? returns true when path exists.
# @param path String path value.
# @return Boolean whether the condition is true.
static exists?: path ->
file_exists(path)
# File.read returns the UTF-8 text contents of path.
# @param path String path value.
# @return Any the resulting value.
static read: path ->
read_file(path)
# File.read_bytes returns the raw bytes stored at path.
# @param path String path value.
# @return Any the resulting value.
static read_bytes: path ->
file_read_bytes(path)
# File.remove removes path.
# @param path String path value.
# @return Any the resulting value.
static remove: path ->
file_remove(path)
# File.rename renames old_path to new_path.
# @param old_path String old path value.
# @param new_path String new path value.
# @return Any the resulting value.
static rename: old_path, new_path ->
file_rename(old_path, new_path)
# File.stat returns metadata for path as a dictionary.
# @param path String path value.
# @return Any the resulting value.
static stat: path ->
file_stat(path)
# File.temp creates an empty temporary file and returns its path.
# @param prefix Any prefix value.
# @param suffix Any suffix value.
# @return Any the resulting value.
static temp: prefix = "tya", suffix = "" ->
file_temp(prefix, suffix)
# File.write replaces path with text and creates the file when needed.
# @param path String path value.
# @param text String text value.
# @return Any the resulting value.
static write: path, text ->
write_file(path, text)
# File.write_bytes replaces path with raw bytes.
# @param path String path value.
# @param bytes Array bytes value.
# @return Any the resulting value.
static write_bytes: path, bytes ->
file_write_bytes(path, bytes)
# File.initialize stores a file path.
# @param path String path value.
# @return Self the initialized object.
initialize: path = nil ->
self.path = path
# File.append provides the file/File standard library operation.
# @param path String path value.
# @param text String text value.
# @return Any the resulting value.
append: path, text = nil ->
if text == nil
text = path
path = self.path
file_append(path, text)
# chmod changes POSIX-like permissions where supported.
# @param path String path value.
# @param mode Any mode value.
# @return Any the resulting value.
chmod: path, mode = nil ->
if mode == nil
mode = path
path = self.path
file_chmod(path, mode)
# copy copies file contents as bytes.
# @param src String src value.
# @param dst Any dst value.
# @param options Dict options value.
# @return Any the resulting value.
copy: src, dst = nil, options = {} ->
if self.path != nil and dst != nil and dst.class == Dict
options = dst
dst = src
src = self.path
if dst == nil
dst = src
src = self.path
file_copy(src, dst, options)
# exists? returns true when path exists.
# @param path String path value.
# @return Boolean whether the condition is true.
exists?: path = nil ->
if path == nil
path = self.path
file_exists(path)
# read returns the UTF-8 text contents of path.
# Raises when the file cannot be opened or read.
# @param path String path value.
# @return Any the resulting value.
read: path = nil ->
if path == nil
path = self.path
read_file(path)
# read_bytes returns the raw bytes stored at path.
# Raises when the file cannot be opened or read.
# @param path String path value.
# @return Any the resulting value.
read_bytes: path = nil ->
if path == nil
path = self.path
file_read_bytes(path)
# File.remove provides the file/File standard library operation.
# @param path String path value.
# @return Any the resulting value.
remove: path = nil ->
if path == nil
path = self.path
file_remove(path)
# File.rename provides the file/File standard library operation.
# @param old_path String old path value.
# @param new_path String new path value.
# @return Any the resulting value.
rename: old_path, new_path = nil ->
if new_path == nil
new_path = old_path
old_path = self.path
file_rename(old_path, new_path)
# stat returns metadata for path as a dictionary.
# Raises when the path cannot be inspected.
# @param path String path value.
# @return Any the resulting value.
stat: path = nil ->
if path == nil
path = self.path
file_stat(path)
# temp creates an empty temporary file and returns its path.
# @param prefix Any prefix value.
# @param suffix Any suffix value.
# @return Any the resulting value.
temp: prefix = "tya", suffix = "" ->
file_temp(prefix, suffix)
# write replaces path with text and creates the file when needed.
# Raises when the file cannot be written.
# @param path String path value.
# @param text String text value.
# @return Any the resulting value.
write: path, text = nil ->
if text == nil
text = path
path = self.path
write_file(path, text)
# write_bytes replaces path with raw bytes.
# Raises when the file cannot be written.
# @param path String path value.
# @param b Int b value.
# @return Any the resulting value.
write_bytes: path, b = nil ->
if b == nil
b = path
path = self.path
file_write_bytes(path, b)
Instance Variables
path
File.path
lib/file.tya:5
File.path stores instance state.
Source
# File.path stores instance state.
# @type Nil
path: nil
Static Methods
append
static File.append(path, text)
lib/file.tya:11
File.append appends text to path and creates the file when needed.
Source
# File.append appends text to path and creates the file when needed.
# @param path String path value.
# @param text String text value.
# @return Any the resulting value.
static append: path, text ->
file_append(path, text)
chmod
static File.chmod(path, mode)
lib/file.tya:18
File.chmod changes POSIX-like permissions where supported.
Source
# File.chmod changes POSIX-like permissions where supported.
# @param path String path value.
# @param mode Any mode value.
# @return Any the resulting value.
static chmod: path, mode ->
file_chmod(path, mode)
copy
static File.copy(src, dst, options = {})
lib/file.tya:26
File.copy copies file contents as bytes.
Source
# File.copy copies file contents as bytes.
# @param src String src value.
# @param dst Any dst value.
# @param options Dict options value.
# @return Any the resulting value.
static copy: src, dst, options = {} ->
file_copy(src, dst, options)
exists?
static File.exists?(path)
lib/file.tya:32
File.exists? returns true when path exists.
Source
# File.exists? returns true when path exists.
# @param path String path value.
# @return Boolean whether the condition is true.
static exists?: path ->
file_exists(path)
read
static File.read(path)
lib/file.tya:38
File.read returns the UTF-8 text contents of path.
Source
# File.read returns the UTF-8 text contents of path.
# @param path String path value.
# @return Any the resulting value.
static read: path ->
read_file(path)
read_bytes
static File.read_bytes(path)
lib/file.tya:44
File.read_bytes returns the raw bytes stored at path.
Source
# File.read_bytes returns the raw bytes stored at path.
# @param path String path value.
# @return Any the resulting value.
static read_bytes: path ->
file_read_bytes(path)
remove
static File.remove(path)
lib/file.tya:50
File.remove removes path.
Source
# File.remove removes path.
# @param path String path value.
# @return Any the resulting value.
static remove: path ->
file_remove(path)
rename
static File.rename(old_path, new_path)
lib/file.tya:57
File.rename renames old_path to new_path.
Source
# File.rename renames old_path to new_path.
# @param old_path String old path value.
# @param new_path String new path value.
# @return Any the resulting value.
static rename: old_path, new_path ->
file_rename(old_path, new_path)
stat
static File.stat(path)
lib/file.tya:63
File.stat returns metadata for path as a dictionary.
Source
# File.stat returns metadata for path as a dictionary.
# @param path String path value.
# @return Any the resulting value.
static stat: path ->
file_stat(path)
temp
static File.temp(prefix = "tya", suffix = "")
lib/file.tya:70
File.temp creates an empty temporary file and returns its path.
Source
# File.temp creates an empty temporary file and returns its path.
# @param prefix Any prefix value.
# @param suffix Any suffix value.
# @return Any the resulting value.
static temp: prefix = "tya", suffix = "" ->
file_temp(prefix, suffix)
write
static File.write(path, text)
lib/file.tya:77
File.write replaces path with text and creates the file when needed.
Source
# File.write replaces path with text and creates the file when needed.
# @param path String path value.
# @param text String text value.
# @return Any the resulting value.
static write: path, text ->
write_file(path, text)
write_bytes
static File.write_bytes(path, bytes)
lib/file.tya:84
File.write_bytes replaces path with raw bytes.
Source
# File.write_bytes replaces path with raw bytes.
# @param path String path value.
# @param bytes Array bytes value.
# @return Any the resulting value.
static write_bytes: path, bytes ->
file_write_bytes(path, bytes)
Methods
append
File.append(path, text = nil)
lib/file.tya:97
File.append provides the file/File standard library operation.
Source
# File.append provides the file/File standard library operation.
# @param path String path value.
# @param text String text value.
# @return Any the resulting value.
append: path, text = nil ->
if text == nil
text = path
path = self.path
file_append(path, text)
chmod
File.chmod(path, mode = nil)
lib/file.tya:107
chmod changes POSIX-like permissions where supported.
Source
# chmod changes POSIX-like permissions where supported.
# @param path String path value.
# @param mode Any mode value.
# @return Any the resulting value.
chmod: path, mode = nil ->
if mode == nil
mode = path
path = self.path
file_chmod(path, mode)
copy
File.copy(src, dst = nil, options = {})
lib/file.tya:118
copy copies file contents as bytes.
Source
# copy copies file contents as bytes.
# @param src String src value.
# @param dst Any dst value.
# @param options Dict options value.
# @return Any the resulting value.
copy: src, dst = nil, options = {} ->
if self.path != nil and dst != nil and dst.class == Dict
options = dst
dst = src
src = self.path
if dst == nil
dst = src
src = self.path
file_copy(src, dst, options)
exists?
File.exists?(path = nil)
lib/file.tya:131
exists? returns true when path exists.
Source
# exists? returns true when path exists.
# @param path String path value.
# @return Boolean whether the condition is true.
exists?: path = nil ->
if path == nil
path = self.path
file_exists(path)
initialize
File.initialize(path = nil)
lib/file.tya:90
File.initialize stores a file path.
Source
# File.initialize stores a file path.
# @param path String path value.
# @return Self the initialized object.
initialize: path = nil ->
self.path = path
read
File.read(path = nil)
lib/file.tya:140
read returns the UTF-8 text contents of path. Raises when the file cannot be opened or read.
Source
# read returns the UTF-8 text contents of path.
# Raises when the file cannot be opened or read.
# @param path String path value.
# @return Any the resulting value.
read: path = nil ->
if path == nil
path = self.path
read_file(path)
read_bytes
File.read_bytes(path = nil)
lib/file.tya:149
read_bytes returns the raw bytes stored at path. Raises when the file cannot be opened or read.
Source
# read_bytes returns the raw bytes stored at path.
# Raises when the file cannot be opened or read.
# @param path String path value.
# @return Any the resulting value.
read_bytes: path = nil ->
if path == nil
path = self.path
file_read_bytes(path)
remove
File.remove(path = nil)
lib/file.tya:157
File.remove provides the file/File standard library operation.
Source
# File.remove provides the file/File standard library operation.
# @param path String path value.
# @return Any the resulting value.
remove: path = nil ->
if path == nil
path = self.path
file_remove(path)
rename
File.rename(old_path, new_path = nil)
lib/file.tya:166
File.rename provides the file/File standard library operation.
Source
# File.rename provides the file/File standard library operation.
# @param old_path String old path value.
# @param new_path String new path value.
# @return Any the resulting value.
rename: old_path, new_path = nil ->
if new_path == nil
new_path = old_path
old_path = self.path
file_rename(old_path, new_path)
stat
File.stat(path = nil)
lib/file.tya:176
stat returns metadata for path as a dictionary. Raises when the path cannot be inspected.
Source
# stat returns metadata for path as a dictionary.
# Raises when the path cannot be inspected.
# @param path String path value.
# @return Any the resulting value.
stat: path = nil ->
if path == nil
path = self.path
file_stat(path)
temp
File.temp(prefix = "tya", suffix = "")
lib/file.tya:185
temp creates an empty temporary file and returns its path.
Source
# temp creates an empty temporary file and returns its path.
# @param prefix Any prefix value.
# @param suffix Any suffix value.
# @return Any the resulting value.
temp: prefix = "tya", suffix = "" ->
file_temp(prefix, suffix)
write
File.write(path, text = nil)
lib/file.tya:193
write replaces path with text and creates the file when needed. Raises when the file cannot be written.
Source
# write replaces path with text and creates the file when needed.
# Raises when the file cannot be written.
# @param path String path value.
# @param text String text value.
# @return Any the resulting value.
write: path, text = nil ->
if text == nil
text = path
path = self.path
write_file(path, text)
write_bytes
File.write_bytes(path, b = nil)
lib/file.tya:204
write_bytes replaces path with raw bytes. Raises when the file cannot be written.
Source
# write_bytes replaces path with raw bytes.
# Raises when the file cannot be written.
# @param path String path value.
# @param b Int b value.
# @return Any the resulting value.
write_bytes: path, b = nil ->
if b == nil
b = path
path = self.path
file_write_bytes(path, b)