fix s3 downloads resulting in flat folder structure

Signed-off-by: Matt Wise <wsmatth@amazon.com>
This commit is contained in:
Matt Wise
2024-02-11 23:19:14 -06:00
parent 57397e7d6d
commit 23f447c0ed
2 changed files with 6 additions and 8 deletions
@@ -46,6 +46,7 @@ import {
import { AbortController } from '@aws-sdk/abort-controller';
import { ReadUrlResponseFactory } from './ReadUrlResponseFactory';
import { Readable } from 'stream';
import { relative } from 'path/posix';
export const DEFAULT_REGION = 'us-east-1';
@@ -345,7 +346,7 @@ export class AwsS3UrlReader implements UrlReader {
responses.push({
data: s3ObjectData,
path: String(allObjects[i]),
path: relative(path, String(allObjects[i])),
lastModifiedAt: response?.LastModified ?? undefined,
});
}
@@ -15,7 +15,7 @@
*/
import concatStream from 'concat-stream';
import platformPath, { basename } from 'path';
import platformPath, { dirname } from 'path';
import getRawBody from 'raw-body';
import fs from 'fs-extra';
@@ -96,12 +96,9 @@ export class ReadableArrayResponse implements ReadTreeResponse {
for (let i = 0; i < this.stream.length; i++) {
if (!this.stream[i].path.endsWith('/')) {
await pipeline(
this.stream[i].data,
fs.createWriteStream(
platformPath.join(dir, basename(this.stream[i].path)),
),
);
const filePath = platformPath.join(dir, this.stream[i].path);
await fs.mkdir(dirname(filePath), { recursive: true });
await pipeline(this.stream[i].data, fs.createWriteStream(filePath));
}
}