Skip to content

Commit

Permalink
Simplify some of the dispatch messiness in #90
Browse files Browse the repository at this point in the history
Possible since we have os/arch specific wrappers now.
  • Loading branch information
ViralBShah committed Aug 22, 2023
1 parent 57cff17 commit 291c113
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GZip"
uuid = "92fee26a-97fe-5a0c-ad85-20a5f3185b63"
authors = ["staticfloat@gmail.com <staticfloat@gmail.com>"]
version = "0.6.0"
version = "0.6.1"

[deps]
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Expand Down
32 changes: 6 additions & 26 deletions src/gz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,31 +136,11 @@ gzwrite(s::GZipStream, p::Ptr, len::Integer) =
gzread(s::GZipStream, p::Ptr, len::Integer) =
@test_gzerror(s, Zlib_h.gzread(s.gz_file, reinterpret(Ptr{Cvoid}, p), Cuint(len)), -1)

global gzbuffer, _gzopen, _gzseek, _gztell, _gzoffset

# Doesn't exist in zlib 1.2.3 or earlier
if Libdl.dlsym_e(Zlib_jll.libz_handle, :gzbuffer) != C_NULL
gzbuffer(gz_file::Zlib_h.gzFile, gz_buf_size::Integer) = Zlib_h.gzbuffer(gz_file, gz_buf_size)
else
gzbuffer(gz_file::Zlib_h.gzFile, gz_buf_size::Integer) = Cint(-1)
end
# Needs zlib 1.2.3 or higher (Julia 1.9 has zlib 1.2.13)
gzbuffer(gz_file::Zlib_h.gzFile, gz_buf_size::Integer) = Zlib_h.gzbuffer(gz_file, gz_buf_size)

Check warning on line 140 in src/gz.jl

View check run for this annotation

Codecov / codecov/patch

src/gz.jl#L140

Added line #L140 was not covered by tests

#####

# Use 64-bit functions if available

if Libdl.dlsym_e(Zlib_jll.libz_handle, :gzopen64) != C_NULL && (z_off_t_sz == 8 || !Sys.iswindows())
const _gzopen = Zlib_h.gzopen64
const _gzseek = Zlib_h.gzseek64
const _gztell = Zlib_h.gztell64
const _gzoffset = Zlib_h.gzoffset64
else
const _gzopen = Zlib_h.gzopen
const _gzseek = Zlib_h.gzseek
const _gztell = Zlib_h.gztell
const _gzoffset = Zlib_h.gzoffset
end

"""
gzopen(fname::AbstractString, [gzmode::AbstractString, buf_size::Integer])::GZipStream
Expand Down Expand Up @@ -207,7 +187,7 @@ function gzopen(fname::AbstractString, gzmode::AbstractString, gz_buf_size::Inte
gzmode *= "b"
end

gz_file = _gzopen(fname, gzmode)
gz_file = Zlib_h.gzopen(fname, gzmode)
if gz_file == C_NULL
errno = unsafe_load(cglobal((:errno, :libc), Cint))
throw(SystemError("$(fname)", errno))
Expand Down Expand Up @@ -306,15 +286,15 @@ function seek(s::GZipStream, n::Integer)
end
end
# Mimic behavior of seek(s::IOStream, n)
_gzseek(s.gz_file, Clong(n), SEEK_SET) != -1 || error("seek (gzseek) failed")
Zlib_h.gzseek(s.gz_file, Clong(n), SEEK_SET) != -1 || error("seek (gzseek) failed")
end

# Note: skips bytes within uncompressed data stream
# Mimic behavior of skip(s::IOStream, n)
skip(s::GZipStream, n::Integer) =
_gzseek(s.gz_file, Clong(n), SEEK_CUR) != -1 || error("skip (gzseek) failed")
Zlib_h.gzseek(s.gz_file, Clong(n), SEEK_CUR) != -1 || error("skip (gzseek) failed")

position(s::GZipStream, raw::Bool=false) = raw ? _gzoffset(s.gz_file) : _gztell(s.gz_file)
position(s::GZipStream, raw::Bool=false) = raw ? Zlib_h.gzoffset(s.gz_file) : Zlib_h.gztell(s.gz_file)

eof(s::GZipStream) = Bool(Zlib_h.gzeof(s.gz_file))

Expand Down
2 changes: 1 addition & 1 deletion src/zlib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const Z_BIG_BUFSIZE = 131072
# Get compile-time option flags
const zlib_compile_flags = Zlib_h.zlibCompileFlags()
const z_off_t_sz = 2 << ((zlib_compile_flags >> 6) & UInt(3))
if z_off_t_sz == 8 || (!Sys.iswindows() && Libdl.dlsym_e(Zlib_jll.libz_handle, :gzopen64) != C_NULL)
if z_off_t_sz == 8 || (!Sys.iswindows() && isdefined(GZip.Zlib_h, :gzopen64))
const ZFileOffset = Int64
elseif z_off_t_sz == 4
const ZFileOffset = Int32
Expand Down

0 comments on commit 291c113

Please sign in to comment.