Skip to content

Commit 4e4f1e8

Browse files
committed
fix s3Store::list
1 parent 8c4e988 commit 4e4f1e8

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.io.IOException;
1313
import java.io.InputStream;
1414
import java.nio.ByteBuffer;
15+
import java.util.ArrayList;
16+
import java.util.List;
1517
import java.util.stream.Stream;
1618

1719
public class S3Store implements Store, Store.ListableStore {
@@ -110,9 +112,20 @@ public Stream<String[]> list(String[] keys) {
110112
.bucket(bucketName).prefix(fullKey)
111113
.build();
112114
ListObjectsResponse res = s3client.listObjects(req);
113-
return res.contents()
114-
.stream()
115-
.map(p -> p.key().substring(fullKey.length() + 1).split("/"));
115+
return res.contents().stream()
116+
.map(S3Object::key)
117+
.flatMap(key -> {
118+
List<String> pathSegments = new ArrayList<>();
119+
int index = fullKey.length();
120+
while ((index = key.indexOf('/', index + 1)) != -1) {
121+
pathSegments.add(key.substring(fullKey.length() + 1, index));
122+
}
123+
pathSegments.add(key.substring(fullKey.length() + 1));
124+
return pathSegments.stream();
125+
})
126+
.distinct()
127+
.map(s -> s.split("/"))
128+
.filter(arr -> arr.length > 0);
116129
}
117130

118131
@Nonnull

0 commit comments

Comments
 (0)