diff --git a/Project.toml b/Project.toml index 9cec039..ad060da 100644 --- a/Project.toml +++ b/Project.toml @@ -16,7 +16,7 @@ StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" StaticStrings = "4db0a0c5-418a-4e1d-8806-cb305fe13294" StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a" TranscodingStreams = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" -ZipFile = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea" +ZipArchives = "49080126-0e18-4c2a-b176-c102e4b3760c" [compat] AbstractTrees = "0.4" @@ -30,5 +30,5 @@ StaticArraysCore = "1" StaticStrings = "0.2" StructArrays = "0.6" TranscodingStreams = "0.9" -ZipFile = "0.10" +ZipArchives = "0.3" julia = "1.8" diff --git a/src/readers.jl b/src/readers.jl index d82e9cc..0308231 100644 --- a/src/readers.jl +++ b/src/readers.jl @@ -3,7 +3,7 @@ # Doesn't support deleting, or changing data already written. using ArgCheck -using ZipFile +using ZipArchives abstract type AbstractReader end @@ -47,19 +47,17 @@ end struct BufferedZipReader <: AbstractReader - zipfile::ZipFile.Reader + zipfile::ZipBufferReader{Vector{UInt8}} function BufferedZipReader(path) @argcheck isfile(path) - io = IOBuffer(read(path, String)) - zipfile = ZipFile.Reader(io) - new(zipfile) + new(ZipBufferReader(read(path))) end end function key_names(d::BufferedZipReader)::Vector{String} - return map(f->f.name, d.zipfile.files) + return zip_names(d.zipfile) end function read_key_idx(d::BufferedZipReader, idx::Int)::Vector{UInt8} - read(d.zipfile.files[idx]) + zip_readentry(d.zipfile, idx) end \ No newline at end of file diff --git a/src/saving.jl b/src/saving.jl index 1a264ff..7733307 100644 --- a/src/saving.jl +++ b/src/saving.jl @@ -28,13 +28,13 @@ function _save_attrs(writer::AbstractWriter, key_prefix::String, z::Union{ZArray if isempty(attrs(z)) return end - write_key(writer, key_prefix*".zattrs", sprint(io->JSON3.pretty(io,attrs(z); allow_inf=true))) + write_key(writer, key_prefix*".zattrs", codeunits(sprint(io->JSON3.pretty(io,attrs(z); allow_inf=true)))) return end function _save_zgroup(writer::AbstractWriter, key_prefix::String, z::ZGroup) group_key = key_prefix*".zgroup" - write_key(writer, group_key, "{\"zarr_format\":2}") + write_key(writer, group_key, codeunits("{\"zarr_format\":2}")) _save_attrs(writer, key_prefix, z) for (k,v) in pairs(children(z)) @argcheck !isempty(k) @@ -93,7 +93,7 @@ function _save_zarray(writer::AbstractWriter, key_prefix::String, z::ZArray) end # store array meta data write_key(writer, key_prefix*".zarray", - """ + codeunits(""" { "chunks": [$(join(z.chunks, ", "))], "compressor": $(JSON3.write(norm_compressor; allow_inf=true)), @@ -104,6 +104,6 @@ function _save_zarray(writer::AbstractWriter, key_prefix::String, z::ZArray) "shape": [$(join(shape, ", "))], "zarr_format": 2 } - """ + """) ) end diff --git a/src/writers.jl b/src/writers.jl index de3e48f..cd3571e 100644 --- a/src/writers.jl +++ b/src/writers.jl @@ -3,7 +3,7 @@ # Doesn't support deleting, or changing data already written. using ArgCheck -using ZipFile +using ZipArchives abstract type AbstractWriter end @@ -41,7 +41,7 @@ Write to an in memory zipfile, that gets saved to disk on close. This writer will overwrite any existing file at `path` """ struct BufferedZipWriter <: AbstractWriter - zipfile::ZipFile.Writer + zipfile::ZipWriter{IOBuffer} path::String iobuffer::IOBuffer function BufferedZipWriter(path) @@ -49,14 +49,13 @@ struct BufferedZipWriter <: AbstractWriter @argcheck !isdirpath(path) mkpath(dirname(path)) iobuffer = IOBuffer() - zipfile = ZipFile.Writer(iobuffer) + zipfile = ZipWriter(iobuffer) new(zipfile, abspath(path), iobuffer) end end function write_key(d::BufferedZipWriter, key::AbstractString, data)::Nothing - f = ZipFile.addfile(d.zipfile, key); - write(f, data) + zip_writefile(d.zipfile, key, data) nothing end @@ -64,6 +63,5 @@ function closewriter(d::BufferedZipWriter) close(d.zipfile) open(d.path, "w") do f write(f, take!(d.iobuffer)) - close(d.iobuffer) end end \ No newline at end of file