更新依赖项版本,添加文件哈希功能,优化远程应用连接逻辑
This commit is contained in:
16
assistant/src/module/file-hash.ts
Normal file
16
assistant/src/module/file-hash.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import crypto from 'node:crypto';
|
||||
import fs from 'node:fs';
|
||||
|
||||
export const getHash = (file: string) => {
|
||||
if (!fs.existsSync(file)) return '';
|
||||
const buffer = fs.readFileSync(file); // 不指定编码,返回 Buffer
|
||||
return crypto.createHash('md5').update(buffer).digest('hex');
|
||||
};
|
||||
|
||||
export const getBufferHash = (buffer: Buffer) => {
|
||||
return crypto.createHash('md5').update(buffer).digest('hex');
|
||||
};
|
||||
|
||||
export const getStringHash = (str: string) => {
|
||||
return crypto.createHash('md5').update(str).digest('hex');
|
||||
}
|
||||
Reference in New Issue
Block a user