Skip to content

Commit 040cf0a

Browse files
authored
delete ByteView (#1149)
* delete ByteView * Update Streams.jl * Use `isempty` instead equality with an empty buffer
1 parent 581c6fc commit 040cf0a

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/Connections.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,12 @@ Read until `find_delimiter(bytes)` returns non-zero.
234234
Return view of bytes up to the delimiter.
235235
"""
236236
function IOExtras.readuntil(c::Connection, f::F #=Vector{UInt8} -> Int=#,
237-
sizehint=4096)::ByteView where {F <: Function}
237+
sizehint=4096) where {F <: Function}
238238
buf = c.buffer
239239
if bytesavailable(buf) == 0
240240
read_to_buffer(c, sizehint)
241241
end
242-
while (bytes = IOExtras.readuntil(buf, f)) == nobytes
242+
while isempty(begin bytes = IOExtras.readuntil(buf, f) end)
243243
read_to_buffer(c, sizehint)
244244
end
245245
return bytes

src/IOExtras.jl

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ using Sockets
1111
using MbedTLS: SSLContext, MbedException
1212
using OpenSSL: SSLStream
1313

14-
export bytes, isbytes, nbytes, ByteView, nobytes,
14+
export bytes, isbytes, nbytes, nobytes,
1515
startwrite, closewrite, startread, closeread, readuntil,
1616
tcpsocket, localport, safe_getpeername
1717

@@ -104,7 +104,6 @@ function safe_getpeername(io)
104104
end
105105

106106

107-
const ByteView = typeof(view(UInt8[], 1:0))
108107
const nobytes = view(UInt8[], 1:0)
109108

110109
readuntil(args...) = Base.readuntil(args...)
@@ -114,8 +113,8 @@ Read from an `IO` stream until `find_delimiter(bytes)` returns non-zero.
114113
Return view of bytes up to the delimiter.
115114
"""
116115
function readuntil(buf::IOBuffer,
117-
find_delimiter::F #= Vector{UInt8} -> Int =#
118-
)::ByteView where {F <: Function}
116+
find_delimiter::F #= Vector{UInt8} -> Int =#
117+
) where {F <: Function}
119118
l = find_delimiter(view(buf.data, buf.ptr:buf.size))
120119
if l == 0
121120
return nobytes

src/Streams.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,15 @@ function readall!(http::Stream, buf::Base.GenericIOBuffer=PipeBuffer())
320320
return n
321321
end
322322

323-
function IOExtras.readuntil(http::Stream, f::Function)::ByteView
323+
function IOExtras.readuntil(http::Stream, f::Function)
324324
UInt(ntoread(http)) == 0 && return Connections.nobytes
325325
try
326326
bytes = IOExtras.readuntil(http.stream, f)
327327
update_ntoread(http, length(bytes))
328328
return bytes
329-
catch
329+
catch ex
330330
# if we error, it means we didn't find what we were looking for
331+
# TODO: this seems very sketchy
331332
return UInt8[]
332333
end
333334
end

0 commit comments

Comments
 (0)