Skip to content

Commit

Permalink
Switches to dispatch-based approach
Browse files Browse the repository at this point in the history
  • Loading branch information
morris25 committed Oct 18, 2019
1 parent 863c088 commit a024a72
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,23 +175,20 @@ function slurp(source)
return final
end

getsource(source::Vector{UInt8}, ::Any) = source
getsource(source::Cmd, ::Any) = Base.read(source)
getsource(source::AbstractPath, ::Any) = Base.read(open(source))
getsource(source::IO, ::Any) = slurp(source)
getsource(source::SystemPath, use_mmap) = getsource(string(source), use_mmap)
function getsource(source, use_mmap)
if source isa Vector{UInt8}
return source
elseif source isa Cmd || (source isa AbstractPath && !isa(source, SystemPath))
return Base.read(open(source))
elseif !isa(source, IO)
m = Mmap.mmap(source isa AbstractPath ? open(source) : source)
if use_mmap
return m
end
m2 = Mmap.mmap(Vector{UInt8}, length(m))
copyto!(m2, 1, m, 1, length(m))
finalize(m)
return m2
else
return slurp(source isa IO ? source : open(String(source)))
m = Mmap.mmap(source)
if use_mmap
return m
end
m2 = Mmap.mmap(Vector{UInt8}, length(m))
copyto!(m2, 1, m, 1, length(m))
finalize(m)
return m2
end

getname(buf::Vector{UInt8}) = "<raw buffer>"
Expand Down

0 comments on commit a024a72

Please sign in to comment.