fix tests
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {HashComputer} from "./HashComputer.js";
|
||||
import {CID_ALGORITHM_NAMES, ComputeInterface, MultiHashData} from "./MultiHashData.js";
|
||||
import {HashIndexManager} from "./HashIndexManager.js";
|
||||
import {HashComputer} from "./HashComputer";
|
||||
import {CID_ALGORITHM_NAMES, ComputeInterface, MultiHashData} from "./MultiHashData";
|
||||
import {HashIndexManager} from "./HashIndexManager";
|
||||
import {stat} from "fs/promises";
|
||||
import path from "path";
|
||||
|
||||
@@ -8,8 +8,8 @@ export class ComputeHashIndexCache implements ComputeInterface {
|
||||
hashIndexManager: HashIndexManager;
|
||||
hashComputer: HashComputer;
|
||||
|
||||
constructor(indexFilePath: string, private targetHash: CID_ALGORITHM_NAMES[] = [CID_ALGORITHM_NAMES.sha1, CID_ALGORITHM_NAMES.sha256]) {
|
||||
this.hashComputer = new HashComputer(this.targetHash);
|
||||
constructor(indexFilePath: string,private targetHash: CID_ALGORITHM_NAMES[] = [CID_ALGORITHM_NAMES.sha1, CID_ALGORITHM_NAMES.sha256],workerPath?:string) {
|
||||
this.hashComputer = new HashComputer(this.targetHash,workerPath);
|
||||
this.hashIndexManager = new HashIndexManager(indexFilePath);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { FileIDComputer } from "./fileID/FileIDComputer.js";
|
||||
import {CID_ALGORITHM_NAMES, ComputeInterface, MultiHashData} from "./MultiHashData.js";
|
||||
import { FileIDComputer } from "./fileID/FileIDComputer";
|
||||
import {CID_ALGORITHM_NAMES, ComputeInterface, MultiHashData} from "./MultiHashData";
|
||||
|
||||
export class HashComputer implements ComputeInterface{
|
||||
private fileIDComputer = new FileIDComputer();
|
||||
private fileIDComputer:FileIDComputer;
|
||||
|
||||
constructor(private targetHash: CID_ALGORITHM_NAMES[]) {
|
||||
constructor(private targetHash: CID_ALGORITHM_NAMES[],workerPath?:string) {
|
||||
this.fileIDComputer = new FileIDComputer(workerPath);
|
||||
}
|
||||
|
||||
async computeMissingHash(filePath: string, metadata: MultiHashData): Promise<void> {
|
||||
|
||||
@@ -2,10 +2,10 @@ import {createReadStream, promises as fs} from 'fs';
|
||||
import {parse} from 'csv-parse';
|
||||
import {parse as parseSync} from 'csv-parse/sync';
|
||||
import {stringify} from 'csv-stringify/sync';
|
||||
import {existsAsync} from "./ExistsAsync.js";
|
||||
import {existsAsync} from "./ExistsAsync";
|
||||
import path from "path";
|
||||
import {clearInterval} from "node:timers";
|
||||
import {CID_ALGORITHM_NAMES} from "./MultiHashData.js";
|
||||
import {CID_ALGORITHM_NAMES} from "./MultiHashData";
|
||||
|
||||
interface IndexLine extends Partial<Record<CID_ALGORITHM_NAMES, string>> {
|
||||
path: string;
|
||||
|
||||
@@ -1,13 +1,21 @@
|
||||
import {Piscina} from "piscina";
|
||||
import {CID_ALGORITHM_NAMES} from "../MultiHashData.js";
|
||||
import {CID_ALGORITHM_NAMES} from "../MultiHashData";
|
||||
|
||||
// Construct the URL for the current module
|
||||
let distFolder = import.meta.dirname;
|
||||
distFolder = distFolder.replace('src', 'dist');
|
||||
distFolder = distFolder + "/worker.js";
|
||||
const workerUrl = new URL(distFolder).href;
|
||||
console.log("Worker URL: ", workerUrl);
|
||||
|
||||
export class FileIDComputer {
|
||||
private piscina: Piscina;
|
||||
|
||||
constructor() {
|
||||
constructor(workerPath?:string) {
|
||||
this.piscina = new Piscina({
|
||||
maxThreads: 4,
|
||||
filename: new URL('./ShaComputeWorker.js', import.meta.url).href
|
||||
//filename: new URL('./ShaComputeWorker.ts', import.meta.url).href
|
||||
filename: workerPath || process.env.WORKER_URL || workerUrl
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { createReadStream } from "fs";
|
||||
import {BinaryLike, createHash} from 'crypto';
|
||||
import { CID } from 'multiformats/cid';
|
||||
import { create } from "multiformats/hashes/digest";
|
||||
import {CID_ALGORITHM, CID_ALGORITHM_CODES, CID_ALGORITHM_NAMES} from "../MultiHashData.js";
|
||||
import {CID_ALGORITHM, CID_ALGORITHM_CODES, CID_ALGORITHM_NAMES} from "../MultiHashData";
|
||||
|
||||
export interface SimpleHash {
|
||||
update(data: BinaryLike),
|
||||
|
||||
+8
-8
@@ -1,11 +1,11 @@
|
||||
// Import and export directly to simplify access to library components
|
||||
export * from './ComputeHashIndexCache';
|
||||
export * from './ExistsAsync'; // Assuming 'async' is a function; adjust as necessary
|
||||
export * from './fileID/FileIDComputer';
|
||||
export * from './fileID/ShaComputeWorker'; // Assuming this exports a class or main function; adjust as needed
|
||||
export * from './HashComputer';
|
||||
export * from './HashIndexManager';
|
||||
export * from './ComputeHashIndexCache.js';
|
||||
export * from './ExistsAsync.js'; // Assuming 'async' is a function; adjust as necessary
|
||||
export * from './fileID/FileIDComputer.js';
|
||||
export * from './fileID/ShaComputeWorker.js'; // Assuming this exports a class or main function; adjust as needed
|
||||
export * from './HashComputer.js';
|
||||
export * from './HashIndexManager.js';
|
||||
// For MultiHashData.ts, assuming interfaces and enums need to be exported; you might need to adjust based on actual content
|
||||
export * from './MultiHashData';
|
||||
export * from './MultiHashData.js';
|
||||
// Assuming Properties.ts exports one or more interfaces; adjust as needed
|
||||
export * from './Properties';
|
||||
export * from './Properties.js';
|
||||
|
||||
Reference in New Issue
Block a user