This PR implements a majority of the File API exposed by Crystal. To do this cleanly, it also introduces a new NativeLib.passthrough macro that should help write native bindings more easily and consistently.
Some methods have issues with this process that lead to them needing special treatment. They are marked with TODO comments describing the bugs.
[X] touch(filename : String, time : Time = Time.now)
[X] writable?(path) : Bool`
All of these are static methods on File. Notably left out of these additions are the stat methods, as they return a Stat object and would need to be transformed into some other Myst object before being returned to the caller. This may be done in the future, but is not needed as of now.
I'll also admit that the testing for these methods is lacking. Most of this is because the methods are direct passthroughs and thus testing them would be repeating the testing done by Crystal itself. However, adding tests for edge cases and argument validity would still be beneficial.
This PR implements a majority of the
File
API exposed by Crystal. To do this cleanly, it also introduces a newNativeLib.passthrough
macro that should help write native bindings more easily and consistently.Some methods have issues with this process that lead to them needing special treatment. They are marked with
TODO
comments describing the bugs.An overview of what's been added:
each_line(filename, encoding = nil, invalid = nil, chomp = true)
read_lines(filename, encoding = nil, invalid = nil, chomp = true) : Array(String)
(implemented as.lines
)join(*parts) : String
read(filename, encoding = nil, invalid = nil) : String
write(filename, content, perm = DEFAULT_CREATE_MODE, encoding = nil, invalid = nil)
basename(path) : String
chmod(path, mode : Int)
chown(path, uid : Int? = -1, gid : Int = -1, follow_symlinks = false)
delete(path)
directory?
(path) : Bool`dirname(path) : String
empty?
(path) : Bool`executable?
(path) : Bool`exists?
(path) : Bool`expand_path(path, dir = nil) : String
extname(filename) : String
file?
(path) : Bool`link(old_path, new_path)
readable?
(path) : Bool`real_path(path) : String
rename(old_filename, new_filename)
size(filename) : UInt64
symlink(old_path, new_path)
symlink?
(path) : Bool`touch(filename : String, time : Time = Time.now)
writable?
(path) : Bool`All of these are static methods on
File
. Notably left out of these additions are thestat
methods, as they return aStat
object and would need to be transformed into some other Myst object before being returned to the caller. This may be done in the future, but is not needed as of now.I'll also admit that the testing for these methods is lacking. Most of this is because the methods are direct passthroughs and thus testing them would be repeating the testing done by Crystal itself. However, adding tests for edge cases and argument validity would still be beneficial.