diff --git a/package.json b/package.json index 95fb212..d22200d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nulo/isogit-lfs", - "version": "0.2.8", + "version": "0.2.9", "description": "LFS helpers for Isomorphic Git", "main": "dist/index.js", "repository": "git@github.com:riboseinc/isogit-lfs.git", diff --git a/src/download.ts b/src/download.ts index 4522a01..d6adbb5 100644 --- a/src/download.ts +++ b/src/download.ts @@ -28,19 +28,21 @@ function isValidLFSInfoResponseData( * Uses already cached object, if size matches. */ export default async function downloadBlobFromPointer( - { promises: fs }: PromiseFsClient, + fs: PromiseFsClient | null, { http: { request }, headers = {}, url, auth }: HTTPRequest, { info, objectPath }: Pointer ): Promise { - try { - const cached = await fs.readFile(objectPath); - if (cached.byteLength === info.size) { - return cached; - } - } catch (e) { - // Silence file not found errors (implies cache miss) - if ((e as any).code !== "ENOENT") { - throw e; + if (fs) { + try { + const cached = await fs?.promises.readFile(objectPath); + if (cached.byteLength === info.size) { + return cached; + } + } catch (e) { + // Silence file not found errors (implies cache miss) + if ((e as any).code !== "ENOENT") { + throw e; + } } } @@ -99,10 +101,12 @@ export default async function downloadBlobFromPointer( const blob = await bodyToBuffer(lfsObjectBody); - // Write LFS cache for this object, if cache path is accessible. - if (await isWriteable({ promises: fs }, objectPath)) { - await fs.mkdir(path.dirname(objectPath), { recursive: true }); - await fs.writeFile(objectPath, blob); + if (fs) { + // Write LFS cache for this object, if cache path is accessible. + if (await isWriteable(fs, objectPath)) { + await fs.promises.mkdir(path.dirname(objectPath), { recursive: true }); + await fs.promises.writeFile(objectPath, blob); + } } return blob;