11# This file was copied from https://github.com/dcjones/Zlib.jl
22#
33# Zlib is licensed under the MIT License:
4- #
4+ #
55# > Copyright (c) 2013: Daniel C. Jones
66# >
77# > Permission is hereby granted, free of charge, to any person obtaining
2525
2626module Zlib
2727
28- using Compat
29-
3028import Base: read, read!, readuntil, readbytes!, write, close, eof
3129
3230export compress, decompress, crc32
@@ -49,7 +47,7 @@ const Z_MEM_ERROR = -4
4947const Z_BUF_ERROR = - 5
5048const Z_VERSION_ERROR = - 6
5149
52- if Compat . Sys. iswindows ()
50+ if Sys. iswindows ()
5351 const libz = " zlib1"
5452else
5553 const libz = " libz"
@@ -66,11 +64,11 @@ mutable struct z_stream
6664 total_out:: Culong
6765
6866 msg:: Ptr{UInt8}
69- state:: Ptr{Compat. Cvoid}
67+ state:: Ptr{Cvoid}
7068
71- zalloc:: Ptr{Compat. Cvoid}
72- zfree:: Ptr{Compat. Cvoid}
73- opaque:: Ptr{Compat. Cvoid}
69+ zalloc:: Ptr{Cvoid}
70+ zfree:: Ptr{Cvoid}
71+ opaque:: Ptr{Cvoid}
7472
7573 data_type:: Cint
7674 adler:: Culong
@@ -106,7 +104,7 @@ mutable struct Writer <: IO
106104 closed:: Bool
107105
108106 Writer (strm:: z_stream , io:: IO , closed:: Bool ) =
109- (w = new (strm, io, closed); @compat ( finalizer (close, w) ); w)
107+ (w = new (strm, io, closed); finalizer (close, w); w)
110108end
111109
112110function Writer (io:: IO , level:: Integer , raw:: Bool = false )
@@ -131,7 +129,7 @@ Writer(io::IO, raw::Bool=false) = Writer(io, 9, raw)
131129function write (w:: Writer , p:: Ptr , nb:: Integer )
132130 w. strm. next_in = p
133131 w. strm. avail_in = nb
134- outbuf = Vector {UInt8} (Compat . undef, 1024 )
132+ outbuf = Vector {UInt8} (undef, 1024 )
135133
136134 while true
137135 w. strm. avail_out = length (outbuf)
@@ -203,10 +201,10 @@ function close(w::Writer)
203201 w. closed = true
204202
205203 # flush zlib buffer using Z_FINISH
206- inbuf = Vector {UInt8} (Compat . undef, 0 )
204+ inbuf = Vector {UInt8} (undef, 0 )
207205 w. strm. next_in = pointer (inbuf)
208206 w. strm. avail_in = 0
209- outbuf = Vector {UInt8} (Compat . undef, 1024 )
207+ outbuf = Vector {UInt8} (undef, 1024 )
210208 ret = Z_OK
211209 while ret != Z_STREAM_END
212210 w. strm. avail_out = length (outbuf)
@@ -239,7 +237,7 @@ mutable struct Reader <: IO
239237 stream_end:: Bool
240238
241239 Reader (strm:: z_stream , io:: IO , buf:: IOBuffer , closed:: Bool , bufsize:: Int ) =
242- (r = new (strm, io, buf, closed, bufsize, false ); @compat ( finalizer (close, r) ); r)
240+ (r = new (strm, io, buf, closed, bufsize, false ); finalizer (close, r); r)
243241end
244242
245243function Reader (io:: IO , raw:: Bool = false ; bufsize:: Int = 4096 )
@@ -258,11 +256,11 @@ end
258256# unless we have already reached EOF.
259257function fillbuf (r:: Reader , minlen:: Integer )
260258 ret = Z_OK
261- while Compat . bytesavailable (r. buf) < minlen && ! eof (r. io) && ret != Z_STREAM_END
262- input = read! (r. io, Array {UInt8} (Compat . undef, min (Compat . bytesavailable (r. io), r. bufsize)))
259+ while bytesavailable (r. buf) < minlen && ! eof (r. io) && ret != Z_STREAM_END
260+ input = read! (r. io, Array {UInt8} (undef, min (bytesavailable (r. io), r. bufsize)))
263261 r. strm. next_in = pointer (input)
264262 r. strm. avail_in = length (input)
265- # outbuf = Vector{UInt8}(Compat. undef, r.bufsize)
263+ # outbuf = Vector{UInt8}(undef, r.bufsize)
266264
267265 while true
268266 # r.strm.next_out = outbuf
@@ -293,7 +291,7 @@ function fillbuf(r::Reader, minlen::Integer)
293291 r. stream_end = true
294292 end
295293
296- Compat . bytesavailable (r. buf)
294+ bytesavailable (r. buf)
297295end
298296
299297# This is to fix the ambiguity with Base.read!
321319
322320# This function needs to be fast because other read calls use it.
323321function read (r:: Reader , :: Type{UInt8} )
324- if Compat . bytesavailable (r. buf) < 1 && fillbuf (r, 1 ) < 1
322+ if bytesavailable (r. buf) < 1 && fillbuf (r, 1 ) < 1
325323 throw (EOFError ())
326324 end
327325 read (r. buf, UInt8)
@@ -335,17 +333,17 @@ readbytes!(r::Reader, b::AbstractArray{UInt8}, nb=length(b)) =
335333function readuntil (r:: Reader , delim:: UInt8 )
336334 nb = readuntil (r. buf, delim)
337335 while nb == 0
338- offset = Compat . bytesavailable (r. buf)
336+ offset = bytesavailable (r. buf)
339337 fillbuf (r, offset+ r. bufsize)
340- if Compat . bytesavailable (r. buf) == nb
338+ if bytesavailable (r. buf) == nb
341339 break
342340 end
343341 # TODO : add offset here when https://github.com/JuliaLang/julia/pull/4485
344342 # is merged
345343 nb = readuntil (r. buf, delim) # , offset)
346344 end
347- if nb == 0 ; nb == Compat . bytesavailable (r. buf); end
348- read! (r. buf, Vector {UInt8} (Compat . undef, nb))
345+ if nb == 0 ; nb == bytesavailable (r. buf); end
346+ read! (r. buf, Vector {UInt8} (undef, nb))
349347end
350348
351349function close (r:: Reader )
@@ -366,7 +364,7 @@ function eof(r::Reader)
366364 # yield no uncompressed data. So, make sure we can get at least
367365 # one more byte of decompressed data before we say we haven't
368366 # reached EOF yet.
369- Compat . bytesavailable (r. buf) == 0 && eof (r. io)
367+ bytesavailable (r. buf) == 0 && eof (r. io)
370368end
371369
372370function crc32 (data:: Vector{UInt8} , crc:: Integer = 0 )
0 commit comments