Skip to content

Commit

Permalink
Fix Julia 1.11 IOBuffer/GenericIOBuffer compat issuewq
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnj committed Sep 23, 2024
1 parent 1b4f829 commit 6d4db2a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Streams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,17 @@ function Base.unsafe_read(http::Stream, p::Ptr{UInt8}, n::UInt)
nothing
end

_alloc_request(buf::IOBuffer, recommended_size::UInt) = Base.alloc_request(buf, recommended_size)

function _alloc_request(buffer::Base.GenericIOBuffer, recommended_size::UInt)
Base.ensureroom(buffer, Int(recommended_size))
ptr = buffer.append ? buffer.size + 1 : buffer.ptr
nb = min(length(buffer.data)-buffer.offset, buffer.maxsize) + buffer.offset - ptr + 1
return (Ptr{Cvoid}(pointer(buffer.data, ptr)), nb)
end

function Base.readbytes!(http::Stream, buf::Base.GenericIOBuffer, n=bytesavailable(http))
p, nbmax = Base.alloc_request(buf, UInt(n))
p, nbmax = _alloc_request(buf, UInt(n))
nbmax < n && throw(ArgumentError("Unable to grow response stream IOBuffer $nbmax large enough for response body size: $n"))
GC.@preserve buf unsafe_read(http, p, UInt(n))
# TODO: use `Base.notify_filled(buf, Int(n))` here, but only once it is identical to this:
Expand Down

0 comments on commit 6d4db2a

Please sign in to comment.