(options: {
key: string
context: StorageContext
})
| 407 | * import worker so a multi-hundred-MB file is never held resident. |
| 408 | */ |
| 409 | export async function downloadFileStream(options: { |
| 410 | key: string |
| 411 | context: StorageContext |
| 412 | }): Promise<Readable> { |
| 413 | const { key, context } = options |
| 414 | const config = getStorageConfig(context) |
| 415 | |
| 416 | if (USE_BLOB_STORAGE) { |
| 417 | const { downloadFromBlobStream } = await import('@/lib/uploads/providers/blob/client') |
| 418 | return downloadFromBlobStream(key, createBlobConfig(config)) |
| 419 | } |
| 420 | |
| 421 | if (USE_S3_STORAGE) { |
| 422 | const { downloadFromS3Stream } = await import('@/lib/uploads/providers/s3/client') |
| 423 | return downloadFromS3Stream(key, createS3Config(config)) |
| 424 | } |
| 425 | |
| 426 | const { createReadStream } = await import('fs') |
| 427 | const { join } = await import('path') |
| 428 | const { UPLOAD_DIR_SERVER } = await import('./setup.server') |
| 429 | return createReadStream(join(UPLOAD_DIR_SERVER, sanitizeFileKey(key))) |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * Delete a file from the configured storage provider |
no test coverage detected