1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

common/utils/tar.ts: reject with Error-type

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2020-11-25 01:02:16 +02:00
parent 55c284f8ef
commit 639bc1a510

View File

@ -9,7 +9,7 @@ export interface ReadFileFromTarOpts {
parseJson?: boolean;
}
export function readFileFromTar<R = Buffer>({tarPath, filePath, parseJson}: ReadFileFromTarOpts): Promise<R> {
export function readFileFromTar<R = Buffer>({ tarPath, filePath, parseJson }: ReadFileFromTarOpts): Promise<R> {
return new Promise(async (resolve, reject) => {
const fileChunks: Buffer[] = [];
@ -21,7 +21,7 @@ export function readFileFromTar<R = Buffer>({tarPath, filePath, parseJson}: Read
fileChunks.push(chunk);
});
entry.once("error", err => {
reject(`Reading ${entry.path} error: ${err}`);
reject(new Error(`reading file has failed ${entry.path}: ${err}`));
});
entry.once("end", () => {
const data = Buffer.concat(fileChunks);
@ -32,7 +32,7 @@ export function readFileFromTar<R = Buffer>({tarPath, filePath, parseJson}: Read
});
if (!fileChunks.length) {
reject(null);
reject(new Error("Not found"));
}
});
}