Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.