Skip to content

Commit

Permalink
Julia v0.5 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
samoconnor committed Apr 19, 2016
1 parent 347ebb0 commit 61fd314
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
9 changes: 8 additions & 1 deletion src/InfoZIP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/info_zip.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions src/zip_file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


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


Expand Down

0 comments on commit 61fd314

Please sign in to comment.