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",
"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",

View file

@ -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<Buffer> {
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;