From bce263659793e4f126756ff4003ef7165d425377 Mon Sep 17 00:00:00 2001 From: Calvin Chai Date: Mon, 30 Sep 2024 16:19:28 -0400 Subject: [PATCH 1/8] Add indents for .zgroup file --- src/ZGroup.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ZGroup.jl b/src/ZGroup.jl index acecf2b..5473f5e 100644 --- a/src/ZGroup.jl +++ b/src/ZGroup.jl @@ -132,7 +132,7 @@ function zgroup(s::AbstractStore, path::String=""; attrs=Dict()) d = Dict("zarr_format"=>2) isemptysub(s, path) || error("Store is not empty") b = IOBuffer() - JSON.print(b,d) + JSON.print(b,d,4) s[path,".zgroup"]=take!(b) writeattrs(s,path,attrs) ZGroup(s, path, Dict{String,ZArray}(), Dict{String,ZGroup}(), attrs,true) From f4e167579e24b092a7f68227f122051fd34b07fa Mon Sep 17 00:00:00 2001 From: Calvin Chai Date: Mon, 30 Sep 2024 16:20:19 -0400 Subject: [PATCH 2/8] Add indents for .zattrs and .zarray --- src/Storage/Storage.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Storage/Storage.jl b/src/Storage/Storage.jl index e54fa94..a7bde78 100644 --- a/src/Storage/Storage.jl +++ b/src/Storage/Storage.jl @@ -97,7 +97,7 @@ function getattrs(s::AbstractStore, p) end function writeattrs(s::AbstractStore, p, att::Dict) b = IOBuffer() - JSON.print(b,att) + JSON.print(b,att,4) s[p,".zattrs"] = take!(b) att end @@ -112,7 +112,7 @@ isinitialized(s::AbstractStore, i) = s[i] !== nothing getmetadata(s::AbstractStore, p,fill_as_missing) = Metadata(String(maybecopy(s[p,".zarray"])),fill_as_missing) function writemetadata(s::AbstractStore, p, m::Metadata) met = IOBuffer() - JSON.print(met,m) + JSON.print(met,m,4) s[p,".zarray"] = take!(met) m end From 29e2781c6c5d74bf71019d19cb12e0f1bf853aa6 Mon Sep 17 00:00:00 2001 From: Kaidong Chai Date: Thu, 10 Oct 2024 10:51:12 -0400 Subject: [PATCH 3/8] Make indenting JSON an optional kargs --- src/Storage/Storage.jl | 20 ++++++++++++++++---- src/ZArray.jl | 6 ++++-- src/ZGroup.jl | 12 +++++++++--- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/Storage/Storage.jl b/src/Storage/Storage.jl index a7bde78..db9e2c1 100644 --- a/src/Storage/Storage.jl +++ b/src/Storage/Storage.jl @@ -95,9 +95,15 @@ function getattrs(s::AbstractStore, p) JSON.parse(replace(String(maybecopy(atts)),": NaN,"=>": \"NaN\",")) end end -function writeattrs(s::AbstractStore, p, att::Dict) +function writeattrs(s::AbstractStore, p, att::Dict; indent_json::Bool= false) b = IOBuffer() - JSON.print(b,att,4) + + if !indent_json + JSON.print(b,att) + else + JSON.print(b,att,4) + end + s[p,".zattrs"] = take!(b) att end @@ -110,9 +116,15 @@ isinitialized(s::AbstractStore, p, i) = isinitialized(s,_concatpath(p,i)) isinitialized(s::AbstractStore, i) = s[i] !== nothing getmetadata(s::AbstractStore, p,fill_as_missing) = Metadata(String(maybecopy(s[p,".zarray"])),fill_as_missing) -function writemetadata(s::AbstractStore, p, m::Metadata) +function writemetadata(s::AbstractStore, p, m::Metadata; indent_json::Bool= false) met = IOBuffer() - JSON.print(met,m,4) + + if !indent_json + JSON.print(met,m) + else + JSON.print(met,m,4) + end + s[p,".zarray"] = take!(met) m end diff --git a/src/ZArray.jl b/src/ZArray.jl index acbf23e..0cae43e 100644 --- a/src/ZArray.jl +++ b/src/ZArray.jl @@ -310,6 +310,7 @@ Creates a new empty zarr array with element type `T` and array dimensions `dims` * `compressor=BloscCompressor()` compressor type and properties * `attrs=Dict()` a dict containing key-value pairs with metadata attributes associated to the array * `writeable=true` determines if the array is opened in read-only or write mode +* `indent_json` determines if indents are added to format the json files """ function zcreate(::Type{T}, dims::Integer...; name="", @@ -334,6 +335,7 @@ function zcreate(::Type{T},storage::AbstractStore, filters = filterfromtype(T), attrs=Dict(), writeable=true, + indent_json=false ) where T length(dims) == length(chunks) || throw(DimensionMismatch("Dims must have the same length as chunks")) @@ -353,9 +355,9 @@ function zcreate(::Type{T},storage::AbstractStore, isemptysub(storage,path) || error("$storage $path is not empty") - writemetadata(storage, path, metadata) + writemetadata(storage, path, metadata, indent_json=indent_json) - writeattrs(storage, path, attrs) + writeattrs(storage, path, attrs, indent_json=indent_json) ZArray{T2, N, typeof(compressor), typeof(storage)}( metadata, storage, path, attrs, writeable) diff --git a/src/ZGroup.jl b/src/ZGroup.jl index 5473f5e..dfd1c27 100644 --- a/src/ZGroup.jl +++ b/src/ZGroup.jl @@ -128,13 +128,19 @@ end Create a new zgroup in the store `s` """ -function zgroup(s::AbstractStore, path::String=""; attrs=Dict()) +function zgroup(s::AbstractStore, path::String=""; attrs=Dict(); indent_json::Bool= false) d = Dict("zarr_format"=>2) isemptysub(s, path) || error("Store is not empty") b = IOBuffer() - JSON.print(b,d,4) + + if !indent_json + JSON.print(b,d) + else + JSON.print(b,d,4) + end + s[path,".zgroup"]=take!(b) - writeattrs(s,path,attrs) + writeattrs(s,path,attrs, indent_json=indent_json) ZGroup(s, path, Dict{String,ZArray}(), Dict{String,ZGroup}(), attrs,true) end From 0fbed319ad4df913edf7ca8b4d4f3203e2a66943 Mon Sep 17 00:00:00 2001 From: Calvin Chai Date: Thu, 10 Oct 2024 11:21:48 -0400 Subject: [PATCH 4/8] Update src/ZGroup.jl Co-authored-by: Anshul Singhvi --- src/ZGroup.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ZGroup.jl b/src/ZGroup.jl index dfd1c27..4c6a765 100644 --- a/src/ZGroup.jl +++ b/src/ZGroup.jl @@ -133,10 +133,10 @@ function zgroup(s::AbstractStore, path::String=""; attrs=Dict(); indent_json::Bo isemptysub(s, path) || error("Store is not empty") b = IOBuffer() - if !indent_json - JSON.print(b,d) - else + if indent_json JSON.print(b,d,4) + else + JSON.print(b,d) end s[path,".zgroup"]=take!(b) From d4c14cf0f60b39b20dcd7f4d7af04fdd5f7294bb Mon Sep 17 00:00:00 2001 From: Calvin Chai Date: Thu, 10 Oct 2024 11:21:53 -0400 Subject: [PATCH 5/8] Update src/Storage/Storage.jl Co-authored-by: Anshul Singhvi --- src/Storage/Storage.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Storage/Storage.jl b/src/Storage/Storage.jl index db9e2c1..6eda351 100644 --- a/src/Storage/Storage.jl +++ b/src/Storage/Storage.jl @@ -98,10 +98,10 @@ end function writeattrs(s::AbstractStore, p, att::Dict; indent_json::Bool= false) b = IOBuffer() - if !indent_json - JSON.print(b,att) - else + if indent_json JSON.print(b,att,4) + else + JSON.print(b,att) end s[p,".zattrs"] = take!(b) From 09b92ea6a4f772ca83f36a1fb2f27ba00484fc73 Mon Sep 17 00:00:00 2001 From: Calvin Chai Date: Thu, 10 Oct 2024 11:21:59 -0400 Subject: [PATCH 6/8] Update src/Storage/Storage.jl Co-authored-by: Anshul Singhvi --- src/Storage/Storage.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Storage/Storage.jl b/src/Storage/Storage.jl index 6eda351..46c819a 100644 --- a/src/Storage/Storage.jl +++ b/src/Storage/Storage.jl @@ -119,10 +119,10 @@ getmetadata(s::AbstractStore, p,fill_as_missing) = Metadata(String(maybecopy(s[p function writemetadata(s::AbstractStore, p, m::Metadata; indent_json::Bool= false) met = IOBuffer() - if !indent_json - JSON.print(met,m) - else + if indent_json JSON.print(met,m,4) + else + JSON.print(met,m) end s[p,".zarray"] = take!(met) From 6a249c824e0ce2c37b07166ce9a4bd07eaea779f Mon Sep 17 00:00:00 2001 From: Calvin Chai Date: Thu, 10 Oct 2024 11:22:04 -0400 Subject: [PATCH 7/8] Update src/ZArray.jl Co-authored-by: Anshul Singhvi --- src/ZArray.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ZArray.jl b/src/ZArray.jl index 0cae43e..b095568 100644 --- a/src/ZArray.jl +++ b/src/ZArray.jl @@ -310,7 +310,7 @@ Creates a new empty zarr array with element type `T` and array dimensions `dims` * `compressor=BloscCompressor()` compressor type and properties * `attrs=Dict()` a dict containing key-value pairs with metadata attributes associated to the array * `writeable=true` determines if the array is opened in read-only or write mode -* `indent_json` determines if indents are added to format the json files +* `indent_json=false` determines if indents are added to format the json files `.zarray` and `.zattrs`. This makes them more readable, but increases file size. """ function zcreate(::Type{T}, dims::Integer...; name="", From 2fcc5d645c84bfd47631bd61b0d620e05fdef10d Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 10 Oct 2024 09:03:53 -0700 Subject: [PATCH 8/8] Fix syntax error --- src/ZGroup.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ZGroup.jl b/src/ZGroup.jl index 4c6a765..35515ed 100644 --- a/src/ZGroup.jl +++ b/src/ZGroup.jl @@ -128,7 +128,7 @@ end Create a new zgroup in the store `s` """ -function zgroup(s::AbstractStore, path::String=""; attrs=Dict(); indent_json::Bool= false) +function zgroup(s::AbstractStore, path::String=""; attrs=Dict(), indent_json::Bool= false) d = Dict("zarr_format"=>2) isemptysub(s, path) || error("Store is not empty") b = IOBuffer()