diff --git a/doc/index.rst b/doc/index.rst index c617c52..54564f7 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -24,7 +24,7 @@ Notes * This implementation mimics the :class:`IOStream` implementation, and should be a drop-in replacement for :class:`IOStream`, with some caveats: - * :func:`seek_end` and :func:`truncate` are not available + * :func:`seekend` and :func:`truncate` are not available * :func:`readuntil` is available, but is not very efficient. (But :func:`readline` works fine.) @@ -43,7 +43,7 @@ following :class:`IO`/:class:`IOStream` functions are supported: * :func:`write()` * :func:`peek()` -Due to limitations in ``zlib``, :func:`seek_end` and :func:`truncate` are not available. +Due to limitations in ``zlib``, :func:`seekend` and :func:`truncate` are not available. --------- Functions diff --git a/src/GZip.jl b/src/GZip.jl index e282f0b..51bbc91 100644 --- a/src/GZip.jl +++ b/src/GZip.jl @@ -5,7 +5,7 @@ module GZip using Compat import Base: show, fd, close, flush, truncate, seek, - skip, position, eof, read, readall, + seekend, skip, position, eof, read, readall, readline, write, peek export @@ -140,7 +140,7 @@ macro test_gzerror(s, cc, val) quote if $(esc(s))._closed throw(EOFError()) end ret = $(esc(cc)) - if ret == $(esc(val)) throw(ret, GZError($(esc(s)))) end + if ret == $(esc(val)) throw(GZError(ret, $(esc(s)))) end ret end end @@ -318,7 +318,7 @@ flush(s::GZipStream, fl::Integer) = @test_z_ok ccall((:gzflush, _zlib), Int32, (Ptr{Void}, Int32), s.gz_file, @compat(Int32(fl))) flush(s::GZipStream) = flush(s, Z_SYNC_FLUSH) -truncate(s::GZipStream, n::Integer) = error("truncate is not supported for GZipStreams") +truncate(s::GZipStream, n::Integer) = throw(MethodError(truncate, (GZipStream, Integer))) # Note: seeks to byte position within uncompressed data stream seek(s::GZipStream, n::Integer) = @@ -326,8 +326,6 @@ seek(s::GZipStream, n::Integer) = s.gz_file, n, SEEK_SET)!=-1 || # Mimick behavior of seek(s::IOStream, n) error("seek (gzseek) failed")) -seek_end(s::GZipStream) = error("seek_end is not supported for GZipStreams") - # Note: skips bytes within uncompressed data stream skip(s::GZipStream, n::Integer) = (ccall((_gzseek, _zlib), ZFileOffset, (Ptr{Void}, ZFileOffset, Int32), diff --git a/src/zlib_h.jl b/src/zlib_h.jl index 0dabd34..1e4e6c8 100644 --- a/src/zlib_h.jl +++ b/src/zlib_h.jl @@ -6,7 +6,7 @@ # Constants zlib_version = bytestring(ccall((:zlibVersion, _zlib), Ptr{UInt8}, ())) -ZLIB_VERSION = tuple([parseint(c) for c in split(zlib_version, '.')]...) +ZLIB_VERSION = tuple([parse(Int, c) for c in split(zlib_version, '.')]...) # Flush values const Z_NO_FLUSH = @compat Int32(0) diff --git a/test/runtests.jl b/test/runtests.jl index 392b28e..ad55026 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -10,9 +10,9 @@ using Base.Test tmp = mktempdir() -test_infile = joinpath(JULIA_HOME, "..", "share", "doc", "julia", "helpdb.jl") -test_compressed = "$tmp/julia.gz" -test_empty = "$tmp/empty.jl.gz" +test_infile = Pkg.dir("GZip", "test", "runtests.jl") +test_compressed = joinpath(tmp, "runtests.jl.gz") +test_empty = joinpath(tmp, "empty.jl.gz") @windows_only gunzip="gunzip.exe" @unix_only gunzip="gunzip" @@ -37,7 +37,6 @@ gzfile = gzopen(test_compressed, "wb") @test close(gzfile) == Z_OK @test close(gzfile) != Z_OK -#@test throws_exception(write(gzfile, data), GZError) @test_throws EOFError write(gzfile, data) if test_gunzip @@ -71,9 +70,10 @@ close(raw_file) try gzopen(readall, test_compressed) - throw(Error("Expecting an ArgumentError or similar")) + throw(Error("Expecting ArgumentError or similar")) catch e - @test isa(e, ArgumentError) || contains(e.msg, "too many arguments") + @test typeof(e) <: Union(ArgumentError, ZError, GZError) || + contains(e.msg, "too many arguments") end @@ -90,7 +90,7 @@ pos = position(gzfile) @test skip(gzfile, 100) @test position(gzfile) == pos + 100 -@test_throws ErrorException truncate(gzfile, 100) +@test_throws MethodError truncate(gzfile, 100) @test_throws MethodError seekend(gzfile) @test close(gzfile) == Z_OK @@ -192,8 +192,8 @@ let BUFSIZE = 65536 end # Array file - b_array_fn = "$tmp/b_array.raw.gz" - r_array_fn = "$tmp/r_array.raw.gz" + b_array_fn = joinpath(tmp, "b_array.raw.gz") + r_array_fn = joinpath(tmp, "r_array.raw.gz") gzaf_b = gzopen(b_array_fn, "w$level") write(gzaf_b, b)