Skip to content

Commit 36062e3

Browse files
committed
Zarr: fix creating a /vsizip/ file
Fixes OSGeo#12790
1 parent 20b6162 commit 36062e3

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

autotest/gdrivers/zarr_driver.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4744,10 +4744,10 @@ def reopen_after_rename():
47444744
"format,create_z_metadata",
47454745
[("ZARR_V2", "YES"), ("ZARR_V2", "NO"), ("ZARR_V3", "NO")],
47464746
)
4747-
def test_zarr_multidim_rename_array_at_creation(tmp_vsimem, format, create_z_metadata):
4747+
def test_zarr_multidim_rename_array_at_creation(tmp_path, format, create_z_metadata):
47484748

47494749
drv = gdal.GetDriverByName("ZARR")
4750-
filename = str(tmp_vsimem / "test.zarr")
4750+
filename = str(tmp_path / "test.zarr")
47514751

47524752
def test():
47534753
ds = drv.CreateMultiDimensional(
@@ -5799,3 +5799,20 @@ def test_zarr_write_error_at_close_on_array(tmp_path, format):
57995799

58005800
with pytest.raises(Exception, match="cannot be opened for writing"):
58015801
ds.Close()
5802+
5803+
5804+
###############################################################################
5805+
#
5806+
5807+
5808+
@gdaltest.enable_exceptions()
5809+
@pytest.mark.parametrize("format", ["ZARR_V2", "ZARR_V3"])
5810+
def test_zarr_write_vsizip(tmp_vsimem, format):
5811+
out_filename = "/vsizip/" + str(tmp_vsimem) + "test.zarr.zip/test.zarr"
5812+
5813+
gdal.GetDriverByName("Zarr").CreateCopy(
5814+
out_filename, gdal.Open("data/byte.tif"), options=["FORMAT=" + format]
5815+
)
5816+
5817+
ds = gdal.Open(out_filename)
5818+
assert ds.GetMetadata() == {"AREA_OR_POINT": "Area"}

frmts/zarr/zarr_v2_group.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ std::shared_ptr<GDALMDArray> ZarrV2Group::CreateMDArray(
11391139
poArray->SetFilters(oFilters);
11401140
poArray->SetUpdatable(true);
11411141
poArray->SetDefinitionModified(true);
1142-
if (!poArray->Flush())
1142+
if (!cpl::starts_with(osZarrayFilename, "/vsi") && !poArray->Flush())
11431143
return nullptr;
11441144
RegisterArray(poArray);
11451145

frmts/zarr/zarr_v3_group.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ std::shared_ptr<GDALMDArray> ZarrV3Group::CreateMDArray(
729729
poArray->SetCodecs(std::move(poCodecs));
730730
poArray->SetUpdatable(true);
731731
poArray->SetDefinitionModified(true);
732-
if (!poArray->Flush())
732+
if (!cpl::starts_with(osFilename, "/vsi") && !poArray->Flush())
733733
return nullptr;
734734
RegisterArray(poArray);
735735

0 commit comments

Comments
 (0)