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

Let IO#copy return UInt64 #7660

Merged
merged 1 commit into from
Apr 25, 2019
Merged
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
10 changes: 6 additions & 4 deletions src/io.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1123,14 +1123,14 @@ abstract class IO
#
# io2.to_s # => "hello"
# ```
def self.copy(src, dst)
def self.copy(src, dst) : UInt64
buffer = uninitialized UInt8[4096]
count = 0
count = 0_u64
while (len = src.read(buffer.to_slice).to_i32) > 0
dst.write buffer.to_slice[0, len]
count += len
end
len < 0 ? len : count
count
end

# Copy at most *limit* bytes from *src* to *dst*.
Expand All @@ -1143,9 +1143,11 @@ abstract class IO
#
# io2.to_s # => "hel"
# ```
def self.copy(src, dst, limit : Int)
def self.copy(src, dst, limit : Int) : UInt64
raise ArgumentError.new("Negative limit") if limit < 0

limit = limit.to_u64

buffer = uninitialized UInt8[4096]
remaining = limit
while (len = src.read(buffer.to_slice[0, Math.min(buffer.size, Math.max(remaining, 0))])) > 0
Expand Down