diff --git a/.travis.yml b/.travis.yml index 7ea58c3..aae7e30 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,9 @@ os: julia: - 0.6 - nightly +matrix: + allow_failures: + - julia: nightly notifications: email: false # uncomment the following lines to override the default test script diff --git a/src/compression.jl b/src/compression.jl index 973f92c..65c8d58 100644 --- a/src/compression.jl +++ b/src/compression.jl @@ -59,6 +59,15 @@ function TranscodingStreams.finalize(codec::ZstdCompression) return end +function TranscodingStreams.startproc(codec::ZstdCompression, mode::Symbol, error::Error) + code = reset!(codec.cstream, 0 #=unknown source size=#) + if iserror(code) + error[] = ErrorException("zstd error") + return :error + end + return :ok +end + function TranscodingStreams.process(codec::ZstdCompression, input::Memory, output::Memory, error::Error) cstream = codec.cstream cstream.ibuffer.src = input.ptr diff --git a/src/decompression.jl b/src/decompression.jl index 904a5d5..8b00734 100644 --- a/src/decompression.jl +++ b/src/decompression.jl @@ -48,6 +48,15 @@ function TranscodingStreams.finalize(codec::ZstdDecompression) return end +function TranscodingStreams.startproc(codec::ZstdDecompression, mode::Symbol, error::Error) + code = reset!(codec.dstream) + if iserror(code) + error[] = ErrorException("zstd error") + return :error + end + return :ok +end + function TranscodingStreams.process(codec::ZstdDecompression, input::Memory, output::Memory, error::Error) dstream = codec.dstream dstream.ibuffer.src = input.ptr diff --git a/src/libzstd.jl b/src/libzstd.jl index 554cd28..e7186fb 100644 --- a/src/libzstd.jl +++ b/src/libzstd.jl @@ -60,6 +60,10 @@ function initialize!(cstream::CStream, level::Integer) return ccall((:ZSTD_initCStream, libzstd), Csize_t, (Ptr{Void}, Cint), cstream.ptr, level) end +function reset!(cstream::CStream, srcsize::Integer) + return ccall((:ZSTD_resetCStream, libzstd), Csize_t, (Ptr{Void}, Culonglong), cstream.ptr, srcsize) +end + function compress!(cstream::CStream) return ccall((:ZSTD_compressStream, libzstd), Csize_t, (Ptr{Void}, Ptr{Void}, Ptr{Void}), cstream.ptr, pointer_from_objref(cstream.obuffer), pointer_from_objref(cstream.ibuffer)) end @@ -91,6 +95,10 @@ function initialize!(dstream::DStream) return ccall((:ZSTD_initDStream, libzstd), Csize_t, (Ptr{Void},), dstream.ptr) end +function reset!(dstream::DStream) + return ccall((:ZSTD_resetDStream, libzstd), Csize_t, (Ptr{Void},), dstream.ptr) +end + function decompress!(dstream::DStream) return ccall((:ZSTD_decompressStream, libzstd), Csize_t, (Ptr{Void}, Ptr{Void}, Ptr{Void}), dstream.ptr, pointer_from_objref(dstream.obuffer), pointer_from_objref(dstream.ibuffer)) end