Skip to content

Commit

Permalink
Fix input body size detection for IOBuffer(codeunits(str)) (#143)
Browse files Browse the repository at this point in the history
Somewhat surprisingly, the type of this is not IOBuffer, but a related
type (Base.GenericIOBuffer{Base.CodeUnits{UInt8, String}}).
  • Loading branch information
c42f authored Aug 26, 2021
1 parent e22219f commit 470b7f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Downloads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ end
p_func(progress::Nothing, input::ArgRead, output::ArgWrite) = nothing

arg_read_size(path::AbstractString) = filesize(path)
arg_read_size(io::IOBuffer) = io.size - io.ptr + 1
arg_read_size(io::Base.GenericIOBuffer) = bytesavailable(io)
arg_read_size(::Base.DevNull) = 0
arg_read_size(::Any) = nothing

Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,14 @@ include("setup.jl")
Downloads.download("https://httpbingo.org/drip"; downloader=dl)
Downloads.download("https://httpbingo.org/drip"; downloader=dl)
end

@testset "Input body size" begin
# Test mechanism to detect the body size from the request(; input) argument
@test Downloads.arg_read_size(@__FILE__) == filesize(@__FILE__)
@test Downloads.arg_read_size(IOBuffer("αa")) == 3
@test Downloads.arg_read_size(IOBuffer(codeunits("αa"))) == 3 # Issue #142
@test Downloads.arg_read_size(devnull) == 0
end
end

Downloads.DOWNLOADER[] = nothing
Expand Down

0 comments on commit 470b7f0

Please sign in to comment.