Skip to content

Commit 8d64385

Browse files
committed
fix ReadOnlyZipStore::list
1 parent 4e4f1e8 commit 8d64385

3 files changed

Lines changed: 25 additions & 9 deletions

File tree

src/main/java/dev/zarr/zarrjava/store/ReadOnlyZipStore.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ public Stream<String[]> list(String[] keys) {
146146
if (!entryName.startsWith(prefix) || entryName.equals(prefix)) {
147147
continue;
148148
}
149-
String[] entryKeys = resolveEntryKeys(entryName.substring(prefix.length() + 1));
149+
entryName = entryName.substring(prefix.length());
150+
if (entryName.startsWith("/")) {
151+
entryName = entryName.substring(1);
152+
}
153+
String[] entryKeys = resolveEntryKeys(entryName);
150154
builder.add(entryKeys);
151155
}
152156
} catch (IOException ignored) {

src/test/java/dev/zarr/zarrjava/Utils.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ public static void zipFile(Path sourceDir, Path targetDir) throws IOException {
2121
}
2222

2323
static void zipFile(File fileToZip, String fileName, ZipOutputStream zipOut) throws IOException {
24-
if (fileToZip.isHidden()) {
25-
return;
26-
}
2724
if (fileToZip.isDirectory()) {
2825
if (fileName.endsWith("/")) {
2926
zipOut.putNextEntry(new ZipEntry(fileName));

src/test/java/dev/zarr/zarrjava/store/ReadOnlyZipStoreTest.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,38 @@
1212
import java.util.Arrays;
1313
import java.util.stream.Collectors;
1414

15-
public class ReadOnlyZipStoreTest extends StoreTest {
15+
public class ReadOnlyZipStoreTest extends StoreTest {
1616

17+
Path storePath = TESTOUTPUT.resolve("readOnlyZipStoreTest.zip");
1718
StoreHandle storeHandleWithData;
1819

1920
@BeforeAll
2021
void writeStoreHandleWithData() throws ZarrException, IOException {
21-
Path source = TESTDATA.resolve("v2_sample").resolve("bool");
22-
Path target = TESTOUTPUT.resolve("readOnlyZipStoreTest.zip");
23-
Utils.zipFile(source, target);
24-
storeHandleWithData = new ReadOnlyZipStore(target).resolve("0.0.0");
22+
Path source = TESTDATA.resolve("v2_sample").resolve("subgroup");
23+
Utils.zipFile(source, storePath);
24+
storeHandleWithData = new ReadOnlyZipStore(storePath).resolve("array", "0.0.0");
2525
}
2626

2727
@Override
2828
StoreHandle storeHandleWithData() {
2929
return storeHandleWithData;
3030
}
3131

32+
@Override
33+
@Test
34+
void testList() {
35+
ReadOnlyZipStore zipStore = new ReadOnlyZipStore(storePath);
36+
BufferedZipStore bufferedZipStore = new BufferedZipStore(storePath);
37+
38+
java.util.Set<String> expectedKeys = bufferedZipStore.resolve().list()
39+
.map(node -> String.join("/", node))
40+
.collect(Collectors.toSet());
41+
java.util.Set<String> actualKeys = zipStore.resolve().list()
42+
.map(node -> String.join("/", node))
43+
.collect(Collectors.toSet());
44+
Assertions.assertEquals(expectedKeys, actualKeys);
45+
}
46+
3247
@Test
3348
public void testOpen() throws ZarrException, IOException {
3449
Path sourceDir = TESTOUTPUT.resolve("testZipStore");

0 commit comments

Comments
 (0)