(bucket: Bucket, filePath: string)
| 129 | }; |
| 130 | |
| 131 | export const getFileFromBucket = async (bucket: Bucket, filePath: string) => { |
| 132 | const { name: bucketName } = bucket; |
| 133 | const gcsBucket = initializeGcsBucket(bucketName); |
| 134 | const file = gcsBucket.file(filePath); |
| 135 | |
| 136 | logger.debug(`Fetching file '${filePath}' from GCS bucket '${bucketName}'`); |
| 137 | const goDownload = await go(() => file.download()); |
| 138 | if (!goDownload.success) { |
| 139 | throw new Error(`Failed to fetch file '${filePath}' from GCS bucket '${bucketName}': ${goDownload.error}`); |
| 140 | } |
| 141 | |
| 142 | return goDownload.data[0].toString('utf-8'); |
| 143 | }; |
| 144 | |
| 145 | export const copyFileInBucket = async (bucket: Bucket, fromFilePath: string, toFilePath: string) => { |
| 146 | const { name: bucketName } = bucket; |
no test coverage detected