From 141e2e45676c702a73d85edae5ff89ee8ce0aa37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Riedemann?= <38795484+longemen3000@users.noreply.github.com> Date: Wed, 28 Feb 2024 01:21:18 -0300 Subject: [PATCH] support for IOBuffer containing `Memory` (#1125) * support for IOBuffer containing memory * fix errors caught in tests * use Base.wrap if available --------- Co-authored-by: Viral B. Shah --- src/utils.jl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/utils.jl b/src/utils.jl index 6bfa36e8..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 @@ -260,6 +266,9 @@ consumeBOM(buf, pos) = (length(buf) >= 3 && buf[pos] == 0xef && buf[pos + 1] == elseif x.data isa SubArray{UInt8} x = x.data return parent(x), first(x.indices), last(x.indices), tfile + else #support from IOBuffer containing Memory + 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