0.2.9 - don't need fs

This commit is contained in:
Cat /dev/Nulo 2023-05-16 19:39:48 -03:00
parent d64787ddc3
commit d44e35d40e
2 changed files with 19 additions and 15 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "@nulo/isogit-lfs", "name": "@nulo/isogit-lfs",
"version": "0.2.8", "version": "0.2.9",
"description": "LFS helpers for Isomorphic Git", "description": "LFS helpers for Isomorphic Git",
"main": "dist/index.js", "main": "dist/index.js",
"repository": "git@github.com:riboseinc/isogit-lfs.git", "repository": "git@github.com:riboseinc/isogit-lfs.git",

View file

@ -28,19 +28,21 @@ function isValidLFSInfoResponseData(
* Uses already cached object, if size matches. * Uses already cached object, if size matches.
*/ */
export default async function downloadBlobFromPointer( export default async function downloadBlobFromPointer(
{ promises: fs }: PromiseFsClient, fs: PromiseFsClient | null,
{ http: { request }, headers = {}, url, auth }: HTTPRequest, { http: { request }, headers = {}, url, auth }: HTTPRequest,
{ info, objectPath }: Pointer { info, objectPath }: Pointer
): Promise<Buffer> { ): Promise<Buffer> {
try { if (fs) {
const cached = await fs.readFile(objectPath); try {
if (cached.byteLength === info.size) { const cached = await fs?.promises.readFile(objectPath);
return cached; if (cached.byteLength === info.size) {
} return cached;
} catch (e) { }
// Silence file not found errors (implies cache miss) } catch (e) {
if ((e as any).code !== "ENOENT") { // Silence file not found errors (implies cache miss)
throw e; if ((e as any).code !== "ENOENT") {
throw e;
}
} }
} }
@ -99,10 +101,12 @@ export default async function downloadBlobFromPointer(
const blob = await bodyToBuffer(lfsObjectBody); const blob = await bodyToBuffer(lfsObjectBody);
// Write LFS cache for this object, if cache path is accessible. if (fs) {
if (await isWriteable({ promises: fs }, objectPath)) { // Write LFS cache for this object, if cache path is accessible.
await fs.mkdir(path.dirname(objectPath), { recursive: true }); if (await isWriteable(fs, objectPath)) {
await fs.writeFile(objectPath, blob); await fs.promises.mkdir(path.dirname(objectPath), { recursive: true });
await fs.promises.writeFile(objectPath, blob);
}
} }
return blob; return blob;