Skip to content

Commit f12e906

Browse files
committed
improve start time
1 parent 070bb68 commit f12e906

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

src/common/download/utils.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import crypto from "node:crypto";
2-
import { homedir } from "node:os";
2+
import * as os from "node:os";
33
import path from "node:path";
44
import fsPromise from "node:fs/promises";
55
import fs from "node:fs";
6-
import Logger from "../logger";
6+
import child_process from "node:child_process";
7+
import { promisify } from "node:util";
8+
const exec = promisify(child_process.exec);
79

810
export const checkFileOrFolderExists = async (pathToCheck: string) => {
911
try {
@@ -15,7 +17,7 @@ export const checkFileOrFolderExists = async (pathToCheck: string) => {
1517
};
1618

1719
export const getSaveFolder = async () => {
18-
const pathSaveFolder = path.join(homedir(), ".firecoder");
20+
const pathSaveFolder = path.join(os.homedir(), ".firecoder");
1921

2022
const folderIsExist = await checkFileOrFolderExists(pathSaveFolder);
2123

@@ -27,7 +29,33 @@ export const getSaveFolder = async () => {
2729
};
2830

2931
export const getChecksum = async (path: string) => {
30-
// TODO: Use sha256sum
32+
const osplatform = os.platform();
33+
const isLinux = osplatform === "linux";
34+
const isWindows = osplatform === "win32";
35+
try {
36+
if (isLinux) {
37+
const hashOutput = await exec(`sha256sum ${path} | awk '{ print $1 }'`);
38+
39+
return hashOutput.stdout.trim();
40+
}
41+
42+
if (isWindows) {
43+
const hashOutput = await exec(
44+
`$(CertUtil -hashfile ${path} SHA256)[1] -replace " ",""`,
45+
{ shell: "powershell.exe" }
46+
);
47+
48+
return hashOutput.stdout.replace("\r\n", "").trim();
49+
}
50+
51+
// fallback to default method
52+
return await getCheckSumNode(path);
53+
} catch (error) {
54+
return await getCheckSumNode(path);
55+
}
56+
};
57+
58+
const getCheckSumNode = async (path: string) => {
3159
return await new Promise((res, rej) => {
3260
try {
3361
const fsStream = fs.createReadStream(path);

0 commit comments

Comments
 (0)