diff --git a/src/InfoZIP.jl b/src/InfoZIP.jl index 283cbaa..c588e7b 100644 --- a/src/InfoZIP.jl +++ b/src/InfoZIP.jl @@ -5,10 +5,17 @@ module InfoZIP export open_zip, create_zip +using Compat.readstring +using Compat.read +using Compat.write +if VERSION < v"0.5.0-dev+2228" +Base.read(cmd::Cmd) = readbytes(cmd) +end + have_infozip = false try - if ismatch(r"^UnZip.*by Info-ZIP.", readall(`unzip`)) + if ismatch(r"^UnZip.*by Info-ZIP.", readstring(`unzip`)) have_infozip = true end catch diff --git a/src/info_zip.jl b/src/info_zip.jl index 0199553..18f7fda 100644 --- a/src/info_zip.jl +++ b/src/info_zip.jl @@ -86,9 +86,9 @@ function Base.get(z::Archive, filename::AbstractString, default=nothing) f = joinpath(z.tempdir, filename) if isfile(f) - b = open(readbytes, f) + b = read(f) else - b = readbytes(`unzip -qc $(z.filename) $filename`) + b = read(`unzip -qc $(z.filename) $filename`) end return isvalid(ASCIIString, b) ? ASCIIString(b) : isvalid(UTF8String, b) ? UTF8String(b) : b @@ -101,7 +101,7 @@ function Base.setindex!(z::Archive, data, filename::AbstractString) # Write file to tempdir... mkpath(joinpath(z.tempdir, dirname(filename))) - open(io->write(io, data), joinpath(z.tempdir, filename), "w") + write(joinpath(z.tempdir, filename), data) # Add filename to "keys"... if !(filename in z.keys) diff --git a/src/zip_file.jl b/src/zip_file.jl index a2adb0e..4833651 100644 --- a/src/zip_file.jl +++ b/src/zip_file.jl @@ -160,7 +160,7 @@ end # Read entire file... function readfile(io::ZipFile.ReadableFile) - b = readbytes(io) + b = read(io) return isvalid(ASCIIString, b) ? ASCIIString(b) : isvalid(UTF8String, b) ? UTF8String(b) : b end @@ -180,9 +180,7 @@ end # Write "data" to "filename" (creating path as needed). function mkpath_write(filename::AbstractString, data) mkpath(dirname(filename)) - Base.open(filename, "w") do io - write(io, data) - end + write(filename, data) end @@ -213,7 +211,7 @@ create_zip(io::IO, files::Array, data::Array) = create_zip(io, zip(files, data). # Write to ZIP format from filenames. function create_zip(io::IO, files::Array) - create_zip(io::IO, files, [Base.open(readbytes, f) for f in files]) + create_zip(io::IO, files, map(read, files)) end