From 907485ca6b358a15e4eb6dfea21823a2654bfd2e Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Sat, 10 Sep 2016 13:01:18 -0700 Subject: [PATCH] Add more utilities (#4) [av skip] --- src/ZStd.jl | 23 +++++++++++++++++++++++ test/runtests.jl | 7 +++++++ 2 files changed, 30 insertions(+) diff --git a/src/ZStd.jl b/src/ZStd.jl index 1fdb5ae..237b0a0 100644 --- a/src/ZStd.jl +++ b/src/ZStd.jl @@ -36,4 +36,27 @@ An integer representing the maximum compression level available. const MAX_COMPRESSION = Int(ccall((:ZSTD_maxCLevel, libzstd), Cint, ())) +""" + maxcompressedsize(srcsize) + +Get the maximum compressed size in the worst-case scenario for a given input size. +""" +function maxcompressedsize(srcsize::Csize_t) + return ccall((:ZSTD_compressBound, libzstd), Csize_t, (Csize_t, ), srcsize) +end + +maxcompressedsize(srcsize::Int) = Int(maxcompressedsize(Csize_t(srcsize))) + + +""" + ZStd.ZSTD_VERSION + +The version of Zstandard in use. +""" +const ZSTD_VERSION = let + ver = Int(ccall((:ZSTD_versionNumber, libzstd), Cuint, ())) + str = join(match(r"(\d+)(\d{2})(\d{2})$", string(ver)).captures, ".") + VersionNumber(str) +end + end # module diff --git a/test/runtests.jl b/test/runtests.jl index 7274d89..540f4ec 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -17,4 +17,11 @@ using Base.Test err_txt = sprint(showerror, err) @test startswith(err_txt, "ZStd: Error (generic)") end + + @test typeof(ZStd.maxcompressedsize(1)) == Int + @test ZStd.maxcompressedsize(1) > 0 + @test typeof(ZStd.maxcompressedsize(UInt(1))) == UInt + @test ZStd.maxcompressedsize(UInt(1)) > UInt(0) + + @test ZStd.ZSTD_VERSION == v"1.0.0" end