add browser dist
This commit is contained in:
@@ -38,19 +38,4 @@ declare enum CID_ALGORITHM {
|
|||||||
sha3_384 = "sha3-384"
|
sha3_384 = "sha3-384"
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SimpleHash {
|
export { CID_ALGORITHM_NAMES as C, type MultiHashData as M, type ComputeInterface as a, CID_ALGORITHM_CODES as b, CID_ALGORITHM as c };
|
||||||
update(data: Buffer): any;
|
|
||||||
digest(): Buffer;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Compute the CIDs of a file using specific algorithms
|
|
||||||
* @param filePath The path to the file
|
|
||||||
* @param algorithms Array of algorithms ('sha256', 'sha1')
|
|
||||||
* @returns Array of CIDs (in the order of the algorithms)
|
|
||||||
*/
|
|
||||||
declare function computeCIDs({ filePath, algorithms }: {
|
|
||||||
filePath: string;
|
|
||||||
algorithms: CID_ALGORITHM_NAMES[];
|
|
||||||
}): Promise<string[]>;
|
|
||||||
|
|
||||||
export { CID_ALGORITHM_NAMES as C, type MultiHashData as M, type SimpleHash as S, type ComputeInterface as a, CID_ALGORITHM_CODES as b, CID_ALGORITHM as c, computeCIDs as d };
|
|
||||||
@@ -38,19 +38,4 @@ declare enum CID_ALGORITHM {
|
|||||||
sha3_384 = "sha3-384"
|
sha3_384 = "sha3-384"
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SimpleHash {
|
export { CID_ALGORITHM_NAMES as C, type MultiHashData as M, type ComputeInterface as a, CID_ALGORITHM_CODES as b, CID_ALGORITHM as c };
|
||||||
update(data: Buffer): any;
|
|
||||||
digest(): Buffer;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Compute the CIDs of a file using specific algorithms
|
|
||||||
* @param filePath The path to the file
|
|
||||||
* @param algorithms Array of algorithms ('sha256', 'sha1')
|
|
||||||
* @returns Array of CIDs (in the order of the algorithms)
|
|
||||||
*/
|
|
||||||
declare function computeCIDs({ filePath, algorithms }: {
|
|
||||||
filePath: string;
|
|
||||||
algorithms: CID_ALGORITHM_NAMES[];
|
|
||||||
}): Promise<string[]>;
|
|
||||||
|
|
||||||
export { CID_ALGORITHM_NAMES as C, type MultiHashData as M, type SimpleHash as S, type ComputeInterface as a, CID_ALGORITHM_CODES as b, CID_ALGORITHM as c, computeCIDs as d };
|
|
||||||
Vendored
+18
@@ -0,0 +1,18 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var chunkPAKJNZBJ_cjs = require('./chunk-PAKJNZBJ.cjs');
|
||||||
|
var stream = require('stream');
|
||||||
|
var digest = require('multiformats/hashes/digest');
|
||||||
|
var cid = require('multiformats/cid');
|
||||||
|
var crypto = require('crypto');
|
||||||
|
var u = require('crc-32');
|
||||||
|
|
||||||
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
||||||
|
|
||||||
|
var u__default = /*#__PURE__*/_interopDefault(u);
|
||||||
|
|
||||||
|
var c=class{_crc=void 0;update(e){return this._crc=u__default.default.buf(e,this._crc),this}digest(){let e=Buffer.alloc(4);return e.writeInt32BE(this._crc,0),e}};var i={cid_crc32:306,cid_md5:213,cid_sha1:17,"cid_sha2-256":18,"cid_sha3-256":22,"cid_sha3-384":21};function m(r){switch(r){case"cid_sha2-256":return crypto.createHash("sha256");case"cid_sha1":return crypto.createHash("sha1");case"cid_md5":return crypto.createHash("md5");case"cid_sha3-256":return crypto.createHash("sha3-256");case"cid_sha3-384":return crypto.createHash("sha3-384");case"cid_crc32":return new c;default:throw new Error(`Unsupported algorithm: ${r}`)}}async function L({stream:r,algorithms:e}){let a=_(e);if(r instanceof stream.Readable)for await(let t of r)a.forEach(s=>s.hasher.update(t));else {let t=r.getReader();for(;;){let{done:s,value:n}=await t.read();if(s)break;a.forEach(f=>f.hasher.update(Buffer.from(n)));}}return H(a)}function _(r){return r.filter(a=>Object.values(chunkPAKJNZBJ_cjs.b).includes(a)).map(a=>({hasher:m(a),code:i[a]}))}async function H(r){return await Promise.all(r.map(async({code:e,hasher:a})=>{let t=a.digest(),s=digest.create(e,t);return cid.CID.createV1(e,s).toString()}))}
|
||||||
|
|
||||||
|
exports.a = L;
|
||||||
|
//# sourceMappingURL=out.js.map
|
||||||
|
//# sourceMappingURL=chunk-33LRP2HS.cjs.map
|
||||||
Vendored
+1
File diff suppressed because one or more lines are too long
Vendored
-11
@@ -1,11 +0,0 @@
|
|||||||
import { createReadStream } from 'fs';
|
|
||||||
import { createHash } from 'crypto';
|
|
||||||
import { CID } from 'multiformats/cid';
|
|
||||||
import { create } from 'multiformats/hashes/digest';
|
|
||||||
import x from 'crc-32';
|
|
||||||
|
|
||||||
var o=(s=>(s[s.crc32=306]="crc32",s[s.md5=213]="md5",s[s.sha1=17]="sha1",s[s.sha256=18]="sha256",s[s.sha3_256=22]="sha3_256",s[s.sha3_384=21]="sha3_384",s))(o||{}),d=(s=>(s.crc32="cid_crc32",s.md5="cid_md5",s.sha1="cid_sha1",s.sha256="cid_sha2-256",s.sha3_256="cid_sha3-256",s.sha3_384="cid_sha3-384",s))(d||{}),u=(s=>(s.crc32="crc32",s.md5="md5",s.sha1="sha1",s.sha256="sha2-256",s.sha3_256="sha3-256",s.sha3_384="sha3-384",s))(u||{});var t=class{_crc=void 0;update(a){return this._crc=x.buf(a,this._crc),this}digest(){let a=Buffer.alloc(4);return a.writeInt32BE(this._crc,0),a}};async function B({filePath:h,algorithms:a}){let c={"cid_sha2-256":{code:18,hasher:createHash("sha256")},cid_sha1:{code:17,hasher:createHash("sha1")},cid_md5:{code:213,hasher:createHash("md5")},"cid_sha3-256":{code:22,hasher:createHash("sha3-256")},"cid_sha3-384":{code:21,hasher:createHash("sha3-384")},cid_crc32:{code:306,hasher:new t}},i=a.map(s=>({hasher:c[s].hasher,code:c[s].code})),n=createReadStream(h);for await(let s of n)for(let r of i)r.hasher.update(s);return await Promise.all(i.map(async({code:s,hasher:r})=>{let m=r.digest(),f=create(s,m);return CID.createV1(s,f).toString()}))}
|
|
||||||
|
|
||||||
export { o as a, d as b, u as c, B as d };
|
|
||||||
//# sourceMappingURL=out.js.map
|
|
||||||
//# sourceMappingURL=chunk-4EZ47WAR.js.map
|
|
||||||
Vendored
-1
File diff suppressed because one or more lines are too long
Vendored
+8
@@ -0,0 +1,8 @@
|
|||||||
|
import { a } from './chunk-A6J5HDTV.js';
|
||||||
|
import m from 'fs';
|
||||||
|
|
||||||
|
async function s({filePath:r,algorithms:e}){let o=m.createReadStream(r);return a({stream:o,algorithms:e})}
|
||||||
|
|
||||||
|
export { s as a };
|
||||||
|
//# sourceMappingURL=out.js.map
|
||||||
|
//# sourceMappingURL=chunk-6UBSWOQL.js.map
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"sources":["../src/lib/file-id/ShaComputeWorker.ts"],"names":["fs","computeCIDs","filePath","algorithms","stream"],"mappings":"wCACA,OAAOA,MAAQ,KASf,eAAOC,EAAmC,CAAC,SAAAC,EAAU,WAAAC,CAAU,EAGzC,CAClB,IAAMC,EAASJ,EAAG,iBAAiBE,CAAQ,EAC3C,OAAOD,EAAoB,CAAC,OAAAG,EAAQ,WAAAD,CAAU,CAAC,CACnD","sourcesContent":["import {CID_ALGORITHM_NAMES} from \"@root/hash-compute/MultiHashData\";\nimport fs from \"fs\";\nimport {computeCIDs as computeCIDsInternal} from \"./ComputeHash\";\n\n/**\n * Compute the CIDs of a file using specific algorithms\n * @param filePath The path to the file\n * @param algorithms Array of algorithms ('sha256', 'sha1')\n * @returns Array of CIDs (in the order of the algorithms)\n */\nexport default async function computeCIDs({filePath, algorithms}: {\n filePath: string;\n algorithms: CID_ALGORITHM_NAMES[]\n}): Promise<string[]> {\n const stream = fs.createReadStream(filePath);\n return computeCIDsInternal({stream, algorithms});\n}\n"]}
|
||||||
Vendored
+12
@@ -0,0 +1,12 @@
|
|||||||
|
import { b } from './chunk-YCFZVUZC.js';
|
||||||
|
import { Readable } from 'stream';
|
||||||
|
import { create } from 'multiformats/hashes/digest';
|
||||||
|
import { CID } from 'multiformats/cid';
|
||||||
|
import { createHash } from 'crypto';
|
||||||
|
import u from 'crc-32';
|
||||||
|
|
||||||
|
var c=class{_crc=void 0;update(e){return this._crc=u.buf(e,this._crc),this}digest(){let e=Buffer.alloc(4);return e.writeInt32BE(this._crc,0),e}};var i={cid_crc32:306,cid_md5:213,cid_sha1:17,"cid_sha2-256":18,"cid_sha3-256":22,"cid_sha3-384":21};function m(r){switch(r){case"cid_sha2-256":return createHash("sha256");case"cid_sha1":return createHash("sha1");case"cid_md5":return createHash("md5");case"cid_sha3-256":return createHash("sha3-256");case"cid_sha3-384":return createHash("sha3-384");case"cid_crc32":return new c;default:throw new Error(`Unsupported algorithm: ${r}`)}}async function L({stream:r,algorithms:e}){let a=_(e);if(r instanceof Readable)for await(let t of r)a.forEach(s=>s.hasher.update(t));else {let t=r.getReader();for(;;){let{done:s,value:n}=await t.read();if(s)break;a.forEach(f=>f.hasher.update(Buffer.from(n)));}}return H(a)}function _(r){return r.filter(a=>Object.values(b).includes(a)).map(a=>({hasher:m(a),code:i[a]}))}async function H(r){return await Promise.all(r.map(async({code:e,hasher:a})=>{let t=a.digest(),s=create(e,t);return CID.createV1(e,s).toString()}))}
|
||||||
|
|
||||||
|
export { L as a };
|
||||||
|
//# sourceMappingURL=out.js.map
|
||||||
|
//# sourceMappingURL=chunk-A6J5HDTV.js.map
|
||||||
Vendored
+1
File diff suppressed because one or more lines are too long
Vendored
-20
@@ -1,20 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
var fs = require('fs');
|
|
||||||
var crypto = require('crypto');
|
|
||||||
var cid = require('multiformats/cid');
|
|
||||||
var digest = require('multiformats/hashes/digest');
|
|
||||||
var x = require('crc-32');
|
|
||||||
|
|
||||||
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
||||||
|
|
||||||
var x__default = /*#__PURE__*/_interopDefault(x);
|
|
||||||
|
|
||||||
var o=(s=>(s[s.crc32=306]="crc32",s[s.md5=213]="md5",s[s.sha1=17]="sha1",s[s.sha256=18]="sha256",s[s.sha3_256=22]="sha3_256",s[s.sha3_384=21]="sha3_384",s))(o||{}),d=(s=>(s.crc32="cid_crc32",s.md5="cid_md5",s.sha1="cid_sha1",s.sha256="cid_sha2-256",s.sha3_256="cid_sha3-256",s.sha3_384="cid_sha3-384",s))(d||{}),u=(s=>(s.crc32="crc32",s.md5="md5",s.sha1="sha1",s.sha256="sha2-256",s.sha3_256="sha3-256",s.sha3_384="sha3-384",s))(u||{});var t=class{_crc=void 0;update(a){return this._crc=x__default.default.buf(a,this._crc),this}digest(){let a=Buffer.alloc(4);return a.writeInt32BE(this._crc,0),a}};async function B({filePath:h,algorithms:a}){let c={"cid_sha2-256":{code:18,hasher:crypto.createHash("sha256")},cid_sha1:{code:17,hasher:crypto.createHash("sha1")},cid_md5:{code:213,hasher:crypto.createHash("md5")},"cid_sha3-256":{code:22,hasher:crypto.createHash("sha3-256")},"cid_sha3-384":{code:21,hasher:crypto.createHash("sha3-384")},cid_crc32:{code:306,hasher:new t}},i=a.map(s=>({hasher:c[s].hasher,code:c[s].code})),n=fs.createReadStream(h);for await(let s of n)for(let r of i)r.hasher.update(s);return await Promise.all(i.map(async({code:s,hasher:r})=>{let m=r.digest(),f=digest.create(s,m);return cid.CID.createV1(s,f).toString()}))}
|
|
||||||
|
|
||||||
exports.a = o;
|
|
||||||
exports.b = d;
|
|
||||||
exports.c = u;
|
|
||||||
exports.d = B;
|
|
||||||
//# sourceMappingURL=out.js.map
|
|
||||||
//# sourceMappingURL=chunk-ASEKTFOG.cjs.map
|
|
||||||
Vendored
-1
File diff suppressed because one or more lines are too long
Vendored
+4
@@ -0,0 +1,4 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
//# sourceMappingURL=out.js.map
|
||||||
|
//# sourceMappingURL=chunk-KWYLOVWT.cjs.map
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"sources":[],"names":[],"mappings":""}
|
||||||
Vendored
+14
@@ -0,0 +1,14 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var chunk33LRP2HS_cjs = require('./chunk-33LRP2HS.cjs');
|
||||||
|
var m = require('fs');
|
||||||
|
|
||||||
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
||||||
|
|
||||||
|
var m__default = /*#__PURE__*/_interopDefault(m);
|
||||||
|
|
||||||
|
async function s({filePath:r,algorithms:e}){let o=m__default.default.createReadStream(r);return chunk33LRP2HS_cjs.a({stream:o,algorithms:e})}
|
||||||
|
|
||||||
|
exports.a = s;
|
||||||
|
//# sourceMappingURL=out.js.map
|
||||||
|
//# sourceMappingURL=chunk-KZVIGNTH.cjs.map
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"sources":["../src/lib/file-id/ShaComputeWorker.ts"],"names":["fs","computeCIDs","filePath","algorithms","stream"],"mappings":"yCACA,OAAOA,MAAQ,KASf,eAAOC,EAAmC,CAAC,SAAAC,EAAU,WAAAC,CAAU,EAGzC,CAClB,IAAMC,EAASJ,EAAG,iBAAiBE,CAAQ,EAC3C,OAAOD,EAAoB,CAAC,OAAAG,EAAQ,WAAAD,CAAU,CAAC,CACnD","sourcesContent":["import {CID_ALGORITHM_NAMES} from \"@root/hash-compute/MultiHashData\";\nimport fs from \"fs\";\nimport {computeCIDs as computeCIDsInternal} from \"./ComputeHash\";\n\n/**\n * Compute the CIDs of a file using specific algorithms\n * @param filePath The path to the file\n * @param algorithms Array of algorithms ('sha256', 'sha1')\n * @returns Array of CIDs (in the order of the algorithms)\n */\nexport default async function computeCIDs({filePath, algorithms}: {\n filePath: string;\n algorithms: CID_ALGORITHM_NAMES[]\n}): Promise<string[]> {\n const stream = fs.createReadStream(filePath);\n return computeCIDsInternal({stream, algorithms});\n}\n"]}
|
||||||
Vendored
+9
@@ -0,0 +1,9 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var s=(a=>(a[a.crc32=306]="crc32",a[a.md5=213]="md5",a[a.sha1=17]="sha1",a[a.sha256=18]="sha256",a[a.sha3_256=22]="sha3_256",a[a.sha3_384=21]="sha3_384",a))(s||{}),c=(a=>(a.crc32="cid_crc32",a.md5="cid_md5",a.sha1="cid_sha1",a.sha256="cid_sha2-256",a.sha3_256="cid_sha3-256",a.sha3_384="cid_sha3-384",a))(c||{}),h=(a=>(a.crc32="crc32",a.md5="md5",a.sha1="sha1",a.sha256="sha2-256",a.sha3_256="sha3-256",a.sha3_384="sha3-384",a))(h||{});
|
||||||
|
|
||||||
|
exports.a = s;
|
||||||
|
exports.b = c;
|
||||||
|
exports.c = h;
|
||||||
|
//# sourceMappingURL=out.js.map
|
||||||
|
//# sourceMappingURL=chunk-PAKJNZBJ.cjs.map
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"sources":["../src/lib/hash-compute/MultiHashData.ts"],"names":["CID_ALGORITHM_CODES","CID_ALGORITHM_NAMES","CID_ALGORITHM"],"mappings":"AAiBO,IAAKA,OACRA,IAAA,MAAQ,KAAR,QACAA,IAAA,IAAM,KAAN,MACAA,IAAA,KAAO,IAAP,OACAA,IAAA,OAAS,IAAT,SACAA,IAAA,SAAW,IAAX,WACAA,IAAA,SAAW,IAAX,WANQA,OAAA,IASAC,OACRA,EAAA,MAAQ,YACRA,EAAA,IAAM,UACNA,EAAA,KAAO,WACPA,EAAA,OAAS,eACTA,EAAA,SAAW,eACXA,EAAA,SAAW,eANHA,OAAA,IASAC,OACRA,EAAA,MAAQ,QACRA,EAAA,IAAM,MACNA,EAAA,KAAO,OACPA,EAAA,OAAS,WACTA,EAAA,SAAW,WACXA,EAAA,SAAW,WANHA,OAAA","sourcesContent":["export interface MultiHashData {\n cid_crc32?: string; //0x0132 CRC32 (SFV)\n cid_md5?: string; // 0xd5 md5\n cid_sha1?: string; // 0x11 sha1\n \"cid_sha2-256\"?: string;//0x12 sha2-256\n \"cid_sha3-256\"?: string; // 0x16 sha3-256\n \"cid_sha3_384\"?: string; // 0x16 sha3-256\n}\n\nexport interface ComputeInterface {\n computeMissingHash(filePath: string, metadata: MultiHashData): Promise<void>;\n}\n\n/**\n * according to\n * https://ipfs.io/ipfs/QmXec1jjwzxWJoNbxQF5KffL8q6hFXm9QwUGaa3wKGk6dT/#title=Multicodecs&src=https://raw.githubusercontent.com/multiformats/multicodec/master/table.csv\n */\nexport enum CID_ALGORITHM_CODES {\n crc32 = 0x0132,\n md5 = 0xd5,\n sha1 = 0x11,\n sha256 = 0x12,\n sha3_256 = 0x16,\n sha3_384 = 0x15,\n}\n\nexport enum CID_ALGORITHM_NAMES {\n crc32 = 'cid_crc32',\n md5 = 'cid_md5',\n sha1 = 'cid_sha1',\n sha256 = 'cid_sha2-256',\n sha3_256 = 'cid_sha3-256',\n sha3_384 = 'cid_sha3-384',\n}\n\nexport enum CID_ALGORITHM {\n crc32 = 'crc32',\n md5 = 'md5',\n sha1 = 'sha1',\n sha256 = 'sha2-256',\n sha3_256 = 'sha3-256',\n sha3_384 = 'sha3-384',\n}"]}
|
||||||
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
//# sourceMappingURL=out.js.map
|
||||||
|
//# sourceMappingURL=chunk-XCJZALP2.js.map
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"sources":[],"names":[],"mappings":""}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
var s=(a=>(a[a.crc32=306]="crc32",a[a.md5=213]="md5",a[a.sha1=17]="sha1",a[a.sha256=18]="sha256",a[a.sha3_256=22]="sha3_256",a[a.sha3_384=21]="sha3_384",a))(s||{}),c=(a=>(a.crc32="cid_crc32",a.md5="cid_md5",a.sha1="cid_sha1",a.sha256="cid_sha2-256",a.sha3_256="cid_sha3-256",a.sha3_384="cid_sha3-384",a))(c||{}),h=(a=>(a.crc32="crc32",a.md5="md5",a.sha1="sha1",a.sha256="sha2-256",a.sha3_256="sha3-256",a.sha3_384="sha3-384",a))(h||{});
|
||||||
|
|
||||||
|
export { s as a, c as b, h as c };
|
||||||
|
//# sourceMappingURL=out.js.map
|
||||||
|
//# sourceMappingURL=chunk-YCFZVUZC.js.map
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"sources":["../src/lib/hash-compute/MultiHashData.ts"],"names":["CID_ALGORITHM_CODES","CID_ALGORITHM_NAMES","CID_ALGORITHM"],"mappings":"AAiBO,IAAKA,OACRA,IAAA,MAAQ,KAAR,QACAA,IAAA,IAAM,KAAN,MACAA,IAAA,KAAO,IAAP,OACAA,IAAA,OAAS,IAAT,SACAA,IAAA,SAAW,IAAX,WACAA,IAAA,SAAW,IAAX,WANQA,OAAA,IASAC,OACRA,EAAA,MAAQ,YACRA,EAAA,IAAM,UACNA,EAAA,KAAO,WACPA,EAAA,OAAS,eACTA,EAAA,SAAW,eACXA,EAAA,SAAW,eANHA,OAAA,IASAC,OACRA,EAAA,MAAQ,QACRA,EAAA,IAAM,MACNA,EAAA,KAAO,OACPA,EAAA,OAAS,WACTA,EAAA,SAAW,WACXA,EAAA,SAAW,WANHA,OAAA","sourcesContent":["export interface MultiHashData {\n cid_crc32?: string; //0x0132 CRC32 (SFV)\n cid_md5?: string; // 0xd5 md5\n cid_sha1?: string; // 0x11 sha1\n \"cid_sha2-256\"?: string;//0x12 sha2-256\n \"cid_sha3-256\"?: string; // 0x16 sha3-256\n \"cid_sha3_384\"?: string; // 0x16 sha3-256\n}\n\nexport interface ComputeInterface {\n computeMissingHash(filePath: string, metadata: MultiHashData): Promise<void>;\n}\n\n/**\n * according to\n * https://ipfs.io/ipfs/QmXec1jjwzxWJoNbxQF5KffL8q6hFXm9QwUGaa3wKGk6dT/#title=Multicodecs&src=https://raw.githubusercontent.com/multiformats/multicodec/master/table.csv\n */\nexport enum CID_ALGORITHM_CODES {\n crc32 = 0x0132,\n md5 = 0xd5,\n sha1 = 0x11,\n sha256 = 0x12,\n sha3_256 = 0x16,\n sha3_384 = 0x15,\n}\n\nexport enum CID_ALGORITHM_NAMES {\n crc32 = 'cid_crc32',\n md5 = 'cid_md5',\n sha1 = 'cid_sha1',\n sha256 = 'cid_sha2-256',\n sha3_256 = 'cid_sha3-256',\n sha3_384 = 'cid_sha3-384',\n}\n\nexport enum CID_ALGORITHM {\n crc32 = 'crc32',\n md5 = 'md5',\n sha1 = 'sha1',\n sha256 = 'sha2-256',\n sha3_256 = 'sha3-256',\n sha3_384 = 'sha3-384',\n}"]}
|
||||||
Vendored
+27
@@ -0,0 +1,27 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
require('./chunk-KWYLOVWT.cjs');
|
||||||
|
var chunk33LRP2HS_cjs = require('./chunk-33LRP2HS.cjs');
|
||||||
|
var chunkPAKJNZBJ_cjs = require('./chunk-PAKJNZBJ.cjs');
|
||||||
|
|
||||||
|
var a=class{constructor(r){this.targetHash=r;}async computeMissingHash(r,e){let t=this.targetHash.filter(o=>!e[o]);if(t.length===0)return;let i=await chunk33LRP2HS_cjs.a({stream:r,algorithms:t});for(let[o,c]of i.entries()){let n=t[o];e[n]=c;}}};
|
||||||
|
|
||||||
|
Object.defineProperty(exports, "computeCIDs", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function () { return chunk33LRP2HS_cjs.a; }
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "CID_ALGORITHM", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function () { return chunkPAKJNZBJ_cjs.c; }
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "CID_ALGORITHM_CODES", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function () { return chunkPAKJNZBJ_cjs.a; }
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "CID_ALGORITHM_NAMES", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function () { return chunkPAKJNZBJ_cjs.b; }
|
||||||
|
});
|
||||||
|
exports.HashComputer = a;
|
||||||
|
//# sourceMappingURL=out.js.map
|
||||||
|
//# sourceMappingURL=index-browser.cjs.map
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"sources":["../src/lib/hash-compute/HashComputer.ts"],"names":["HashComputer","targetHash","stream","metadata","neededHashes","hashName","cids","computeCIDs","index","cid","hashType"],"mappings":"6HAKO,IAAMA,EAAN,KAAkB,CAErB,YAAoBC,EAAmC,CAAnC,gBAAAA,CACpB,CAEA,MAAM,mBAAmBC,EAAkBC,EAAwC,CAE/E,IAAMC,EAAe,KAAK,WAAW,OAAOC,GAAY,CAACF,EAASE,CAAQ,CAAC,EAG3E,GAAID,EAAa,SAAW,EACxB,OAIJ,IAAME,EAAO,MAAMC,EAAY,CAAC,OAAAL,EAAQ,WAAWE,CAAY,CAAC,EAGhE,OAAW,CAACI,EAAOC,CAAG,IAAKH,EAAK,QAAQ,EAAG,CACvC,IAAMI,EAAWN,EAAaI,CAAK,EACnCL,EAASO,CAAQ,EAAID,CACzB,CACJ,CACJ","sourcesContent":["import {CID_ALGORITHM_NAMES, MultiHashData} from \"./MultiHashData\";\nimport {Readable} from \"stream\";\n\nimport {computeCIDs} from \"@root/file-id/ComputeHash\";\n\nexport class HashComputer{\n\n constructor(private targetHash: CID_ALGORITHM_NAMES[]) {\n }\n\n async computeMissingHash(stream: Readable, metadata: MultiHashData): Promise<void> {\n // Dynamically determine which hashes are needed\n const neededHashes = this.targetHash.filter(hashName => !metadata[hashName]);\n\n // If all hashes are already computed, skip the processing\n if (neededHashes.length === 0) {\n return;\n }\n\n // Compute only the needed CIDs\n const cids = await computeCIDs({stream, algorithms:neededHashes});\n\n // Map the computed CIDs back to their respective metadata properties\n for (const [index, cid] of cids.entries()) {\n const hashType = neededHashes[index];\n metadata[hashType] = cid;\n }\n }\n}\n"]}
|
||||||
Vendored
+23
@@ -0,0 +1,23 @@
|
|||||||
|
import { C as CID_ALGORITHM_NAMES, M as MultiHashData } from './MultiHashData-B-scpa5G.cjs';
|
||||||
|
export { c as CID_ALGORITHM, b as CID_ALGORITHM_CODES, a as ComputeInterface } from './MultiHashData-B-scpa5G.cjs';
|
||||||
|
export { FileIDComputerInterface, FileProcessorInterface } from './index-interface.cjs';
|
||||||
|
import { Readable } from 'stream';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the CIDs of a file using specific algorithms
|
||||||
|
* @param stream The Readable stream of the file
|
||||||
|
* @param algorithms Array of algorithms ('sha256', 'sha1', etc.)
|
||||||
|
* @returns Array of CIDs (in the order of the algorithms)
|
||||||
|
*/
|
||||||
|
declare function computeCIDs({ stream, algorithms }: {
|
||||||
|
stream: Readable | ReadableStream;
|
||||||
|
algorithms: CID_ALGORITHM_NAMES[];
|
||||||
|
}): Promise<string[]>;
|
||||||
|
|
||||||
|
declare class HashComputer {
|
||||||
|
private targetHash;
|
||||||
|
constructor(targetHash: CID_ALGORITHM_NAMES[]);
|
||||||
|
computeMissingHash(stream: Readable, metadata: MultiHashData): Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { CID_ALGORITHM_NAMES, HashComputer, MultiHashData, computeCIDs };
|
||||||
Vendored
+23
@@ -0,0 +1,23 @@
|
|||||||
|
import { C as CID_ALGORITHM_NAMES, M as MultiHashData } from './MultiHashData-B-scpa5G.js';
|
||||||
|
export { c as CID_ALGORITHM, b as CID_ALGORITHM_CODES, a as ComputeInterface } from './MultiHashData-B-scpa5G.js';
|
||||||
|
export { FileIDComputerInterface, FileProcessorInterface } from './index-interface.js';
|
||||||
|
import { Readable } from 'stream';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the CIDs of a file using specific algorithms
|
||||||
|
* @param stream The Readable stream of the file
|
||||||
|
* @param algorithms Array of algorithms ('sha256', 'sha1', etc.)
|
||||||
|
* @returns Array of CIDs (in the order of the algorithms)
|
||||||
|
*/
|
||||||
|
declare function computeCIDs({ stream, algorithms }: {
|
||||||
|
stream: Readable | ReadableStream;
|
||||||
|
algorithms: CID_ALGORITHM_NAMES[];
|
||||||
|
}): Promise<string[]>;
|
||||||
|
|
||||||
|
declare class HashComputer {
|
||||||
|
private targetHash;
|
||||||
|
constructor(targetHash: CID_ALGORITHM_NAMES[]);
|
||||||
|
computeMissingHash(stream: Readable, metadata: MultiHashData): Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { CID_ALGORITHM_NAMES, HashComputer, MultiHashData, computeCIDs };
|
||||||
Vendored
+10
@@ -0,0 +1,10 @@
|
|||||||
|
import './chunk-XCJZALP2.js';
|
||||||
|
import { a as a$1 } from './chunk-A6J5HDTV.js';
|
||||||
|
export { a as computeCIDs } from './chunk-A6J5HDTV.js';
|
||||||
|
export { c as CID_ALGORITHM, a as CID_ALGORITHM_CODES, b as CID_ALGORITHM_NAMES } from './chunk-YCFZVUZC.js';
|
||||||
|
|
||||||
|
var a=class{constructor(r){this.targetHash=r;}async computeMissingHash(r,e){let t=this.targetHash.filter(o=>!e[o]);if(t.length===0)return;let i=await a$1({stream:r,algorithms:t});for(let[o,c]of i.entries()){let n=t[o];e[n]=c;}}};
|
||||||
|
|
||||||
|
export { a as HashComputer };
|
||||||
|
//# sourceMappingURL=out.js.map
|
||||||
|
//# sourceMappingURL=index-browser.js.map
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"sources":["../src/lib/hash-compute/HashComputer.ts"],"names":["HashComputer","targetHash","stream","metadata","neededHashes","hashName","cids","computeCIDs","index","cid","hashType"],"mappings":"0HAKO,IAAMA,EAAN,KAAkB,CAErB,YAAoBC,EAAmC,CAAnC,gBAAAA,CACpB,CAEA,MAAM,mBAAmBC,EAAkBC,EAAwC,CAE/E,IAAMC,EAAe,KAAK,WAAW,OAAOC,GAAY,CAACF,EAASE,CAAQ,CAAC,EAG3E,GAAID,EAAa,SAAW,EACxB,OAIJ,IAAME,EAAO,MAAMC,EAAY,CAAC,OAAAL,EAAQ,WAAWE,CAAY,CAAC,EAGhE,OAAW,CAACI,EAAOC,CAAG,IAAKH,EAAK,QAAQ,EAAG,CACvC,IAAMI,EAAWN,EAAaI,CAAK,EACnCL,EAASO,CAAQ,EAAID,CACzB,CACJ,CACJ","sourcesContent":["import {CID_ALGORITHM_NAMES, MultiHashData} from \"./MultiHashData\";\nimport {Readable} from \"stream\";\n\nimport {computeCIDs} from \"@root/file-id/ComputeHash\";\n\nexport class HashComputer{\n\n constructor(private targetHash: CID_ALGORITHM_NAMES[]) {\n }\n\n async computeMissingHash(stream: Readable, metadata: MultiHashData): Promise<void> {\n // Dynamically determine which hashes are needed\n const neededHashes = this.targetHash.filter(hashName => !metadata[hashName]);\n\n // If all hashes are already computed, skip the processing\n if (neededHashes.length === 0) {\n return;\n }\n\n // Compute only the needed CIDs\n const cids = await computeCIDs({stream, algorithms:neededHashes});\n\n // Map the computed CIDs back to their respective metadata properties\n for (const [index, cid] of cids.entries()) {\n const hashType = neededHashes[index];\n metadata[hashType] = cid;\n }\n }\n}\n"]}
|
||||||
Vendored
+21
@@ -0,0 +1,21 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
require('./chunk-KWYLOVWT.cjs');
|
||||||
|
var chunkPAKJNZBJ_cjs = require('./chunk-PAKJNZBJ.cjs');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Object.defineProperty(exports, "CID_ALGORITHM", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function () { return chunkPAKJNZBJ_cjs.c; }
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "CID_ALGORITHM_CODES", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function () { return chunkPAKJNZBJ_cjs.a; }
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "CID_ALGORITHM_NAMES", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function () { return chunkPAKJNZBJ_cjs.b; }
|
||||||
|
});
|
||||||
|
//# sourceMappingURL=out.js.map
|
||||||
|
//# sourceMappingURL=index-interface.cjs.map
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"sources":[],"names":[],"mappings":""}
|
||||||
Vendored
+15
@@ -0,0 +1,15 @@
|
|||||||
|
import { C as CID_ALGORITHM_NAMES } from './MultiHashData-B-scpa5G.cjs';
|
||||||
|
export { c as CID_ALGORITHM, b as CID_ALGORITHM_CODES, a as ComputeInterface, M as MultiHashData } from './MultiHashData-B-scpa5G.cjs';
|
||||||
|
import * as Stream from 'stream';
|
||||||
|
|
||||||
|
interface FileProcessorInterface {
|
||||||
|
processFile(current: number, queueSize: number, nfoFilePath: string): Promise<void>;
|
||||||
|
canProcessFile(filePath: string): Promise<boolean>;
|
||||||
|
deleteFile(filePath: string): Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FileIDComputerInterface {
|
||||||
|
computeCIDs(filePath: Stream, algorithms: CID_ALGORITHM_NAMES[]): Promise<string[]>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { CID_ALGORITHM_NAMES, type FileIDComputerInterface, type FileProcessorInterface };
|
||||||
Vendored
+15
@@ -0,0 +1,15 @@
|
|||||||
|
import { C as CID_ALGORITHM_NAMES } from './MultiHashData-B-scpa5G.js';
|
||||||
|
export { c as CID_ALGORITHM, b as CID_ALGORITHM_CODES, a as ComputeInterface, M as MultiHashData } from './MultiHashData-B-scpa5G.js';
|
||||||
|
import * as Stream from 'stream';
|
||||||
|
|
||||||
|
interface FileProcessorInterface {
|
||||||
|
processFile(current: number, queueSize: number, nfoFilePath: string): Promise<void>;
|
||||||
|
canProcessFile(filePath: string): Promise<boolean>;
|
||||||
|
deleteFile(filePath: string): Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FileIDComputerInterface {
|
||||||
|
computeCIDs(filePath: Stream, algorithms: CID_ALGORITHM_NAMES[]): Promise<string[]>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { CID_ALGORITHM_NAMES, type FileIDComputerInterface, type FileProcessorInterface };
|
||||||
Vendored
+4
@@ -0,0 +1,4 @@
|
|||||||
|
import './chunk-XCJZALP2.js';
|
||||||
|
export { c as CID_ALGORITHM, a as CID_ALGORITHM_CODES, b as CID_ALGORITHM_NAMES } from './chunk-YCFZVUZC.js';
|
||||||
|
//# sourceMappingURL=out.js.map
|
||||||
|
//# sourceMappingURL=index-interface.js.map
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"sources":[],"names":[],"mappings":""}
|
||||||
Vendored
+11
-9
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+20
-30
@@ -1,8 +1,23 @@
|
|||||||
import { C as CID_ALGORITHM_NAMES, a as ComputeInterface, M as MultiHashData } from './ShaComputeWorker-CNdGUbtT.cjs';
|
import { C as CID_ALGORITHM_NAMES, a as ComputeInterface, M as MultiHashData } from './MultiHashData-B-scpa5G.cjs';
|
||||||
export { c as CID_ALGORITHM, b as CID_ALGORITHM_CODES, S as SimpleHash } from './ShaComputeWorker-CNdGUbtT.cjs';
|
export { c as CID_ALGORITHM, b as CID_ALGORITHM_CODES } from './MultiHashData-B-scpa5G.cjs';
|
||||||
import * as PQueue from 'p-queue';
|
import * as PQueue from 'p-queue';
|
||||||
import PQueue__default from 'p-queue';
|
import PQueue__default from 'p-queue';
|
||||||
import * as p_queue_dist_priority_queue_js from 'p-queue/dist/priority-queue.js';
|
import * as p_queue_dist_priority_queue_js from 'p-queue/dist/priority-queue.js';
|
||||||
|
import { FileProcessorInterface } from './index-interface.cjs';
|
||||||
|
export { FileIDComputerInterface } from './index-interface.cjs';
|
||||||
|
import 'stream';
|
||||||
|
|
||||||
|
declare class FileIDComputerWorker {
|
||||||
|
private piscina;
|
||||||
|
constructor(workerPath?: string);
|
||||||
|
/**
|
||||||
|
* Compute the CIDs of a file using specific algorithms
|
||||||
|
* @param filePath The path to the file
|
||||||
|
* @param algorithms Array of algorithms ('sha256', 'sha1')
|
||||||
|
* @returns Array of CIDs (in the order of the algorithms)
|
||||||
|
*/
|
||||||
|
computeCIDs(filePath: string, algorithms: CID_ALGORITHM_NAMES[]): Promise<string[]>;
|
||||||
|
}
|
||||||
|
|
||||||
interface IndexLine extends Partial<Record<CID_ALGORITHM_NAMES, string>> {
|
interface IndexLine extends Partial<Record<CID_ALGORITHM_NAMES, string>> {
|
||||||
path: string;
|
path: string;
|
||||||
@@ -41,7 +56,7 @@ declare class HashIndexManager {
|
|||||||
addFileCid(filePath: string, fileSize: number, mtime: string, hashs: Partial<Record<CID_ALGORITHM_NAMES, string>>): void;
|
addFileCid(filePath: string, fileSize: number, mtime: string, hashs: Partial<Record<CID_ALGORITHM_NAMES, string>>): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare class ComputeHashIndexCache implements ComputeInterface {
|
declare class HashComputerIndexCache implements ComputeInterface {
|
||||||
private targetHash;
|
private targetHash;
|
||||||
private hashIndexManager;
|
private hashIndexManager;
|
||||||
private hashComputer;
|
private hashComputer;
|
||||||
@@ -50,38 +65,13 @@ declare class ComputeHashIndexCache implements ComputeInterface {
|
|||||||
getHashIndexManager(): Promise<HashIndexManager>;
|
getHashIndexManager(): Promise<HashIndexManager>;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare function existsAsync(filePath: string): Promise<boolean>;
|
declare class HashComputerWorker implements ComputeInterface {
|
||||||
|
|
||||||
declare class FileIDComputer {
|
|
||||||
private piscina;
|
|
||||||
constructor(workerPath?: string);
|
|
||||||
/**
|
|
||||||
* Compute the CIDs of a file using specific algorithms
|
|
||||||
* @param filePath The path to the file
|
|
||||||
* @param algorithms Array of algorithms ('sha256', 'sha1')
|
|
||||||
* @returns Array of CIDs (in the order of the algorithms)
|
|
||||||
*/
|
|
||||||
computeCIDs(filePath: string, algorithms: CID_ALGORITHM_NAMES[]): Promise<string[]>;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare class HashComputer implements ComputeInterface {
|
|
||||||
private targetHash;
|
private targetHash;
|
||||||
private fileIDComputer;
|
private fileIDComputer;
|
||||||
constructor(targetHash: CID_ALGORITHM_NAMES[], workerPath?: string);
|
constructor(targetHash: CID_ALGORITHM_NAMES[], workerPath?: string);
|
||||||
computeMissingHash(filePath: string, metadata: MultiHashData): Promise<void>;
|
computeMissingHash(filePath: string, metadata: MultiHashData): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Properties {
|
|
||||||
TARGET_HASHES: string;
|
|
||||||
INDEX_FILE_PATH: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface FileProcessorInterface {
|
|
||||||
processFile(current: number, queueSize: number, nfoFilePath: string): Promise<void>;
|
|
||||||
canProcessFile(filePath: string): Promise<boolean>;
|
|
||||||
deleteFile(filePath: string): Promise<void>;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare class FolderWatcher {
|
declare class FolderWatcher {
|
||||||
private WATCH_FOLDER_LIST;
|
private WATCH_FOLDER_LIST;
|
||||||
private config;
|
private config;
|
||||||
@@ -115,4 +105,4 @@ declare class FolderWatcher {
|
|||||||
watch(): Promise<void>;
|
watch(): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { CID_ALGORITHM_NAMES, ComputeHashIndexCache, ComputeInterface, FileIDComputer, type FileProcessorInterface, FolderWatcher, HashComputer, HashIndexManager, INDEX_HEADERS, MultiHashData, type Properties, existsAsync };
|
export { CID_ALGORITHM_NAMES, ComputeInterface, FileIDComputerWorker, FileProcessorInterface, FolderWatcher, HashComputerIndexCache, HashComputerWorker, HashIndexManager, INDEX_HEADERS, MultiHashData };
|
||||||
|
|||||||
Vendored
+20
-30
@@ -1,8 +1,23 @@
|
|||||||
import { C as CID_ALGORITHM_NAMES, a as ComputeInterface, M as MultiHashData } from './ShaComputeWorker-CNdGUbtT.js';
|
import { C as CID_ALGORITHM_NAMES, a as ComputeInterface, M as MultiHashData } from './MultiHashData-B-scpa5G.js';
|
||||||
export { c as CID_ALGORITHM, b as CID_ALGORITHM_CODES, S as SimpleHash } from './ShaComputeWorker-CNdGUbtT.js';
|
export { c as CID_ALGORITHM, b as CID_ALGORITHM_CODES } from './MultiHashData-B-scpa5G.js';
|
||||||
import * as PQueue from 'p-queue';
|
import * as PQueue from 'p-queue';
|
||||||
import PQueue__default from 'p-queue';
|
import PQueue__default from 'p-queue';
|
||||||
import * as p_queue_dist_priority_queue_js from 'p-queue/dist/priority-queue.js';
|
import * as p_queue_dist_priority_queue_js from 'p-queue/dist/priority-queue.js';
|
||||||
|
import { FileProcessorInterface } from './index-interface.js';
|
||||||
|
export { FileIDComputerInterface } from './index-interface.js';
|
||||||
|
import 'stream';
|
||||||
|
|
||||||
|
declare class FileIDComputerWorker {
|
||||||
|
private piscina;
|
||||||
|
constructor(workerPath?: string);
|
||||||
|
/**
|
||||||
|
* Compute the CIDs of a file using specific algorithms
|
||||||
|
* @param filePath The path to the file
|
||||||
|
* @param algorithms Array of algorithms ('sha256', 'sha1')
|
||||||
|
* @returns Array of CIDs (in the order of the algorithms)
|
||||||
|
*/
|
||||||
|
computeCIDs(filePath: string, algorithms: CID_ALGORITHM_NAMES[]): Promise<string[]>;
|
||||||
|
}
|
||||||
|
|
||||||
interface IndexLine extends Partial<Record<CID_ALGORITHM_NAMES, string>> {
|
interface IndexLine extends Partial<Record<CID_ALGORITHM_NAMES, string>> {
|
||||||
path: string;
|
path: string;
|
||||||
@@ -41,7 +56,7 @@ declare class HashIndexManager {
|
|||||||
addFileCid(filePath: string, fileSize: number, mtime: string, hashs: Partial<Record<CID_ALGORITHM_NAMES, string>>): void;
|
addFileCid(filePath: string, fileSize: number, mtime: string, hashs: Partial<Record<CID_ALGORITHM_NAMES, string>>): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare class ComputeHashIndexCache implements ComputeInterface {
|
declare class HashComputerIndexCache implements ComputeInterface {
|
||||||
private targetHash;
|
private targetHash;
|
||||||
private hashIndexManager;
|
private hashIndexManager;
|
||||||
private hashComputer;
|
private hashComputer;
|
||||||
@@ -50,38 +65,13 @@ declare class ComputeHashIndexCache implements ComputeInterface {
|
|||||||
getHashIndexManager(): Promise<HashIndexManager>;
|
getHashIndexManager(): Promise<HashIndexManager>;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare function existsAsync(filePath: string): Promise<boolean>;
|
declare class HashComputerWorker implements ComputeInterface {
|
||||||
|
|
||||||
declare class FileIDComputer {
|
|
||||||
private piscina;
|
|
||||||
constructor(workerPath?: string);
|
|
||||||
/**
|
|
||||||
* Compute the CIDs of a file using specific algorithms
|
|
||||||
* @param filePath The path to the file
|
|
||||||
* @param algorithms Array of algorithms ('sha256', 'sha1')
|
|
||||||
* @returns Array of CIDs (in the order of the algorithms)
|
|
||||||
*/
|
|
||||||
computeCIDs(filePath: string, algorithms: CID_ALGORITHM_NAMES[]): Promise<string[]>;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare class HashComputer implements ComputeInterface {
|
|
||||||
private targetHash;
|
private targetHash;
|
||||||
private fileIDComputer;
|
private fileIDComputer;
|
||||||
constructor(targetHash: CID_ALGORITHM_NAMES[], workerPath?: string);
|
constructor(targetHash: CID_ALGORITHM_NAMES[], workerPath?: string);
|
||||||
computeMissingHash(filePath: string, metadata: MultiHashData): Promise<void>;
|
computeMissingHash(filePath: string, metadata: MultiHashData): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Properties {
|
|
||||||
TARGET_HASHES: string;
|
|
||||||
INDEX_FILE_PATH: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface FileProcessorInterface {
|
|
||||||
processFile(current: number, queueSize: number, nfoFilePath: string): Promise<void>;
|
|
||||||
canProcessFile(filePath: string): Promise<boolean>;
|
|
||||||
deleteFile(filePath: string): Promise<void>;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare class FolderWatcher {
|
declare class FolderWatcher {
|
||||||
private WATCH_FOLDER_LIST;
|
private WATCH_FOLDER_LIST;
|
||||||
private config;
|
private config;
|
||||||
@@ -115,4 +105,4 @@ declare class FolderWatcher {
|
|||||||
watch(): Promise<void>;
|
watch(): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { CID_ALGORITHM_NAMES, ComputeHashIndexCache, ComputeInterface, FileIDComputer, type FileProcessorInterface, FolderWatcher, HashComputer, HashIndexManager, INDEX_HEADERS, MultiHashData, type Properties, existsAsync };
|
export { CID_ALGORITHM_NAMES, ComputeInterface, FileIDComputerWorker, FileProcessorInterface, FolderWatcher, HashComputerIndexCache, HashComputerWorker, HashIndexManager, INDEX_HEADERS, MultiHashData };
|
||||||
|
|||||||
Vendored
+7
-4
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+4
-2
@@ -1,9 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var chunkASEKTFOG_cjs = require('./chunk-ASEKTFOG.cjs');
|
var chunkKZVIGNTH_cjs = require('./chunk-KZVIGNTH.cjs');
|
||||||
|
require('./chunk-33LRP2HS.cjs');
|
||||||
|
require('./chunk-PAKJNZBJ.cjs');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = chunkASEKTFOG_cjs.d;
|
module.exports = chunkKZVIGNTH_cjs.a;
|
||||||
//# sourceMappingURL=out.js.map
|
//# sourceMappingURL=out.js.map
|
||||||
//# sourceMappingURL=worker.cjs.map
|
//# sourceMappingURL=worker.cjs.map
|
||||||
Vendored
+14
-1
@@ -1 +1,14 @@
|
|||||||
export { S as SimpleHash, d as default } from './ShaComputeWorker-CNdGUbtT.cjs';
|
import { C as CID_ALGORITHM_NAMES } from './MultiHashData-B-scpa5G.cjs';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the CIDs of a file using specific algorithms
|
||||||
|
* @param filePath The path to the file
|
||||||
|
* @param algorithms Array of algorithms ('sha256', 'sha1')
|
||||||
|
* @returns Array of CIDs (in the order of the algorithms)
|
||||||
|
*/
|
||||||
|
declare function computeCIDs({ filePath, algorithms }: {
|
||||||
|
filePath: string;
|
||||||
|
algorithms: CID_ALGORITHM_NAMES[];
|
||||||
|
}): Promise<string[]>;
|
||||||
|
|
||||||
|
export { computeCIDs as default };
|
||||||
|
|||||||
Vendored
+14
-1
@@ -1 +1,14 @@
|
|||||||
export { S as SimpleHash, d as default } from './ShaComputeWorker-CNdGUbtT.js';
|
import { C as CID_ALGORITHM_NAMES } from './MultiHashData-B-scpa5G.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the CIDs of a file using specific algorithms
|
||||||
|
* @param filePath The path to the file
|
||||||
|
* @param algorithms Array of algorithms ('sha256', 'sha1')
|
||||||
|
* @returns Array of CIDs (in the order of the algorithms)
|
||||||
|
*/
|
||||||
|
declare function computeCIDs({ filePath, algorithms }: {
|
||||||
|
filePath: string;
|
||||||
|
algorithms: CID_ALGORITHM_NAMES[];
|
||||||
|
}): Promise<string[]>;
|
||||||
|
|
||||||
|
export { computeCIDs as default };
|
||||||
|
|||||||
Vendored
+3
-1
@@ -1,3 +1,5 @@
|
|||||||
export { d as default } from './chunk-4EZ47WAR.js';
|
export { a as default } from './chunk-6UBSWOQL.js';
|
||||||
|
import './chunk-A6J5HDTV.js';
|
||||||
|
import './chunk-YCFZVUZC.js';
|
||||||
//# sourceMappingURL=out.js.map
|
//# sourceMappingURL=out.js.map
|
||||||
//# sourceMappingURL=worker.js.map
|
//# sourceMappingURL=worker.js.map
|
||||||
+8
-4
@@ -21,13 +21,17 @@
|
|||||||
"import": "./dist/index.js",
|
"import": "./dist/index.js",
|
||||||
"require": "./dist/index.cjs"
|
"require": "./dist/index.cjs"
|
||||||
},
|
},
|
||||||
"./index.async": {
|
"./index-interface": {
|
||||||
"import": "./dist/index.async.js",
|
"import": "./dist/index-interface.js",
|
||||||
"require": "./dist/index.async.cjs"
|
"require": "./dist/index-interface.cjs"
|
||||||
|
},
|
||||||
|
"./index-browser": {
|
||||||
|
"import": "./dist/index-browser.js",
|
||||||
|
"require": "./dist/index-browser.cjs"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "cross-env rimraf dist & tsup",
|
"build": "cross-env rimraf ./dist & tsup",
|
||||||
"ci": "yarn run coverage",
|
"ci": "yarn run coverage",
|
||||||
"test": "vitest"
|
"test": "vitest"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
|
|
||||||
export interface Properties{
|
|
||||||
TARGET_HASHES:string;
|
|
||||||
INDEX_FILE_PATH:string;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import {CID_ALGORITHM_CODES, CID_ALGORITHM_NAMES} from "../hash-compute/MultiHashData";
|
||||||
|
import {Readable} from "stream";
|
||||||
|
import {create} from "multiformats/hashes/digest";
|
||||||
|
import {CID} from 'multiformats/cid';
|
||||||
|
import {createHasher, codeTable} from "./CreateHasher";
|
||||||
|
import {SimpleHash} from "./SimpleHash";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the CIDs of a file using specific algorithms
|
||||||
|
* @param stream The Readable stream of the file
|
||||||
|
* @param algorithms Array of algorithms ('sha256', 'sha1', etc.)
|
||||||
|
* @returns Array of CIDs (in the order of the algorithms)
|
||||||
|
*/
|
||||||
|
export async function computeCIDs({stream, algorithms}: {
|
||||||
|
stream: Readable | ReadableStream;
|
||||||
|
algorithms: CID_ALGORITHM_NAMES[]
|
||||||
|
}): Promise<string[]> {
|
||||||
|
const hashers = hasherDefiner(algorithms);
|
||||||
|
|
||||||
|
// Check if the environment is Node.js or Browser and handle the stream accordingly
|
||||||
|
if (stream instanceof Readable) {
|
||||||
|
// Node.js environment
|
||||||
|
for await (const chunk of stream) {
|
||||||
|
hashers.forEach(item => item.hasher.update(chunk as Buffer));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Browser environment
|
||||||
|
const reader = stream.getReader();
|
||||||
|
while (true) {
|
||||||
|
const {done, value} = await reader.read();
|
||||||
|
if (done) break;
|
||||||
|
// Assuming the hasher can handle Uint8Array directly
|
||||||
|
hashers.forEach(item => item.hasher.update(Buffer.from(value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cidFinalize(hashers);
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasherDefiner(algorithms: CID_ALGORITHM_NAMES[]): {
|
||||||
|
hasher: SimpleHash,
|
||||||
|
code: CID_ALGORITHM_CODES
|
||||||
|
}[] {
|
||||||
|
const hashers = algorithms.filter(algo => Object.values(CID_ALGORITHM_NAMES).includes(algo))
|
||||||
|
.map(algo => ({
|
||||||
|
hasher: createHasher(algo),
|
||||||
|
code: codeTable[algo]
|
||||||
|
}));
|
||||||
|
return hashers;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function cidFinalize(hashers: { hasher: SimpleHash, code: number }[]): Promise<string[]> {
|
||||||
|
return await Promise.all(hashers.map(async ({code, hasher}) => {
|
||||||
|
const hashBuffer = hasher.digest();
|
||||||
|
const digest = create(code, hashBuffer);
|
||||||
|
return CID.createV1(code, digest).toString();
|
||||||
|
}));
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import crc32 from "crc-32";
|
||||||
|
import {SimpleHash} from "@root/file-id/SimpleHash";
|
||||||
|
|
||||||
|
export class Crc32Hash implements SimpleHash {
|
||||||
|
private _crc: number = undefined;
|
||||||
|
|
||||||
|
update(data: Buffer): Crc32Hash {
|
||||||
|
// Update the CRC-32 checksum with the new chunk of data
|
||||||
|
this._crc = crc32.buf(data, this._crc);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
digest(): Buffer {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import {CID_ALGORITHM_CODES, CID_ALGORITHM_NAMES} from "../hash-compute/MultiHashData";
|
||||||
|
import {Readable} from "stream";
|
||||||
|
import {ReadableStream} from "stream/web";
|
||||||
|
import {SimpleHash} from "./SimpleHash";
|
||||||
|
import {createHash} from "crypto";
|
||||||
|
import {Crc32Hash} from "./Crc32Hash";
|
||||||
|
|
||||||
|
export const codeTable = {
|
||||||
|
[CID_ALGORITHM_NAMES.crc32]: CID_ALGORITHM_CODES.crc32,
|
||||||
|
[CID_ALGORITHM_NAMES.md5]: CID_ALGORITHM_CODES.md5,
|
||||||
|
[CID_ALGORITHM_NAMES.sha1]: CID_ALGORITHM_CODES.sha1,
|
||||||
|
[CID_ALGORITHM_NAMES.sha256]: CID_ALGORITHM_CODES.sha256,
|
||||||
|
[CID_ALGORITHM_NAMES.sha3_256]: CID_ALGORITHM_CODES.sha3_256,
|
||||||
|
[CID_ALGORITHM_NAMES.sha3_384]: CID_ALGORITHM_CODES.sha3_384
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the CIDs of a file using specific algorithms
|
||||||
|
* @returns Array of CIDs (in the order of the algorithms)
|
||||||
|
* @param algo
|
||||||
|
*/
|
||||||
|
export function createHasher(algo: CID_ALGORITHM_NAMES): SimpleHash {
|
||||||
|
switch (algo) {
|
||||||
|
case CID_ALGORITHM_NAMES.sha256:
|
||||||
|
return createHash("sha256");
|
||||||
|
case CID_ALGORITHM_NAMES.sha1:
|
||||||
|
return createHash("sha1");
|
||||||
|
case CID_ALGORITHM_NAMES.md5:
|
||||||
|
return createHash("md5");
|
||||||
|
case CID_ALGORITHM_NAMES.sha3_256:
|
||||||
|
return createHash("sha3-256");
|
||||||
|
case CID_ALGORITHM_NAMES.sha3_384:
|
||||||
|
return createHash("sha3-384");
|
||||||
|
case CID_ALGORITHM_NAMES.crc32:
|
||||||
|
return new Crc32Hash();
|
||||||
|
default:
|
||||||
|
throw new Error(`Unsupported algorithm: ${algo}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import {CID_ALGORITHM_NAMES} from "@root/hash-compute/MultiHashData";
|
||||||
|
import * as Stream from "stream";
|
||||||
|
|
||||||
|
export interface FileIDComputerInterface{
|
||||||
|
computeCIDs(filePath: Stream, algorithms: CID_ALGORITHM_NAMES[]): Promise<string[]>;
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import {Piscina} from "piscina";
|
import {Piscina} from "piscina";
|
||||||
import {CID_ALGORITHM_NAMES} from "../MultiHashData";
|
import {CID_ALGORITHM_NAMES} from "../hash-compute/MultiHashData";
|
||||||
|
import {FileIDComputerInterface} from "@root/file-id/FileIDComputerInterface";
|
||||||
|
|
||||||
// Construct the URL for the current module
|
// Construct the URL for the current module
|
||||||
let distFolder = import.meta.dirname;
|
let distFolder = import.meta.dirname;
|
||||||
@@ -8,7 +9,7 @@ distFolder = distFolder + "/worker.js";
|
|||||||
const workerUrl = new URL(distFolder).href;
|
const workerUrl = new URL(distFolder).href;
|
||||||
console.log("Worker URL: ", workerUrl);
|
console.log("Worker URL: ", workerUrl);
|
||||||
|
|
||||||
export class FileIDComputer {
|
export class FileIDComputerWorker{
|
||||||
private piscina: Piscina;
|
private piscina: Piscina;
|
||||||
|
|
||||||
constructor(workerPath?:string) {
|
constructor(workerPath?:string) {
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import {CID_ALGORITHM_NAMES} from "@root/hash-compute/MultiHashData";
|
||||||
|
import fs from "fs";
|
||||||
|
import {computeCIDs as computeCIDsInternal} from "./ComputeHash";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the CIDs of a file using specific algorithms
|
||||||
|
* @param filePath The path to the file
|
||||||
|
* @param algorithms Array of algorithms ('sha256', 'sha1')
|
||||||
|
* @returns Array of CIDs (in the order of the algorithms)
|
||||||
|
*/
|
||||||
|
export default async function computeCIDs({filePath, algorithms}: {
|
||||||
|
filePath: string;
|
||||||
|
algorithms: CID_ALGORITHM_NAMES[]
|
||||||
|
}): Promise<string[]> {
|
||||||
|
const stream = fs.createReadStream(filePath);
|
||||||
|
return computeCIDsInternal({stream, algorithms});
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
export interface SimpleHash {
|
||||||
|
update(data: Buffer),
|
||||||
|
|
||||||
|
digest(): Buffer;
|
||||||
|
}
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
import {createReadStream} from "fs";
|
|
||||||
import {createHash} from 'crypto';
|
|
||||||
import {CID} from 'multiformats/cid';
|
|
||||||
import {create} from "multiformats/hashes/digest";
|
|
||||||
import crc32 from 'crc-32';
|
|
||||||
import {CID_ALGORITHM_CODES, CID_ALGORITHM_NAMES} from "../MultiHashData";
|
|
||||||
|
|
||||||
export interface SimpleHash {
|
|
||||||
update(data: Buffer),
|
|
||||||
|
|
||||||
digest(): Buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Crc32Hash implements SimpleHash {
|
|
||||||
private _crc: number = undefined;
|
|
||||||
|
|
||||||
update(data: Buffer): Crc32Hash {
|
|
||||||
// Update the CRC-32 checksum with the new chunk of data
|
|
||||||
this._crc = crc32.buf(data, this._crc);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
digest(): Buffer {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compute the CIDs of a file using specific algorithms
|
|
||||||
* @param filePath The path to the file
|
|
||||||
* @param algorithms Array of algorithms ('sha256', 'sha1')
|
|
||||||
* @returns Array of CIDs (in the order of the algorithms)
|
|
||||||
*/
|
|
||||||
export default async function computeCIDs({filePath, algorithms}: {
|
|
||||||
filePath: string;
|
|
||||||
algorithms: CID_ALGORITHM_NAMES[]
|
|
||||||
}): Promise<string[]> {
|
|
||||||
const hashFunctions: Record<string, { code: number, hasher: SimpleHash }>
|
|
||||||
= {
|
|
||||||
[CID_ALGORITHM_NAMES.sha256]: {code: CID_ALGORITHM_CODES.sha256, hasher: createHash('sha256')},
|
|
||||||
[CID_ALGORITHM_NAMES.sha1]: {code: CID_ALGORITHM_CODES.sha1, hasher: createHash('sha1')},
|
|
||||||
[CID_ALGORITHM_NAMES.md5]: {code: CID_ALGORITHM_CODES.md5, hasher: createHash('md5')},
|
|
||||||
[CID_ALGORITHM_NAMES.sha3_256]: {code: CID_ALGORITHM_CODES.sha3_256, hasher: createHash('sha3-256')},
|
|
||||||
[CID_ALGORITHM_NAMES.sha3_384]: {code: CID_ALGORITHM_CODES.sha3_384, hasher: createHash('sha3-384')},
|
|
||||||
[CID_ALGORITHM_NAMES.crc32]: {code: CID_ALGORITHM_CODES.crc32, hasher: new Crc32Hash()}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
const hashers = algorithms.map(algo => ({
|
|
||||||
hasher: hashFunctions[algo].hasher,
|
|
||||||
code: hashFunctions[algo].code
|
|
||||||
}));
|
|
||||||
|
|
||||||
const stream = createReadStream(filePath);
|
|
||||||
for await (const chunk of stream) {
|
|
||||||
for (const item of hashers) {
|
|
||||||
item.hasher.update(chunk as Buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const cids = await Promise.all(hashers.map(async ({code, hasher}) => {
|
|
||||||
const hashBuffer = hasher.digest();
|
|
||||||
const digest = create(code, hashBuffer);
|
|
||||||
return CID.createV1(code, digest).toString();
|
|
||||||
}));
|
|
||||||
|
|
||||||
return cids;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import {CID_ALGORITHM_NAMES, MultiHashData} from "./MultiHashData";
|
||||||
|
import {Readable} from "stream";
|
||||||
|
|
||||||
|
import {computeCIDs} from "@root/file-id/ComputeHash";
|
||||||
|
|
||||||
|
export class HashComputer{
|
||||||
|
|
||||||
|
constructor(private targetHash: CID_ALGORITHM_NAMES[]) {
|
||||||
|
}
|
||||||
|
|
||||||
|
async computeMissingHash(stream: Readable, metadata: MultiHashData): Promise<void> {
|
||||||
|
// Dynamically determine which hashes are needed
|
||||||
|
const neededHashes = this.targetHash.filter(hashName => !metadata[hashName]);
|
||||||
|
|
||||||
|
// If all hashes are already computed, skip the processing
|
||||||
|
if (neededHashes.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute only the needed CIDs
|
||||||
|
const cids = await computeCIDs({stream, algorithms:neededHashes});
|
||||||
|
|
||||||
|
// Map the computed CIDs back to their respective metadata properties
|
||||||
|
for (const [index, cid] of cids.entries()) {
|
||||||
|
const hashType = neededHashes[index];
|
||||||
|
metadata[hashType] = cid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
import {HashComputer} from "./HashComputer";
|
import {HashComputerWorker} from "./HashComputerWorker";
|
||||||
import {CID_ALGORITHM_NAMES, ComputeInterface, MultiHashData} from "./MultiHashData";
|
import {CID_ALGORITHM_NAMES, ComputeInterface, MultiHashData} from "./MultiHashData";
|
||||||
import {HashIndexManager} from "./HashIndexManager";
|
import {HashIndexManager} from "./HashIndexManager";
|
||||||
import {stat} from "fs/promises";
|
import {stat} from "fs/promises";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
export class ComputeHashIndexCache implements ComputeInterface {
|
export class HashComputerIndexCache implements ComputeInterface {
|
||||||
private hashIndexManager: HashIndexManager;
|
private hashIndexManager: HashIndexManager;
|
||||||
private hashComputer: HashComputer;
|
private hashComputer: HashComputerWorker;
|
||||||
|
|
||||||
constructor(indexFilePath: string,private targetHash: CID_ALGORITHM_NAMES[] = [CID_ALGORITHM_NAMES.sha1, CID_ALGORITHM_NAMES.sha256],workerPath?:string) {
|
constructor(indexFilePath: string,private targetHash: CID_ALGORITHM_NAMES[] = [CID_ALGORITHM_NAMES.sha1, CID_ALGORITHM_NAMES.sha256],workerPath?:string) {
|
||||||
this.hashComputer = new HashComputer(targetHash,workerPath);
|
this.hashComputer = new HashComputerWorker(targetHash,workerPath);
|
||||||
this.hashIndexManager = new HashIndexManager(indexFilePath,targetHash);
|
this.hashIndexManager = new HashIndexManager(indexFilePath,targetHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import {FileIDComputer} from "./fileID/FileIDComputer";
|
import {FileIDComputerWorker} from "../file-id/FileIDComputerWorker";
|
||||||
import {CID_ALGORITHM_NAMES, ComputeInterface, MultiHashData} from "./MultiHashData";
|
import {CID_ALGORITHM_NAMES, ComputeInterface, MultiHashData} from "./MultiHashData";
|
||||||
|
|
||||||
export class HashComputer implements ComputeInterface {
|
export class HashComputerWorker implements ComputeInterface {
|
||||||
private fileIDComputer: FileIDComputer;
|
private fileIDComputer: FileIDComputerWorker;
|
||||||
|
|
||||||
constructor(private targetHash: CID_ALGORITHM_NAMES[], workerPath?: string) {
|
constructor(private targetHash: CID_ALGORITHM_NAMES[], workerPath?: string) {
|
||||||
this.fileIDComputer = new FileIDComputer(workerPath);
|
this.fileIDComputer = new FileIDComputerWorker(workerPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
async computeMissingHash(filePath: string, metadata: MultiHashData): Promise<void> {
|
async computeMissingHash(filePath: string, metadata: MultiHashData): Promise<void> {
|
||||||
@@ -2,7 +2,7 @@ import {createReadStream, promises as fs} from 'fs';
|
|||||||
import {parse} from 'csv-parse';
|
import {parse} from 'csv-parse';
|
||||||
import {parse as parseSync} from 'csv-parse/sync';
|
import {parse as parseSync} from 'csv-parse/sync';
|
||||||
import {stringify} from 'csv-stringify/sync';
|
import {stringify} from 'csv-stringify/sync';
|
||||||
import {existsAsync} from "./ExistsAsync";
|
import {existsAsync} from "../utils/ExistsAsync";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import {clearInterval} from "node:timers";
|
import {clearInterval} from "node:timers";
|
||||||
import {CID_ALGORITHM_NAMES} from "./MultiHashData";
|
import {CID_ALGORITHM_NAMES} from "./MultiHashData";
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
export * from './index-interface.js';
|
||||||
|
export * from './file-id/ComputeHash.js';
|
||||||
|
export * from './hash-compute/HashComputer.js';
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export * from './hash-compute/MultiHashData.js';
|
||||||
|
export * from './folder-watcher/FileProcessorInterface.js';
|
||||||
|
export * from './file-id/FileIDComputerInterface.js';
|
||||||
+12
-13
@@ -1,13 +1,12 @@
|
|||||||
// Import and export directly to simplify access to library components
|
//fileID
|
||||||
export * from './ComputeHashIndexCache.js';
|
export * from './file-id/FileIDComputerWorker.js';
|
||||||
export * from './ExistsAsync.js'; // Assuming 'async' is a function; adjust as necessary
|
export * from './file-id/ShaComputeWorker.js';//worker
|
||||||
export * from './fileID/FileIDComputer.js';
|
|
||||||
export * from './fileID/ShaComputeWorker.js'; // Assuming this exports a class or main function; adjust as needed
|
//hash-compute
|
||||||
export * from './HashComputer.js';
|
export * from './hash-compute/HashComputerIndexCache.js';
|
||||||
export * from './HashIndexManager.js';
|
export * from './hash-compute/HashComputerWorker.js';
|
||||||
// For MultiHashData.ts, assuming interfaces and enums need to be exported; you might need to adjust based on actual content
|
export * from './hash-compute/HashIndexManager.js';
|
||||||
export * from './MultiHashData.js';
|
|
||||||
// Assuming Properties.ts exports one or more interfaces; adjust as needed
|
//folder-watcher
|
||||||
export * from './Properties.js';
|
export * from './folder-watcher/FolderWatcher.js';
|
||||||
export * from './folder_watcher/FolderWatcher.js';
|
export * from './index-interface.js';
|
||||||
export * from './folder_watcher/FileProcessorInterface.js';
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import {CID_ALGORITHM_NAMES, ComputeHashIndexCache, HashComputer} from "../lib";
|
import {CID_ALGORITHM_NAMES, HashComputerIndexCache, HashComputerWorker} from "../lib";
|
||||||
|
|
||||||
import {describe, expect, it} from 'vitest';
|
import {describe, expect, it} from 'vitest';
|
||||||
import * as process from "process";
|
import * as process from "process";
|
||||||
@@ -13,7 +13,7 @@ process.env.WORKER_URL = "./dist/worker.js";
|
|||||||
|
|
||||||
describe('add', () => {
|
describe('add', () => {
|
||||||
it('meta data compute', async () => {
|
it('meta data compute', async () => {
|
||||||
let hashComputer = new HashComputer([
|
let hashComputer = new HashComputerWorker([
|
||||||
CID_ALGORITHM_NAMES.sha1,
|
CID_ALGORITHM_NAMES.sha1,
|
||||||
CID_ALGORITHM_NAMES.sha256,
|
CID_ALGORITHM_NAMES.sha256,
|
||||||
CID_ALGORITHM_NAMES.md5,
|
CID_ALGORITHM_NAMES.md5,
|
||||||
@@ -43,7 +43,7 @@ describe('add', () => {
|
|||||||
it('meta data compute with index', async () => {
|
it('meta data compute with index', async () => {
|
||||||
await rm("./tmp",{recursive:true});
|
await rm("./tmp",{recursive:true});
|
||||||
await mkdir("./tmp",{recursive:true});
|
await mkdir("./tmp",{recursive:true});
|
||||||
let hashComputer = new ComputeHashIndexCache("./tmp/index.csv",[
|
let hashComputer = new HashComputerIndexCache("./tmp/index.csv",[
|
||||||
CID_ALGORITHM_NAMES.sha1,
|
CID_ALGORITHM_NAMES.sha1,
|
||||||
CID_ALGORITHM_NAMES.sha256,
|
CID_ALGORITHM_NAMES.sha256,
|
||||||
CID_ALGORITHM_NAMES.md5,
|
CID_ALGORITHM_NAMES.md5,
|
||||||
@@ -73,7 +73,7 @@ describe('add', () => {
|
|||||||
});
|
});
|
||||||
it('cache', async () => {
|
it('cache', async () => {
|
||||||
await mkdir("./tmp",{recursive:true});
|
await mkdir("./tmp",{recursive:true});
|
||||||
let hashComputer = new ComputeHashIndexCache("./tmp/index.csv",[
|
let hashComputer = new HashComputerIndexCache("./tmp/index.csv",[
|
||||||
CID_ALGORITHM_NAMES.sha1,
|
CID_ALGORITHM_NAMES.sha1,
|
||||||
CID_ALGORITHM_NAMES.sha256,
|
CID_ALGORITHM_NAMES.sha256,
|
||||||
CID_ALGORITHM_NAMES.md5,
|
CID_ALGORITHM_NAMES.md5,
|
||||||
|
|||||||
+3
-1
@@ -3,7 +3,9 @@ import {defineConfig} from 'tsup'
|
|||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
entry: {
|
entry: {
|
||||||
'index': 'src/lib/index.ts',
|
'index': 'src/lib/index.ts',
|
||||||
'worker': 'src/lib/fileID/ShaComputeWorker.ts',
|
'index-interface': 'src/lib/index-interface.ts',
|
||||||
|
'index-browser': 'src/lib/index-browser.ts',
|
||||||
|
'worker': 'src/lib/file-id/ShaComputeWorker.ts',
|
||||||
},
|
},
|
||||||
splitting: true,
|
splitting: true,
|
||||||
treeshake: true,
|
treeshake: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user