@dpkit/file
Version:
Fast TypeScript data management framework built on top of the Data Package standard and Polars DataFrames
18 lines (15 loc) • 564 B
text/typescript
import { isRemotePath } from "@dpkit/core"
import { saveFileToDisc } from "./save.js"
import { getTempFilePath } from "./temp.js"
export async function prefetchFiles(path?: string | string[]) {
if (!path) return []
const paths = Array.isArray(path) ? path : [path]
const newPaths = await Promise.all(paths.map(prefetchFile))
return newPaths
}
export async function prefetchFile(path: string) {
if (!isRemotePath(path)) return path
const newPath = getTempFilePath()
await saveFileToDisc({ sourcePath: path, targetPath: newPath })
return newPath
}