Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove reference to binary file mode in File.open #11824

Merged
merged 2 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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