Skip to content

Commit

Permalink
support for IOBuffer containing Memory (#1125)
Browse files Browse the repository at this point in the history
* support for IOBuffer containing memory

* fix errors caught in tests

* use Base.wrap if available

---------

Co-authored-by: Viral B. Shah <[email protected]>
  • Loading branch information
longemen3000 and ViralBShah authored Feb 28, 2024
1 parent 66a3a65 commit 141e2e4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions 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
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 @@ -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
Expand Down

0 comments on commit 141e2e4

Please sign in to comment.