(uri: string)
| 38 | |
| 39 | /** Parse `s3://bucket/key/path` → `{ bucket, key }`. Throws on malformed input. */ |
| 40 | export function parseS3Uri(uri: string): S3Location { |
| 41 | if (!uri.startsWith("s3://")) { |
| 42 | throw new Error(`[s3Transport] expected s3:// URI, got: ${JSON.stringify(uri)}`); |
| 43 | } |
| 44 | const rest = uri.slice("s3://".length); |
| 45 | const slash = rest.indexOf("/"); |
| 46 | if (slash === -1) { |
| 47 | throw new Error(`[s3Transport] missing key in s3 URI: ${JSON.stringify(uri)}`); |
| 48 | } |
| 49 | const bucket = rest.slice(0, slash); |
| 50 | const key = rest.slice(slash + 1); |
| 51 | if (!bucket || !key) { |
| 52 | throw new Error(`[s3Transport] empty bucket or key in s3 URI: ${JSON.stringify(uri)}`); |
| 53 | } |
| 54 | return { bucket, key }; |
| 55 | } |
| 56 | |
| 57 | /** Build `s3://bucket/key` from a location. */ |
| 58 | export function formatS3Uri(loc: S3Location): string { |
no outgoing calls
no test coverage detected