From 0580f9ea915ec4f9d11f42867c50855e1bf11274 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 01:41:53 -0300 Subject: [PATCH 1/3] support for IOBuffer containing memory --- src/utils.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utils.jl b/src/utils.jl index 6bfa36e8..61ee4b55 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -260,6 +260,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 + _x = take!(x) + return _x, 1, length(_x), tfile end elseif x isa Cmd || x isa IO if buffer_in_memory From 69c845353bcf07b551c164087864c9d914cfaa8e 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 19:19:52 -0300 Subject: [PATCH 2/3] fix errors caught in tests --- src/utils.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index 61ee4b55..fdfcc933 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -261,8 +261,7 @@ 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 - _x = take!(x) - return _x, 1, length(_x), tfile + return take!(x), x.ptr, x.size, tfile end elseif x isa Cmd || x isa IO if buffer_in_memory 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 3/3] 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