Skip to content

Commit

Permalink
Re-introduce IO#read restrictions and cast to Int32
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Jun 29, 2021
1 parent b998a9f commit e8cf88e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/digest/io_digest.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class IO::Digest < IO
def initialize(@io : IO, @digest_algorithm : ::Digest, @mode = DigestMode::Read)
end

def read(slice : Bytes)
read_bytes = io.read(slice)
def read(slice : Bytes) : Int32
read_bytes = io.read(slice).to_i32
if @mode.read?
digest_algorithm.update(slice[0, read_bytes])
end
Expand Down
10 changes: 5 additions & 5 deletions src/http/content.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module HTTP
class FixedLengthContent < IO::Sized
include Content

def read(slice : Bytes)
def read(slice : Bytes) : Int32
ensure_send_continue
super
end
Expand Down Expand Up @@ -58,9 +58,9 @@ module HTTP
def initialize(@io : IO)
end

def read(slice : Bytes)
def read(slice : Bytes) : Int32
ensure_send_continue
@io.read(slice)
@io.read(slice).to_i32
end

def read_byte : UInt8?
Expand Down Expand Up @@ -112,7 +112,7 @@ module HTTP
@received_final_chunk = false
end

def read(slice : Bytes)
def read(slice : Bytes) : Int32
ensure_send_continue
count = slice.size
return 0 if count == 0
Expand All @@ -123,7 +123,7 @@ module HTTP

to_read = Math.min(count, @chunk_remaining)

bytes_read = @io.read slice[0, to_read]
bytes_read = @io.read(slice[0, to_read]).to_i32

if bytes_read == 0
raise IO::EOFError.new("Invalid HTTP chunked content")
Expand Down
2 changes: 1 addition & 1 deletion src/io/argf.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class IO::ARGF < IO
@read_from_stdin = false
end

def read(slice : Bytes)
def read(slice : Bytes) : Int32
first_initialize unless @initialized

if current_io = @current_io
Expand Down
4 changes: 2 additions & 2 deletions src/io/hexdump.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class IO::Hexdump < IO
def initialize(@io : IO, @output : IO = STDERR, @read = false, @write = false)
end

def read(buf : Bytes)
@io.read(buf).tap do |read_bytes|
def read(buf : Bytes) : Int32
@io.read(buf).to_i32.tap do |read_bytes|
buf[0, read_bytes].hexdump(@output) if @read && read_bytes
end
end
Expand Down
4 changes: 2 additions & 2 deletions src/io/sized.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class IO::Sized < IO
@read_remaining = read_size.to_u64
end

def read(slice : Bytes)
def read(slice : Bytes) : Int32
check_open

count = {slice.size.to_u64, @read_remaining}.min
bytes_read = @io.read slice[0, count]
bytes_read = @io.read(slice[0, count]).to_i32
@read_remaining -= bytes_read
bytes_read
end
Expand Down
4 changes: 2 additions & 2 deletions src/io/stapled.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class IO::Stapled < IO
end

# Reads a slice from `reader`.
def read(slice : Bytes)
def read(slice : Bytes) : Int32
check_open

@reader.read(slice)
@reader.read(slice).to_i32
end

# Gets a string from `reader`.
Expand Down

0 comments on commit e8cf88e

Please sign in to comment.