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,12 +28,13 @@ 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> {
if (fs) {
try { try {
const cached = await fs.readFile(objectPath); const cached = await fs?.promises.readFile(objectPath);
if (cached.byteLength === info.size) { if (cached.byteLength === info.size) {
return cached; return cached;
} }
@ -43,6 +44,7 @@ export default async function downloadBlobFromPointer(
throw e; throw e;
} }
} }
}
const authHeaders: Record<string, string> = auth ? getAuthHeader(auth) : {}; const authHeaders: Record<string, string> = auth ? getAuthHeader(auth) : {};
@ -99,10 +101,12 @@ export default async function downloadBlobFromPointer(
const blob = await bodyToBuffer(lfsObjectBody); const blob = await bodyToBuffer(lfsObjectBody);
if (fs) {
// Write LFS cache for this object, if cache path is accessible. // Write LFS cache for this object, if cache path is accessible.
if (await isWriteable({ promises: fs }, objectPath)) { if (await isWriteable(fs, objectPath)) {
await fs.mkdir(path.dirname(objectPath), { recursive: true }); await fs.promises.mkdir(path.dirname(objectPath), { recursive: true });
await fs.writeFile(objectPath, blob); await fs.promises.writeFile(objectPath, blob);
}
} }
return blob; return blob;