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

Allow Int64 values within IO#read_at #10356

Merged
merged 4 commits into from
Feb 12, 2021
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
5 changes: 5 additions & 0 deletions spec/std/file_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -946,9 +946,14 @@ describe "File" do
file.read_at(6, 100) do |io|
io.gets_to_end.should eq("World\nHello World\nHello World\nHello World\nHello World\nHello World\nHello World\nHello World\nHello Worl")
end

file.read_at(0, 240) do |io|
io.gets_to_end.should eq(File.read(filename))
end

file.read_at(6_i64, 5_i64) do |io|
io.gets_to_end.should eq("World")
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/file.cr
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ class File < IO::FileDescriptor

# Yields an `IO` to read a section inside this file.
# Multiple sections can be read concurrently.
def read_at(offset, bytesize, &block)
def read_at(offset, bytesize, & : IO ->)
self_bytesize = self.size

unless 0 <= offset <= self_bytesize
Expand Down
7 changes: 6 additions & 1 deletion src/file/preader.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ class File::PReader < IO

getter? closed = false

def initialize(@file : File, @offset : Int32, @bytesize : Int32)
@offset : Int64
@bytesize : Int64

def initialize(@file : File, offset : Int, bytesize : Int)
@offset = offset.to_i64
@bytesize = bytesize.to_i64
@pos = 0
end

Expand Down
2 changes: 1 addition & 1 deletion src/io.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ abstract class IO
# `File` and `IO::Memory` implement it.
#
# Multiple sections can be read concurrently.
def read_at(offset, bytesize, &block)
def read_at(offset, bytesize, & : IO ->)
raise Error.new "Unable to read_at"
end

Expand Down
2 changes: 1 addition & 1 deletion src/io/memory.cr
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ class IO::Memory < IO
#
# During the block duration `self` becomes read-only,
# so multiple concurrent open are allowed.
def read_at(offset, bytesize)
def read_at(offset, bytesize, & : IO ->)
unless 0 <= offset <= @bytesize
raise ArgumentError.new("Offset out of bounds")
end
Expand Down