Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,17 @@ function load_dir(reader::AbstractReader)::ZGroup
#shape and chunks have been pre reversed so reverse chunkidx as well.
reverse(chunktuple)
end
chunkname = arrayname*"/"*join(chunknametuple, metadata.dimension_separator)
# empty chunk has name "0" this is the case for zero dim arrays
chunkname = arrayname*"/"*(isempty(chunknametuple) ? "0" : join(chunknametuple, metadata.dimension_separator))
chunknameidx = get(Returns(0), keyname_dict, chunkname)
if chunknameidx > 0
rawchunkdata = read_key_idx(reader, chunknameidx)
decompressed_chunkdata = decompress!(Vector{UInt8}(), rawchunkdata, metadata)
chunkstart = chunktuple .* chunks .+ 1
chunkstop = min.(chunkstart .+ chunks .- 1, shape)
real_chunksize = chunkstop .- chunkstart .+ 1
if zarr_size == 1
if julia_size == 1
@assert zarr_size == 1
shaped_chunkdata = reshape(decompressed_chunkdata, chunks...)
shaped_array = reinterpret(UInt8, array)
array_view = view(shaped_array, (range.(chunkstart, chunkstop))...)
Expand Down
3 changes: 2 additions & 1 deletion src/saving.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ function _save_zarray(writer::AbstractWriter, key_prefix::String, z::ZArray)
selectdim(chunk_view, 1, zarr_byte) .= selectdim(array_view, 1, julia_byte)
end
compressed_chunkdata = compress(norm_compressor, reshape(shaped_chunkdata,:), zarr_size)
chunkname = key_prefix*join(chunktuple, '.')
# empty chunk has name "0" this is the case for zero dim arrays
chunkname = key_prefix*(isempty(chunktuple) ? "0" : join(chunktuple, '.'))
write_key(writer, chunkname, compressed_chunkdata)
end
end
Expand Down
1 change: 1 addition & 0 deletions src/writers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ end
Add a key and value to the store.
"""
function write_key(d::DirectoryWriter, key::AbstractString, data)::Nothing
@assert !endswith(key, "/")
filename = joinpath([d.path; split(key,"/")])
mkpath(dirname(filename))
open(filename, "w") do f
Expand Down
18 changes: 18 additions & 0 deletions test/test_edge-cases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,22 @@ end
"foo" => "bar",
])
end
end


@testset "saving and loading zero dimensional array" begin
g = ZGroup()
a::Array{Float64, 0} = fill(3.25)
b::Array{Int8, 0} = fill(Int8(2))
c::Array{UInt8, 0} = fill(UInt8(0xFF))
g["a"] = a
g["b"] = b
g["c"] = c
mktempdir() do path
SmallZarrGroups.save_dir(path, g)
gload = SmallZarrGroups.load_dir(path)
@test gload["a"][] == 3.25
@test gload["b"][] == 2
@test gload["c"][] == 0xFF
end
end