Skip to content

Commit

Permalink
Merge bug and testfixes, including the rest of #20
Browse files Browse the repository at this point in the history
Closes #20
  • Loading branch information
garborg committed Mar 18, 2015
1 parent a506d5e commit c1f70c7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
4 changes: 2 additions & 2 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.)

Expand All @@ -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
Expand Down
8 changes: 3 additions & 5 deletions src/GZip.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -318,16 +318,14 @@ 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) =
(ccall((_gzseek, _zlib), ZFileOffset, (Ptr{Void}, ZFileOffset, Int32),
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),
Expand Down
2 changes: 1 addition & 1 deletion src/zlib_h.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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


Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c1f70c7

Please sign in to comment.