diff --git a/src/read.jl b/src/read.jl index 50354d4..b689f61 100644 --- a/src/read.jl +++ b/src/read.jl @@ -4,6 +4,7 @@ struct VectorString{T <: AbstractVector{UInt8}} <: AbstractString end Base.codeunits(x::VectorString) = x.bytes +read_json_str(json::VectorString) = json # high-level user API functions read(io::Union{IO, Base.AbstractCmd}; kw...) = read(Base.read(io, String); kw...) diff --git a/src/utils.jl b/src/utils.jl index 63fa16c..8609047 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -192,7 +192,18 @@ end function read_json_str(json) # length check is to ensure that isfile doesn't thrown an error # see issue for details https://github.com/JuliaLang/julia/issues/39774 - !(json isa VectorString) && sizeof(json) < 255 && isfile(json) ? - VectorString(Mmap.mmap(json)) : - json + isfilename(json) && isfile(json) ? + VectorString(Mmap.mmap(json)) : + json +end + +isfilename(filename) = try + stat(filename) + true +catch e + if isa(e, Base.IOError) + e.code != -36 # -36 is ENAMETOOLONG; other IO errors indicate valid filename + else + rethrow() + end end