Skip to content

Commit

Permalink
Handle multiple CommonPrefix nodes in listObjectsGrouped
Browse files Browse the repository at this point in the history
  • Loading branch information
chromakode committed Jun 25, 2023
1 parent c349309 commit ce4883f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,16 +567,16 @@ export class Client {
throw new Error(`Unexpected response: ${responseText}`);
}
// If a delimiter was specified, first return any common prefixes from this page of results:
const commonPrefixesElement = root.children.find((c) => c.name === "CommonPrefixes");
const prefixElements = root.children
.filter((c) => c.name === "CommonPrefixes")
.flatMap((c) => c.children);
const toYield: Array<S3Object | CommonPrefix> = [];
if (commonPrefixesElement) {
for (const prefixElement of commonPrefixesElement.children) {
toYield.push({
type: "CommonPrefix",
prefix: prefixElement.content ?? "",
});
resultCount++;
}
for (const prefixElement of prefixElements) {
toYield.push({
type: "CommonPrefix",
prefix: prefixElement.content ?? "",
});
resultCount++;
}
// Now return all regular object keys found in the result:
for (const objectElement of root.children.filter((c) => c.name === "Contents")) {
Expand Down

0 comments on commit ce4883f

Please sign in to comment.