Get object in bucket as text

Script s3 Verified

by admin ยท 8/16/2022

The script

Submitted by hugo989 Bun
Verified 6 hours ago
1
import * as Minio from "minio@7";
2

3
type S3 = {
4
  endPoint: string;
5
  port: number;
6
  useSSL: boolean;
7
  pathStyle: boolean;
8
  bucket: string;
9
  accessKey: string;
10
  secretKey: string;
11
  region: string;
12
};
13
export async function main(s3: S3, path: string) {
14
  const stream = await new Minio.Client(s3).getObject(s3.bucket, path);
15
  const chunks: Buffer[] = [];
16
  for await (const chunk of stream) {
17
    chunks.push(chunk as Buffer);
18
  }
19
  return Buffer.concat(chunks).toString("utf-8");
20
}
21

Other submissions
  • Submitted by admin Deno
    Created 1157 days ago
    1
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    2
    import { S3Client } from "https://deno.land/x/[email protected]/mod.ts";
    3
    
    
    4
    export async function main(
    5
      s3: wmill.Resource<"s3">,
    6
      path: string,
    7
    ) {
    8
      return (await new S3Client(s3).getObject(path)).text();
    9
    }
    10
    
    
  • Submitted by yassinsiouda74165 Deno
    Created 393 days ago
    1
    import { S3Client } from "https://deno.land/x/[email protected]/mod.ts";
    2
    
    
    3
    type S3 = {
    4
      endPoint: string;
    5
      port: number;
    6
      useSSL: boolean;
    7
      pathStyle: boolean;
    8
      bucket: string;
    9
      accessKey: string;
    10
      secretKey: string;
    11
      region: string;
    12
    };
    13
    export async function main(s3: S3, path: string) {
    14
      return (await new S3Client(s3).getObject(path)).text();
    15
    }
    16