Skip to content

Commit

Permalink
Document IO::FileDescriptor#info (#12384)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil authored Aug 16, 2022
1 parent 3eceaff commit f306598
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/file.cr
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ class File < IO::FileDescriptor
#
# File.symlink("foo", "bar")
# File.info?("bar", follow_symlinks: false).try(&.type.symlink?) # => true
#
# Use `#info` if the `File` is already open.
# ```
#
# Use `IO::FileDescriptor#info` if the file is already open.
def self.info?(path : Path | String, follow_symlinks = true) : Info?
Crystal::System::File.info?(path.to_s, follow_symlinks)
end
Expand All @@ -156,9 +156,9 @@ class File < IO::FileDescriptor
#
# File.symlink("foo", "bar")
# File.info("bar", follow_symlinks: false).type.symlink? # => true
#
# Use `#info` if the `File` is already open.
# ```
#
# Use `IO::FileDescriptor#info` if the file is already open.
def self.info(path : Path | String, follow_symlinks = true) : Info
Crystal::System::File.info(path.to_s, follow_symlinks)
end
Expand Down
20 changes: 19 additions & 1 deletion src/io/file_descriptor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,25 @@ class IO::FileDescriptor < IO
end
{% end %}

def info
# Returns a `File::Info` object for this file descriptor, or raises
# `IO::Error` in case of an error.
#
# Certain fields like the file size may not be updated until an explicit
# flush.
#
# ```
# File.write("testfile", "abc")
#
# file = File.new("testfile", "a")
# file.info.size # => 3
# file << "defgh"
# file.info.size # => 3
# file.flush
# file.info.size # => 8
# ```
#
# Use `File.info` if the file is not open and a path to the file is available.
def info : File::Info
system_info
end

Expand Down

0 comments on commit f306598

Please sign in to comment.