MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / S3FileReader

Class S3FileReader

packages/filesystem/s3/rw.ts:8–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6 * 通过 GET 请求下载 S3 对象
7 */
8export class S3FileReader implements FileReader {
9 client: S3Client;
10
11 bucket: string;
12
13 key: string;
14
15 constructor(client: S3Client, bucket: string, key: string) {
16 this.client = client;
17 this.bucket = bucket;
18 this.key = key;
19 }
20
21 /**
22 * 读取文件内容
23 * @param type 输出格式:"string" 为文本,"blob" 为二进制(默认)
24 * @returns 文件内容
25 * @throws {S3Error} 文件不存在或读取失败
26 */
27 async read(type: "string" | "blob" = "blob"): Promise<string | Blob> {
28 const response = await this.client.request("GET", this.bucket, this.key);
29 if (type === "string") {
30 return response.text();
31 }
32 return response.blob();
33 }
34}
35
36/**
37 * S3 文件写入器

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected