Skip to content

Commit

Permalink
Remove reference to binary file mode in File.open (#11824)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil authored Mar 17, 2022
1 parent 39efd0c commit 31c8616
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
4 changes: 2 additions & 2 deletions spec/std/file_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,8 @@ describe "File" do
end
end

it "supports binary modes" do
with_tempfile("binary-modes.txt") do |path|
it "supports the `b` mode flag" do
with_tempfile("b-mode-flag.txt") do |path|
File.open(path, "wb") do |f|
f.write(Bytes[1, 3, 6, 10])
end
Expand Down
37 changes: 16 additions & 21 deletions src/file.cr
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,22 @@ class File < IO::FileDescriptor
# *mode* must be one of the following file open modes:
#
# ```text
# Mode | Description
# --------+------------------------------------------------------
# r | Read-only, starts at the beginning of the file.
# r+ | Read-write, starts at the beginning of the file.
# w | Write-only, truncates existing file to zero length or
# | creates a new file if the file doesn't exist.
# w+ | Read-write, truncates existing file to zero length or
# | creates a new file if the file doesn't exist.
# a | Write-only, all writes seek to the end of the file,
# | creates a new file if the file doesn't exist.
# a+ | Read-write, all writes seek to the end of the file,
# | creates a new file if the file doesn't exist.
# rb | Same as 'r' but in binary file mode.
# r+b rb+ | Same as 'r+' but in binary file mode.
# wb | Same as 'w' but in binary file mode.
# w+b wb+ | Same as 'w+' but in binary file mode.
# ab | Same as 'a' but in binary file mode.
# a+b ab+ | Same as 'a+' but in binary file mode.
# ```
#
# In binary file mode, line endings are not converted to CRLF on Windows.
# Mode | Description
# -----------+------------------------------------------------------
# r rb | Read-only, starts at the beginning of the file.
# r+ r+b rb+ | Read-write, starts at the beginning of the file.
# w wb | Write-only, truncates existing file to zero length or
# | creates a new file if the file doesn't exist.
# w+ w+b wb+ | Read-write, truncates existing file to zero length or
# | creates a new file if the file doesn't exist.
# a ab | Write-only, all writes seek to the end of the file,
# | creates a new file if the file doesn't exist.
# a+ a+b ab+ | Read-write, all writes seek to the end of the file,
# | creates a new file if the file doesn't exist.
# ```
#
# Line endings are preserved on all platforms. The `b` mode flag has no
# effect; it is provided only for POSIX compatibility.
def self.new(filename : Path | String, mode = "r", perm = DEFAULT_CREATE_PERMISSIONS, encoding = nil, invalid = nil)
filename = filename.to_s
fd = Crystal::System::File.open(filename, mode, perm)
Expand Down

0 comments on commit 31c8616

Please sign in to comment.