Skip to content

Commit 16289a1

Browse files
committed
refactor(path-like): improve error handling and add jsdoc comments
1 parent 688c5a4 commit 16289a1

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/utils/path-like.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import { readFile } from "fs/promises";
22
import { SquareCloudBlobError } from "../structures/error";
33

4+
/**
5+
* Parses a path-like input into a Buffer
6+
* @param pathLike - File path string or Buffer
7+
* @returns Promise resolving to Buffer
8+
*/
49
export async function parsePathLike(
510
pathLike: string | Buffer,
611
): Promise<Buffer> {
712
if (typeof pathLike === "string") {
8-
const fileBuffer = await readFile(pathLike).catch(() => undefined);
9-
10-
if (!fileBuffer) {
11-
throw new SquareCloudBlobError("INVALID_FILE", "File not found");
13+
try {
14+
const fileBuffer = await readFile(pathLike);
15+
return fileBuffer;
16+
} catch {
17+
throw new SquareCloudBlobError("INVALID_FILE_PATH", "File not found");
1218
}
13-
14-
return fileBuffer;
1519
}
1620

1721
return pathLike;

0 commit comments

Comments
 (0)