Skip to content

Commit

Permalink
use Base.wrap if available
Browse files Browse the repository at this point in the history
  • Loading branch information
longemen3000 authored Feb 27, 2024
1 parent 69c8453 commit 8d2c5a3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ end
# one-liner suggested from ScottPJones
consumeBOM(buf, pos) = (length(buf) >= 3 && buf[pos] == 0xef && buf[pos + 1] == 0xbb && buf[pos + 2] == 0xbf) ? pos + 3 : pos

if isdefined(Base,:wrap)
__wrap(x,pos) = Base.wrap(Array,x,pos)
else
__wrap(x,pos) = x

Check warning on line 251 in src/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils.jl#L251

Added line #L251 was not covered by tests
end

# whatever input is given, turn it into an AbstractVector{UInt8} we can parse with
@inline function getbytebuffer(x, buffer_in_memory)
tfile = nothing
Expand All @@ -261,7 +267,8 @@ consumeBOM(buf, pos) = (length(buf) >= 3 && buf[pos] == 0xef && buf[pos + 1] ==
x = x.data
return parent(x), first(x.indices), last(x.indices), tfile
else #support from IOBuffer containing Memory
return take!(x), x.ptr, x.size, tfile
y = __wrap(x.data,length(x.data)) #generates a Vector{UInt8} from Memory{UInt8}
return y, x.ptr, x.size, tfile
end
elseif x isa Cmd || x isa IO
if buffer_in_memory
Expand Down

0 comments on commit 8d2c5a3

Please sign in to comment.