BioJulia / Libz.jl

Fast, flexible zlib bindings.
Other
27 stars 17 forks source link

Incorrect function descriptions in README #37

Closed tlnagy closed 8 years ago

tlnagy commented 8 years ago

There is some code in NRRD.jl that looks like the following

function FileIO.load(io::Stream{format"NRRD"}; mmap=:auto)
    io = stream(io)
    ...
    sdata = io
    ...
    sdata = Zlib.Reader(sdata)
    ...
    A = read(sdata, T, sz...)
end

I would like to convert this to Libz. How can I do this? My first attempt doesn't work and I'm not sure what else to try.

function FileIO.load(io::Stream{format"NRRD"}; mmap=:auto)
    io = stream(io)
    ...
    sdata = io
    ...
    sdata = Libz.ZlibInflateOutputStream(sdata)
    ...
    A = read(sdata, T, sz...)
end

but this gives me the following error:

ERROR: LoadError: BufferedStreams.BufferedOutputStream{Libz.Sink{:inflate,BufferedStreams.BufferedOutputStream{IOStream}}} does not support byte I/O
 in unsafe_read(::BufferedStreams.BufferedOutputStream{Libz.Sink{:inflate,BufferedStreams.BufferedOutputStream{IOStream}}}, ::Ptr{UInt8}, ::UInt64) at ./io.jl:71
 in read!(::BufferedStreams.BufferedOutputStream{Libz.Sink{:inflate,BufferedStreams.BufferedOutputStream{IOStream}}}, ::Array{Float32,3}) at ./io.jl:248
 in read(::BufferedStreams.BufferedOutputStream{Libz.Sink{:inflate,BufferedStreams.BufferedOutputStream{IOStream}}}, ::Type{Float32}, ::Int64, ::Int64, ::Vararg{Int64,N}) at ./io.jl:235
 in #load#2(::Symbol, ::Function, ::FileIO.Stream{FileIO.DataFormat{:NRRD},IOStream}) at /Users/tamasnagy/.julia/v0.5/NRRD/src/NRRD.jl:162
 in (::FileIO.#kw##load)(::Array{Any,1}, ::FileIO.#load, ::FileIO.Stream{FileIO.DataFormat{:NRRD},IOStream}) at ./<missing>:0
 in #load#1(::Symbol, ::Function, ::FileIO.File{FileIO.DataFormat{:NRRD}}) at /Users/tamasnagy/.julia/v0.5/NRRD/src/NRRD.jl:84
 in load(::FileIO.File{FileIO.DataFormat{:NRRD}}) at /Users/tamasnagy/.julia/v0.5/NRRD/src/NRRD.jl:82
 in #load#13(::Array{Any,1}, ::Function, ::String) at /Users/tamasnagy/.julia/v0.5/FileIO/src/loadsave.jl:45
 in (::##20#55{String})() at /Users/tamasnagy/.julia/v0.5/NRRD/test/runtests.jl:41
 in context(::##20#55{String}, ::String) at /Users/tamasnagy/.julia/v0.5/FactCheck/src/FactCheck.jl:475
 in (::##1#36)() at /Users/tamasnagy/.julia/v0.5/NRRD/test/runtests.jl:40
 in facts(::##1#36, ::String) at /Users/tamasnagy/.julia/v0.5/FactCheck/src/FactCheck.jl:449
 in include_from_node1(::String) at ./loading.jl:488
 in include_from_node1(::String) at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
 in process_options(::Base.JLOptions) at ./client.jl:262
 in _start() at ./client.jl:318
 in _start() at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
while loading /Users/tamasnagy/.julia/v0.5/NRRD/test/runtests.jl, in expression starting on line 10

Not sure how to do byte I/O with Libz

bicycle1885 commented 8 years ago

ZlibInflateOutputStream is designed for writing data, not for reading. I guess what you need is ZlibInflateInputStream.

tlnagy commented 8 years ago

Thanks. That fixed by problem, but then I think the following line in the README is very confusing:

ZlibInflateInputStream = write and decompress data

I was reading data from a file?

bicycle1885 commented 8 years ago

Oh no, the README swaps the words. ZlibInflateInputStream is a stream to read data from.

tlnagy commented 8 years ago

I updated the issue title to reflect this problem.

bicycle1885 commented 8 years ago

Thanks. The README is fixed.