diff --git a/src/Downloads.jl b/src/Downloads.jl index 6a6c5cb..fce01ae 100644 --- a/src/Downloads.jl +++ b/src/Downloads.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index ff89dad..0d58422 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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