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

delete ByteView #1149

Merged
merged 3 commits into from
Feb 17, 2024
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
4 changes: 2 additions & 2 deletions src/Connections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@ Read until `find_delimiter(bytes)` returns non-zero.
Return view of bytes up to the delimiter.
"""
function IOExtras.readuntil(c::Connection, f::F #=Vector{UInt8} -> Int=#,
sizehint=4096)::ByteView where {F <: Function}
sizehint=4096) where {F <: Function}
buf = c.buffer
if bytesavailable(buf) == 0
read_to_buffer(c, sizehint)
end
while (bytes = IOExtras.readuntil(buf, f)) == nobytes
while isempty(begin bytes = IOExtras.readuntil(buf, f) end)
read_to_buffer(c, sizehint)
end
return bytes
Expand Down
7 changes: 3 additions & 4 deletions src/IOExtras.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using Sockets
using MbedTLS: SSLContext, MbedException
using OpenSSL: SSLStream

export bytes, isbytes, nbytes, ByteView, nobytes,
export bytes, isbytes, nbytes, nobytes,
startwrite, closewrite, startread, closeread, readuntil,
tcpsocket, localport, safe_getpeername

Expand Down Expand Up @@ -104,7 +104,6 @@ function safe_getpeername(io)
end


const ByteView = typeof(view(UInt8[], 1:0))
const nobytes = view(UInt8[], 1:0)

readuntil(args...) = Base.readuntil(args...)
Expand All @@ -114,8 +113,8 @@ Read from an `IO` stream until `find_delimiter(bytes)` returns non-zero.
Return view of bytes up to the delimiter.
"""
function readuntil(buf::IOBuffer,
find_delimiter::F #= Vector{UInt8} -> Int =#
)::ByteView where {F <: Function}
find_delimiter::F #= Vector{UInt8} -> Int =#
) where {F <: Function}
l = find_delimiter(view(buf.data, buf.ptr:buf.size))
if l == 0
return nobytes
Expand Down
5 changes: 3 additions & 2 deletions src/Streams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,15 @@ function readall!(http::Stream, buf::Base.GenericIOBuffer=PipeBuffer())
return n
end

function IOExtras.readuntil(http::Stream, f::Function)::ByteView
function IOExtras.readuntil(http::Stream, f::Function)
UInt(ntoread(http)) == 0 && return Connections.nobytes
try
bytes = IOExtras.readuntil(http.stream, f)
update_ntoread(http, length(bytes))
return bytes
catch
catch ex
# if we error, it means we didn't find what we were looking for
# TODO: this seems very sketchy
return UInt8[]
end
end
Expand Down
Loading