bug fix
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { FileIDComputer } from "./fileID/FileIDComputer";
|
||||
import {FileIDComputer} from "./fileID/FileIDComputer";
|
||||
import {CID_ALGORITHM_NAMES, ComputeInterface, MultiHashData} from "./MultiHashData";
|
||||
|
||||
export class HashComputer implements ComputeInterface{
|
||||
private fileIDComputer:FileIDComputer;
|
||||
export class HashComputer implements ComputeInterface {
|
||||
private fileIDComputer: FileIDComputer;
|
||||
|
||||
constructor(private targetHash: CID_ALGORITHM_NAMES[],workerPath?:string) {
|
||||
constructor(private targetHash: CID_ALGORITHM_NAMES[], workerPath?: string) {
|
||||
this.fileIDComputer = new FileIDComputer(workerPath);
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ export class HashComputer implements ComputeInterface{
|
||||
const cids = await this.fileIDComputer.computeCIDs(filePath, neededHashes);
|
||||
|
||||
// Map the computed CIDs back to their respective metadata properties
|
||||
cids.forEach((cid, index) => {
|
||||
for (const [index, cid] of cids.entries()) {
|
||||
const hashType = neededHashes[index];
|
||||
metadata[hashType] = cid;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,7 +273,12 @@ export class HashIndexManager {
|
||||
const baseName = path.basename(filePath);
|
||||
let indexLine = this.cache.get(baseName);
|
||||
if (!indexLine) {
|
||||
const data = {path: baseName, size: size, mtime: mtime, ...hashs};
|
||||
//filter only the hashes we need
|
||||
let filteredHash = {};
|
||||
for (const hash of this.targetHash) {
|
||||
filteredHash[hash] = hashs[hash];
|
||||
}
|
||||
const data = {path: baseName, size: size, mtime: mtime, ...filteredHash};
|
||||
this.cache.set(baseName, data);
|
||||
} else {
|
||||
//update the cache with the latest data
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
export interface MultiHashData {
|
||||
"cid_sha2-256"?: string;//0x12 sha2-256
|
||||
cid_sha1?: string; // 0x11 sha1
|
||||
cid_md5?: string; // 0xd5 md5
|
||||
"cid_sha3-256"?: string; // 0x16 sha3-256
|
||||
cid_crc32?: string; //0x0132 CRC32 (SFV)
|
||||
cid_md5?: string; // 0xd5 md5
|
||||
cid_sha1?: string; // 0x11 sha1
|
||||
"cid_sha2-256"?: string;//0x12 sha2-256
|
||||
"cid_sha3-256"?: string; // 0x16 sha3-256
|
||||
"cid_sha3_384"?: string; // 0x16 sha3-256
|
||||
}
|
||||
|
||||
export interface ComputeInterface {
|
||||
|
||||
@@ -21,7 +21,6 @@ class Crc32Hash implements SimpleHash {
|
||||
}
|
||||
|
||||
digest(): Buffer {
|
||||
console.log((this._crc>>>0).toString(16)) ;
|
||||
const buffer = Buffer.alloc(4); // Create a buffer of 4 bytes (32 bits)
|
||||
buffer.writeInt32BE(this._crc, 0); // Write the unsigned integer to the buffer in big-endian format
|
||||
return buffer;
|
||||
|
||||
Reference in New Issue
Block a user