diff --git a/src/memory.jl b/src/memory.jl index 35c39497..d558076d 100644 --- a/src/memory.jl +++ b/src/memory.jl @@ -11,6 +11,10 @@ struct Memory size::UInt end +function Memory(data::Vector{UInt8}) + return Memory(pointer(data), sizeof(data)) +end + @inline function Base.length(mem::Memory) return mem.size end diff --git a/test/runtests.jl b/test/runtests.jl index 91e973fb..38f8d5e4 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -94,7 +94,7 @@ end end data = Vector{UInt8}(b"foobar") - GC.@preserve data let mem = TranscodingStreams.Memory(pointer(data), sizeof(data)) + GC.@preserve data let mem = TranscodingStreams.Memory(data) @test mem isa TranscodingStreams.Memory @test mem.ptr == pointer(data) @test mem.size == sizeof(data)