triangle-utils 1.4.36 → 1.4.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,9 @@ export declare class UtilsS3 {
3
3
  private readonly s3;
4
4
  constructor(region: string);
5
5
  file_exists(s3_filename: string): Promise<boolean | undefined>;
6
+ get_s3_filenames(s3_filename_prefix: string, options: {
7
+ compile?: boolean;
8
+ }): Promise<string[] | undefined>;
6
9
  get_file(s3_filename: string, encoding?: string): Promise<string | undefined>;
7
10
  get_file_buffer(s3_filename: string): Promise<Buffer | undefined>;
8
11
  get_file_stream(s3_filename: string): Promise<Readable | undefined>;
@@ -28,6 +28,32 @@ export class UtilsS3 {
28
28
  return false;
29
29
  }
30
30
  }
31
+ async get_s3_filenames(s3_filename_prefix, options) {
32
+ const compile = options.compile !== undefined ? options.compile : false;
33
+ const s3_key = parse_s3_filename(s3_filename_prefix);
34
+ if (s3_key === undefined) {
35
+ return undefined;
36
+ }
37
+ const s3_filenames = [];
38
+ let last_token = undefined;
39
+ while (true) {
40
+ const response = await this.s3.listObjectsV2({
41
+ Bucket: s3_key.Bucket,
42
+ Delimiter: "/",
43
+ Prefix: s3_key.Key,
44
+ ContinuationToken: last_token
45
+ });
46
+ if (response.Contents === undefined) {
47
+ return [];
48
+ }
49
+ const new_s3_filenames = response.Contents.map(content => content.Key).filter(key => key !== undefined).map(key => "s3://" + s3_key.Bucket + "/" + key);
50
+ s3_filenames.push(...new_s3_filenames);
51
+ if (response.ContinuationToken === undefined || !compile) {
52
+ return s3_filenames;
53
+ }
54
+ last_token = response.ContinuationToken;
55
+ }
56
+ }
31
57
  async get_file(s3_filename, encoding = "utf-8") {
32
58
  const s3_key = parse_s3_filename(s3_filename);
33
59
  if (s3_key === undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.36",
3
+ "version": "1.4.37",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
package/src/UtilsS3.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { S3, NoSuchKey, GetObjectCommand, PutObjectCommand } from "@aws-sdk/client-s3"
1
+ import { S3, NoSuchKey, GetObjectCommand, PutObjectCommand, ListObjectsV2CommandOutput } from "@aws-sdk/client-s3"
2
2
  import { getSignedUrl } from "@aws-sdk/s3-request-presigner"
3
3
  import { Readable } from "stream"
4
4
 
@@ -38,6 +38,33 @@ export class UtilsS3 {
38
38
  }
39
39
  }
40
40
 
41
+ async get_s3_filenames(s3_filename_prefix : string, options : { compile? : boolean }) {
42
+ const compile = options.compile !== undefined ? options.compile : false
43
+ const s3_key = parse_s3_filename(s3_filename_prefix)
44
+ if (s3_key === undefined) {
45
+ return undefined
46
+ }
47
+ const s3_filenames = []
48
+ let last_token : string | undefined = undefined
49
+ while (true) {
50
+ const response : ListObjectsV2CommandOutput = await this.s3.listObjectsV2({
51
+ Bucket : s3_key.Bucket,
52
+ Delimiter : "/",
53
+ Prefix : s3_key.Key,
54
+ ContinuationToken : last_token
55
+ })
56
+ if (response.Contents === undefined) {
57
+ return []
58
+ }
59
+ const new_s3_filenames = response.Contents.map(content => content.Key).filter(key => key !== undefined).map(key => "s3://" + s3_key.Bucket + "/" + key)
60
+ s3_filenames.push(...new_s3_filenames)
61
+ if (response.ContinuationToken === undefined || !compile) {
62
+ return s3_filenames
63
+ }
64
+ last_token = response.ContinuationToken
65
+ }
66
+ }
67
+
41
68
  async get_file(s3_filename : string, encoding : string = "utf-8") : Promise<string | undefined> {
42
69
  const s3_key = parse_s3_filename(s3_filename)
43
70
  if (s3_key === undefined) {