Skip to content

Commit

Permalink
Add GZip.GZLIB_VERSION and make new position() call dependent on havi…
Browse files Browse the repository at this point in the history
…ng a recent enough version)
  • Loading branch information
quinnj committed May 8, 2015
1 parent 88d438c commit 2dcb99a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Binary file added .DS_Store
Binary file not shown.
9 changes: 8 additions & 1 deletion src/GZip.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export

include("zlib_h.jl")

const GZLIB_VERSION = bytestring(ccall((:zlibVersion, GZip._zlib), Ptr{UInt8}, ()))

# Expected line length for strings
const GZ_LINE_BUFSIZE = 256

Expand Down Expand Up @@ -340,9 +342,14 @@ skip(s::GZipStream, n::Integer) =
s.gz_file, n, SEEK_CUR)!=-1 ||
error("skip (gzseek) failed")) # Mimick behavior of skip(s::IOStream, n)

position(s::GZipStream, of_raw::Bool=false) = of_raw ?
if GZLIB_VERSION > "1.2.2.4"
position(s::GZipStream, raw::Bool=false) = raw ?
ccall((_gzoffset, _zlib), ZFileOffset, (Ptr{Void},), s.gz_file) :
ccall((_gztell, _zlib), ZFileOffset, (Ptr{Void},), s.gz_file)
else
position(s::GZipStream, raw::Bool=false) =
ccall((_gztell, _zlib), ZFileOffset, (Ptr{Void},), s.gz_file)
end

eof(s::GZipStream) = @compat Bool(ccall((:gzeof, _zlib), Int32, (Ptr{Void},), s.gz_file))

Expand Down
7 changes: 4 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ gzfile = gzopen(test_compressed, "wb")
write(gzfile, data) == length(data.data)
@test flush(gzfile) == Z_OK

NEW = GZip.GZLIB_VERSION > "1.2.2.4"
pos = position(gzfile)
pos2 = position(gzfile,true)
NEW && (pos2 = position(gzfile,true))
@test_throws ErrorException seek(gzfile, 100) # can't seek backwards on write
@test position(gzfile) == pos
@test position(gzfile,true) == pos2
NEW && (@test position(gzfile,true) == pos2)
@test skip(gzfile, 100)
@test position(gzfile) == pos + 100
@test position(gzfile,true) == pos
NEW && (@test position(gzfile,true) == pos2)

@test_throws MethodError truncate(gzfile, 100)
@test_throws MethodError seekend(gzfile)
Expand Down

0 comments on commit 2dcb99a

Please sign in to comment.