Skip to content
This repository has been archived by the owner on May 29, 2018. It is now read-only.

Commit

Permalink
Add more utilities (#4)
Browse files Browse the repository at this point in the history
[av skip]
  • Loading branch information
ararslan committed Sep 10, 2016
1 parent c587a80 commit 907485c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/ZStd.jl
Expand Up @@ -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
7 changes: 7 additions & 0 deletions test/runtests.jl
Expand Up @@ -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

0 comments on commit 907485c

Please sign in to comment.