From 8d2c5a375d1c54f88368e2abbd99c34db7621eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Riedemann?= <38795484+longemen3000@users.noreply.github.com> Date: Tue, 27 Feb 2024 20:17:20 -0300 Subject: [PATCH] use Base.wrap if available --- src/utils.jl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/utils.jl b/src/utils.jl index fdfcc933..d12eb023 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -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 +end + # whatever input is given, turn it into an AbstractVector{UInt8} we can parse with @inline function getbytebuffer(x, buffer_in_memory) tfile = nothing @@ -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