Skip to content

Commit 998d334

Browse files
RalphASfhs
authored andcommitted
remove compat, fix read! call (#44)
* Remove Compat * correct Base method name Closes #43
1 parent b795c9c commit 998d334

File tree

6 files changed

+43
-48
lines changed

6 files changed

+43
-48
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ os:
33
- linux
44
- osx
55
julia:
6-
- 0.6
6+
- 0.7
77
- 1.0
88
- nightly
99
notifications:

REQUIRE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
julia 0.6
2-
Compat 0.59.0
1+
julia 0.7

src/ZipFile.jl

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
VERSION < v"0.7.0-beta2.199" && __precompile__()
2-
31
"""
42
A Julia package for reading/writing ZIP archive files
53
@@ -38,8 +36,7 @@ Julia
3836
module ZipFile
3937

4038
import Base: read, eof, write, close, mtime, position, show, unsafe_write
41-
using Compat
42-
using Compat.Printf
39+
using Printf
4340

4441
export read, eof, write, close, mtime, position, show
4542

@@ -108,7 +105,7 @@ mutable struct Reader
108105
diroff, nfiles, comment = _find_diroffset(io, endoff)
109106
files = _getfiles(io, diroff, nfiles)
110107
x = new(io, close_io, files, comment)
111-
@compat finalizer(close, x)
108+
finalizer(close, x)
112109
x
113110
end
114111
end
@@ -145,7 +142,7 @@ mutable struct WritableFile <: IO
145142
end
146143
f = new(io, name, method, dostime, dosdate, crc32,
147144
compressedsize, uncompressedsize, _offset, _datapos, _zio, _closed)
148-
@compat finalizer(close, f)
145+
finalizer(close, f)
149146
f
150147
end
151148
end
@@ -167,7 +164,7 @@ mutable struct Writer
167164

168165
function Writer(io::IO, close_io::Bool)
169166
x = new(io, close_io, WritableFile[], nothing, false)
170-
@compat finalizer(close, x)
167+
finalizer(close, x)
171168
x
172169
end
173170
end
@@ -276,7 +273,7 @@ function _find_enddiroffset(io::IO)
276273
k = min(filesize, guess)
277274
n = filesize-k
278275
seek(io, n)
279-
b = read!(io, Array{UInt8}(Compat.undef, k))
276+
b = read!(io, Array{UInt8}(undef, k))
280277
for i in 1:k-3
281278
if getindex_u32le(b, i) == _EndCentralDirSig
282279
offset = n+i-1
@@ -300,13 +297,13 @@ function _find_diroffset(io::IO, enddiroffset::Integer)
300297
skip(io, 4)
301298
offset = readle(io, UInt32)
302299
commentlen = readle(io, UInt16)
303-
comment = utf8_validate(read!(io, Array{UInt8}(Compat.undef, commentlen)))
300+
comment = utf8_validate(read!(io, Array{UInt8}(undef, commentlen)))
304301
offset, nfiles, comment
305302
end
306303

307304
function _getfiles(io::IO, diroffset::Integer, nfiles::Integer)
308305
seek(io, diroffset)
309-
files = Vector{ReadableFile}(Compat.undef, nfiles)
306+
files = Vector{ReadableFile}(undef, nfiles)
310307
for i in 1:nfiles
311308
if readle(io, UInt32) != _CentralDirSig
312309
error("invalid file header")
@@ -327,7 +324,7 @@ function _getfiles(io::IO, diroffset::Integer, nfiles::Integer)
327324
commentlen = readle(io, UInt16)
328325
skip(io, 2+2+4)
329326
offset = readle(io, UInt32)
330-
name = utf8_validate(read!(io, Array{UInt8}(Compat.undef, namelen)))
327+
name = utf8_validate(read!(io, Array{UInt8}(undef, namelen)))
331328
skip(io, extralen+commentlen)
332329
files[i] = ReadableFile(io, name, method, dostime, dosdate,
333330
crc32, compsize, uncompsize, offset)
@@ -371,7 +368,7 @@ function close(w::Writer)
371368
_writele(w._io, UInt32(f.crc32))
372369
_writele(w._io, UInt32(f.compressedsize))
373370
_writele(w._io, UInt32(f.uncompressedsize))
374-
b = Vector{UInt8}(Compat.codeunits(f.name))
371+
b = Vector{UInt8}(codeunits(f.name))
375372
_writele(w._io, UInt16(length(b)))
376373
_writele(w._io, UInt16(0))
377374
_writele(w._io, UInt16(0))
@@ -426,7 +423,9 @@ end
426423
# Read data into a. Throws EOFError if a cannot be filled in completely.
427424
function read(f::ReadableFile, a::Array{T}) where T
428425
if !isbitstype(T)
429-
return invoke(read, Tuple{IO,Array}, f, a)
426+
# may need to wrap in invoke() if this package is refactored to overload read!
427+
# return invoke(read!, Tuple{IO,Array}, f, a)
428+
return read!(f, a)
430429
end
431430

432431
if f._datapos < 0
@@ -451,7 +450,7 @@ function read(f::ReadableFile, a::Array{T}) where T
451450
end
452451

453452
seek(f._io, f._datapos+f._zpos)
454-
b = Array{UInt8}(Compat.undef, sizeof(a))
453+
b = Array{UInt8}(undef, sizeof(a))
455454
read!(f._zio, b)
456455
f._zpos = position(f._io) - f._datapos
457456
f._pos += length(b)
@@ -510,7 +509,7 @@ function addfile(w::Writer, name::AbstractString; method::Integer=Store, mtime::
510509
_writele(w._io, UInt32(f.crc32)) # filler
511510
_writele(w._io, UInt32(f.compressedsize)) # filler
512511
_writele(w._io, UInt32(f.uncompressedsize)) # filler
513-
b = Vector{UInt8}(Compat.codeunits(f.name))
512+
b = Vector{UInt8}(codeunits(f.name))
514513
_writele(w._io, UInt16(length(b)))
515514
_writele(w._io, UInt16(0))
516515
_writele(w._io, b)

src/Zlib.jl

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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
@@ -25,8 +25,6 @@
2525

2626
module Zlib
2727

28-
using Compat
29-
3028
import Base: read, read!, readuntil, readbytes!, write, close, eof
3129

3230
export compress, decompress, crc32
@@ -49,7 +47,7 @@ const Z_MEM_ERROR = -4
4947
const Z_BUF_ERROR = -5
5048
const Z_VERSION_ERROR = -6
5149

52-
if Compat.Sys.iswindows()
50+
if Sys.iswindows()
5351
const libz = "zlib1"
5452
else
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)
110108
end
111109

112110
function Writer(io::IO, level::Integer, raw::Bool=false)
@@ -131,7 +129,7 @@ Writer(io::IO, raw::Bool=false) = Writer(io, 9, raw)
131129
function 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)
243241
end
244242

245243
function Reader(io::IO, raw::Bool=false; bufsize::Int=4096)
@@ -258,11 +256,11 @@ end
258256
# unless we have already reached EOF.
259257
function 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)
297295
end
298296

299297
# This is to fix the ambiguity with Base.read!
@@ -321,7 +319,7 @@ end
321319

322320
# This function needs to be fast because other read calls use it.
323321
function 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)) =
335333
function 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))
349347
end
350348

351349
function 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)
370368
end
371369

372370
function crc32(data::Vector{UInt8}, crc::Integer=0)

src/iojunk.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ end
77
function read(f::ReadableFile, ::Type{UInt8})
88
# This function needs to be fast because readbytes, readstring, etc.
99
# uses it. Avoid function calls when possible.
10-
b = Vector{UInt8}(Compat.undef, 1)
10+
b = Vector{UInt8}(undef, 1)
1111
c = read(f, b)
1212
c[1]
1313
end

test/runtests.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Compat
2-
using Compat.Test
1+
using Test
32
using ZipFile
43

54
Debug = false
@@ -93,8 +92,8 @@ write(f, s1)
9392
write(f, s2)
9493
close(dir)
9594
dir = ZipFile.Reader(filename)
96-
@test String(read!(dir.files[1], Array{UInt8}(Compat.undef, length(s1)))) == s1
97-
@test String(read!(dir.files[1], Array{UInt8}(Compat.undef, length(s2)))) == s2
95+
@test String(read!(dir.files[1], Array{UInt8}(undef, length(s1)))) == s1
96+
@test String(read!(dir.files[1], Array{UInt8}(undef, length(s2)))) == s2
9897
@test eof(dir.files[1])
9998
close(dir)
10099

@@ -111,7 +110,7 @@ data = Any[
111110
filename = "$tmp/multi2.zip"
112111
dir = ZipFile.Writer(filename)
113112
f = ZipFile.addfile(dir, "data"; method=ZipFile.Deflate)
114-
@test_throws ErrorException read!(f, Array{UInt8}(Compat.undef, 1))
113+
@test_throws ErrorException read!(f, Array{UInt8}(undef, 1))
115114
for x in data
116115
write(f, x)
117116
end
@@ -121,7 +120,7 @@ dir = ZipFile.Reader(filename)
121120
@test_throws ErrorException write(dir.files[1], UInt8(20))
122121
for x in data
123122
if isa(x, String)
124-
@test x == String(read!(dir.files[1], Array{UInt8}(Compat.undef, length(x))))
123+
@test x == String(read!(dir.files[1], Array{UInt8}(undef, length(x))))
125124
elseif isa(x, Array)
126125
y = similar(x)
127126
y[:] .= 0

0 commit comments

Comments
 (0)