hash improvement
This commit is contained in:
Vendored
-18
@@ -1,18 +0,0 @@
|
||||
'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
-8
@@ -1,8 +0,0 @@
|
||||
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
@@ -1 +0,0 @@
|
||||
{"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
@@ -1,12 +0,0 @@
|
||||
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
+32
@@ -0,0 +1,32 @@
|
||||
// src/lib/hash-compute/MultiHashData.ts
|
||||
var CID_ALGORITHM_CODES = /* @__PURE__ */ ((CID_ALGORITHM_CODES2) => {
|
||||
CID_ALGORITHM_CODES2[CID_ALGORITHM_CODES2["crc32"] = 306] = "crc32";
|
||||
CID_ALGORITHM_CODES2[CID_ALGORITHM_CODES2["md5"] = 213] = "md5";
|
||||
CID_ALGORITHM_CODES2[CID_ALGORITHM_CODES2["sha1"] = 17] = "sha1";
|
||||
CID_ALGORITHM_CODES2[CID_ALGORITHM_CODES2["sha256"] = 18] = "sha256";
|
||||
CID_ALGORITHM_CODES2[CID_ALGORITHM_CODES2["sha3_256"] = 22] = "sha3_256";
|
||||
CID_ALGORITHM_CODES2[CID_ALGORITHM_CODES2["sha3_384"] = 21] = "sha3_384";
|
||||
return CID_ALGORITHM_CODES2;
|
||||
})(CID_ALGORITHM_CODES || {});
|
||||
var CID_ALGORITHM_NAMES = /* @__PURE__ */ ((CID_ALGORITHM_NAMES2) => {
|
||||
CID_ALGORITHM_NAMES2["crc32"] = "cid_crc32";
|
||||
CID_ALGORITHM_NAMES2["md5"] = "cid_md5";
|
||||
CID_ALGORITHM_NAMES2["sha1"] = "cid_sha1";
|
||||
CID_ALGORITHM_NAMES2["sha256"] = "cid_sha2-256";
|
||||
CID_ALGORITHM_NAMES2["sha3_256"] = "cid_sha3-256";
|
||||
CID_ALGORITHM_NAMES2["sha3_384"] = "cid_sha3-384";
|
||||
return CID_ALGORITHM_NAMES2;
|
||||
})(CID_ALGORITHM_NAMES || {});
|
||||
var CID_ALGORITHM = /* @__PURE__ */ ((CID_ALGORITHM2) => {
|
||||
CID_ALGORITHM2["crc32"] = "crc32";
|
||||
CID_ALGORITHM2["md5"] = "md5";
|
||||
CID_ALGORITHM2["sha1"] = "sha1";
|
||||
CID_ALGORITHM2["sha256"] = "sha2-256";
|
||||
CID_ALGORITHM2["sha3_256"] = "sha3-256";
|
||||
CID_ALGORITHM2["sha3_384"] = "sha3-384";
|
||||
return CID_ALGORITHM2;
|
||||
})(CID_ALGORITHM || {});
|
||||
|
||||
export { CID_ALGORITHM, CID_ALGORITHM_CODES, CID_ALGORITHM_NAMES };
|
||||
//# sourceMappingURL=out.js.map
|
||||
//# sourceMappingURL=chunk-HTZ763NS.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,IAAK,sBAAL,kBAAKA,yBAAL;AACH,EAAAA,0CAAA,WAAQ,OAAR;AACA,EAAAA,0CAAA,SAAM,OAAN;AACA,EAAAA,0CAAA,UAAO,MAAP;AACA,EAAAA,0CAAA,YAAS,MAAT;AACA,EAAAA,0CAAA,cAAW,MAAX;AACA,EAAAA,0CAAA,cAAW,MAAX;AANQ,SAAAA;AAAA,GAAA;AASL,IAAK,sBAAL,kBAAKC,yBAAL;AACH,EAAAA,qBAAA,WAAQ;AACR,EAAAA,qBAAA,SAAM;AACN,EAAAA,qBAAA,UAAO;AACP,EAAAA,qBAAA,YAAS;AACT,EAAAA,qBAAA,cAAW;AACX,EAAAA,qBAAA,cAAW;AANH,SAAAA;AAAA,GAAA;AASL,IAAK,gBAAL,kBAAKC,mBAAL;AACH,EAAAA,eAAA,WAAQ;AACR,EAAAA,eAAA,SAAM;AACN,EAAAA,eAAA,UAAO;AACP,EAAAA,eAAA,YAAS;AACT,EAAAA,eAAA,cAAW;AACX,EAAAA,eAAA,cAAW;AANH,SAAAA;AAAA,GAAA","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
-14
@@ -1,14 +0,0 @@
|
||||
'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
@@ -1 +0,0 @@
|
||||
{"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
+11
@@ -0,0 +1,11 @@
|
||||
import { computeCIDs } from './chunk-SV45D2HN.js';
|
||||
import fs from 'fs';
|
||||
|
||||
async function computeCIDs2({ filePath, algorithms }) {
|
||||
const stream = fs.createReadStream(filePath);
|
||||
return computeCIDs({ stream, algorithms });
|
||||
}
|
||||
|
||||
export { computeCIDs2 as computeCIDs };
|
||||
//# sourceMappingURL=out.js.map
|
||||
//# sourceMappingURL=chunk-LTWPBXM5.js.map
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/lib/file-id/ShaComputeWorker.ts"],"names":["computeCIDs"],"mappings":";;;;;AACA,OAAO,QAAQ;AASf,eAAOA,aAAmC,EAAC,UAAU,WAAU,GAGzC;AAClB,QAAM,SAAS,GAAG,iBAAiB,QAAQ;AAC3C,SAAO,YAAoB,EAAC,QAAQ,WAAU,CAAC;AACnD","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
+94
@@ -0,0 +1,94 @@
|
||||
'use strict';
|
||||
|
||||
var chunkS7BSPELE_cjs = require('./chunk-S7BSPELE.cjs');
|
||||
var stream = require('stream');
|
||||
var digest = require('multiformats/hashes/digest');
|
||||
var cid = require('multiformats/cid');
|
||||
var crypto = require('crypto');
|
||||
var crc32 = require('crc-32');
|
||||
|
||||
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
||||
|
||||
var crc32__default = /*#__PURE__*/_interopDefault(crc32);
|
||||
|
||||
var Crc32Hash = class {
|
||||
_crc = void 0;
|
||||
update(data) {
|
||||
this._crc = crc32__default.default.buf(data, this._crc);
|
||||
return this;
|
||||
}
|
||||
digest() {
|
||||
const buffer = Buffer.alloc(4);
|
||||
buffer.writeInt32BE(this._crc, 0);
|
||||
return buffer;
|
||||
}
|
||||
};
|
||||
|
||||
// src/lib/file-id/CreateHasher.ts
|
||||
var codeTable = {
|
||||
["cid_crc32" /* crc32 */]: 306 /* crc32 */,
|
||||
["cid_md5" /* md5 */]: 213 /* md5 */,
|
||||
["cid_sha1" /* sha1 */]: 17 /* sha1 */,
|
||||
["cid_sha2-256" /* sha256 */]: 18 /* sha256 */,
|
||||
["cid_sha3-256" /* sha3_256 */]: 22 /* sha3_256 */,
|
||||
["cid_sha3-384" /* sha3_384 */]: 21 /* sha3_384 */
|
||||
};
|
||||
async function createHasher(algo) {
|
||||
switch (algo) {
|
||||
case "cid_sha2-256" /* sha256 */:
|
||||
return crypto.createHash("sha256");
|
||||
case "cid_sha1" /* sha1 */:
|
||||
return crypto.createHash("sha1");
|
||||
case "cid_md5" /* md5 */:
|
||||
return crypto.createHash("md5");
|
||||
case "cid_sha3-256" /* sha3_256 */:
|
||||
return crypto.createHash("sha3-256");
|
||||
case "cid_sha3-384" /* sha3_384 */:
|
||||
return crypto.createHash("sha3-384");
|
||||
case "cid_crc32" /* crc32 */:
|
||||
return new Crc32Hash();
|
||||
default:
|
||||
throw new Error(`Unsupported algorithm: ${algo}`);
|
||||
}
|
||||
}
|
||||
|
||||
// src/lib/file-id/ComputeHash.ts
|
||||
async function computeCIDs({ stream: stream$1, algorithms }) {
|
||||
const hashers = await hasherDefiner(algorithms);
|
||||
if (stream$1 instanceof stream.Readable) {
|
||||
for await (const chunk of stream$1) {
|
||||
for (const item of hashers) {
|
||||
await item.hasher.update(chunk);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const reader = stream$1.getReader();
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done)
|
||||
break;
|
||||
for (const item of hashers) {
|
||||
await item.hasher.update(Buffer.from(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
return cidFinalize(hashers);
|
||||
}
|
||||
async function hasherDefiner(algorithms) {
|
||||
const hashers = algorithms.filter((algo) => Object.values(chunkS7BSPELE_cjs.CID_ALGORITHM_NAMES).includes(algo)).map(async (algo) => ({
|
||||
hasher: await createHasher(algo),
|
||||
code: codeTable[algo]
|
||||
}));
|
||||
return await Promise.all(hashers);
|
||||
}
|
||||
async function cidFinalize(hashers) {
|
||||
return await Promise.all(hashers.map(async ({ code, hasher }) => {
|
||||
const hashBuffer = await hasher.digest();
|
||||
const digest$1 = digest.create(code, hashBuffer);
|
||||
return cid.CID.createV1(code, digest$1).toString();
|
||||
}));
|
||||
}
|
||||
|
||||
exports.computeCIDs = computeCIDs;
|
||||
//# sourceMappingURL=out.js.map
|
||||
//# sourceMappingURL=chunk-OHUFSPVO.cjs.map
|
||||
Vendored
+1
File diff suppressed because one or more lines are too long
Vendored
-9
@@ -1,9 +0,0 @@
|
||||
'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
@@ -1 +0,0 @@
|
||||
{"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
+36
@@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
// src/lib/hash-compute/MultiHashData.ts
|
||||
var CID_ALGORITHM_CODES = /* @__PURE__ */ ((CID_ALGORITHM_CODES2) => {
|
||||
CID_ALGORITHM_CODES2[CID_ALGORITHM_CODES2["crc32"] = 306] = "crc32";
|
||||
CID_ALGORITHM_CODES2[CID_ALGORITHM_CODES2["md5"] = 213] = "md5";
|
||||
CID_ALGORITHM_CODES2[CID_ALGORITHM_CODES2["sha1"] = 17] = "sha1";
|
||||
CID_ALGORITHM_CODES2[CID_ALGORITHM_CODES2["sha256"] = 18] = "sha256";
|
||||
CID_ALGORITHM_CODES2[CID_ALGORITHM_CODES2["sha3_256"] = 22] = "sha3_256";
|
||||
CID_ALGORITHM_CODES2[CID_ALGORITHM_CODES2["sha3_384"] = 21] = "sha3_384";
|
||||
return CID_ALGORITHM_CODES2;
|
||||
})(CID_ALGORITHM_CODES || {});
|
||||
var CID_ALGORITHM_NAMES = /* @__PURE__ */ ((CID_ALGORITHM_NAMES2) => {
|
||||
CID_ALGORITHM_NAMES2["crc32"] = "cid_crc32";
|
||||
CID_ALGORITHM_NAMES2["md5"] = "cid_md5";
|
||||
CID_ALGORITHM_NAMES2["sha1"] = "cid_sha1";
|
||||
CID_ALGORITHM_NAMES2["sha256"] = "cid_sha2-256";
|
||||
CID_ALGORITHM_NAMES2["sha3_256"] = "cid_sha3-256";
|
||||
CID_ALGORITHM_NAMES2["sha3_384"] = "cid_sha3-384";
|
||||
return CID_ALGORITHM_NAMES2;
|
||||
})(CID_ALGORITHM_NAMES || {});
|
||||
var CID_ALGORITHM = /* @__PURE__ */ ((CID_ALGORITHM2) => {
|
||||
CID_ALGORITHM2["crc32"] = "crc32";
|
||||
CID_ALGORITHM2["md5"] = "md5";
|
||||
CID_ALGORITHM2["sha1"] = "sha1";
|
||||
CID_ALGORITHM2["sha256"] = "sha2-256";
|
||||
CID_ALGORITHM2["sha3_256"] = "sha3-256";
|
||||
CID_ALGORITHM2["sha3_384"] = "sha3-384";
|
||||
return CID_ALGORITHM2;
|
||||
})(CID_ALGORITHM || {});
|
||||
|
||||
exports.CID_ALGORITHM = CID_ALGORITHM;
|
||||
exports.CID_ALGORITHM_CODES = CID_ALGORITHM_CODES;
|
||||
exports.CID_ALGORITHM_NAMES = CID_ALGORITHM_NAMES;
|
||||
//# sourceMappingURL=out.js.map
|
||||
//# sourceMappingURL=chunk-S7BSPELE.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,IAAK,sBAAL,kBAAKA,yBAAL;AACH,EAAAA,0CAAA,WAAQ,OAAR;AACA,EAAAA,0CAAA,SAAM,OAAN;AACA,EAAAA,0CAAA,UAAO,MAAP;AACA,EAAAA,0CAAA,YAAS,MAAT;AACA,EAAAA,0CAAA,cAAW,MAAX;AACA,EAAAA,0CAAA,cAAW,MAAX;AANQ,SAAAA;AAAA,GAAA;AASL,IAAK,sBAAL,kBAAKC,yBAAL;AACH,EAAAA,qBAAA,WAAQ;AACR,EAAAA,qBAAA,SAAM;AACN,EAAAA,qBAAA,UAAO;AACP,EAAAA,qBAAA,YAAS;AACT,EAAAA,qBAAA,cAAW;AACX,EAAAA,qBAAA,cAAW;AANH,SAAAA;AAAA,GAAA;AASL,IAAK,gBAAL,kBAAKC,mBAAL;AACH,EAAAA,eAAA,WAAQ;AACR,EAAAA,eAAA,SAAM;AACN,EAAAA,eAAA,UAAO;AACP,EAAAA,eAAA,YAAS;AACT,EAAAA,eAAA,cAAW;AACX,EAAAA,eAAA,cAAW;AANH,SAAAA;AAAA,GAAA","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
+88
@@ -0,0 +1,88 @@
|
||||
import { CID_ALGORITHM_NAMES } from './chunk-HTZ763NS.js';
|
||||
import { Readable } from 'stream';
|
||||
import { create } from 'multiformats/hashes/digest';
|
||||
import { CID } from 'multiformats/cid';
|
||||
import { createHash } from 'crypto';
|
||||
import crc32 from 'crc-32';
|
||||
|
||||
var Crc32Hash = class {
|
||||
_crc = void 0;
|
||||
update(data) {
|
||||
this._crc = crc32.buf(data, this._crc);
|
||||
return this;
|
||||
}
|
||||
digest() {
|
||||
const buffer = Buffer.alloc(4);
|
||||
buffer.writeInt32BE(this._crc, 0);
|
||||
return buffer;
|
||||
}
|
||||
};
|
||||
|
||||
// src/lib/file-id/CreateHasher.ts
|
||||
var codeTable = {
|
||||
["cid_crc32" /* crc32 */]: 306 /* crc32 */,
|
||||
["cid_md5" /* md5 */]: 213 /* md5 */,
|
||||
["cid_sha1" /* sha1 */]: 17 /* sha1 */,
|
||||
["cid_sha2-256" /* sha256 */]: 18 /* sha256 */,
|
||||
["cid_sha3-256" /* sha3_256 */]: 22 /* sha3_256 */,
|
||||
["cid_sha3-384" /* sha3_384 */]: 21 /* sha3_384 */
|
||||
};
|
||||
async function createHasher(algo) {
|
||||
switch (algo) {
|
||||
case "cid_sha2-256" /* sha256 */:
|
||||
return createHash("sha256");
|
||||
case "cid_sha1" /* sha1 */:
|
||||
return createHash("sha1");
|
||||
case "cid_md5" /* md5 */:
|
||||
return createHash("md5");
|
||||
case "cid_sha3-256" /* sha3_256 */:
|
||||
return createHash("sha3-256");
|
||||
case "cid_sha3-384" /* sha3_384 */:
|
||||
return createHash("sha3-384");
|
||||
case "cid_crc32" /* crc32 */:
|
||||
return new Crc32Hash();
|
||||
default:
|
||||
throw new Error(`Unsupported algorithm: ${algo}`);
|
||||
}
|
||||
}
|
||||
|
||||
// src/lib/file-id/ComputeHash.ts
|
||||
async function computeCIDs({ stream, algorithms }) {
|
||||
const hashers = await hasherDefiner(algorithms);
|
||||
if (stream instanceof Readable) {
|
||||
for await (const chunk of stream) {
|
||||
for (const item of hashers) {
|
||||
await item.hasher.update(chunk);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const reader = stream.getReader();
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done)
|
||||
break;
|
||||
for (const item of hashers) {
|
||||
await item.hasher.update(Buffer.from(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
return cidFinalize(hashers);
|
||||
}
|
||||
async function hasherDefiner(algorithms) {
|
||||
const hashers = algorithms.filter((algo) => Object.values(CID_ALGORITHM_NAMES).includes(algo)).map(async (algo) => ({
|
||||
hasher: await createHasher(algo),
|
||||
code: codeTable[algo]
|
||||
}));
|
||||
return await Promise.all(hashers);
|
||||
}
|
||||
async function cidFinalize(hashers) {
|
||||
return await Promise.all(hashers.map(async ({ code, hasher }) => {
|
||||
const hashBuffer = await hasher.digest();
|
||||
const digest = create(code, hashBuffer);
|
||||
return CID.createV1(code, digest).toString();
|
||||
}));
|
||||
}
|
||||
|
||||
export { computeCIDs };
|
||||
//# sourceMappingURL=out.js.map
|
||||
//# sourceMappingURL=chunk-SV45D2HN.js.map
|
||||
Vendored
+1
File diff suppressed because one or more lines are too long
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
var chunkOHUFSPVO_cjs = require('./chunk-OHUFSPVO.cjs');
|
||||
var fs = require('fs');
|
||||
|
||||
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
||||
|
||||
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
||||
|
||||
async function computeCIDs2({ filePath, algorithms }) {
|
||||
const stream = fs__default.default.createReadStream(filePath);
|
||||
return chunkOHUFSPVO_cjs.computeCIDs({ stream, algorithms });
|
||||
}
|
||||
|
||||
exports.computeCIDs = computeCIDs2;
|
||||
//# sourceMappingURL=out.js.map
|
||||
//# sourceMappingURL=chunk-Y5FIE5OK.cjs.map
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/lib/file-id/ShaComputeWorker.ts"],"names":["computeCIDs"],"mappings":";;;;;AACA,OAAO,QAAQ;AASf,eAAOA,aAAmC,EAAC,UAAU,WAAU,GAGzC;AAClB,QAAM,SAAS,GAAG,iBAAiB,QAAQ;AAC3C,SAAO,YAAoB,EAAC,QAAQ,WAAU,CAAC;AACnD","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
-5
@@ -1,5 +0,0 @@
|
||||
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
@@ -1 +0,0 @@
|
||||
{"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
+28
-12
@@ -1,27 +1,43 @@
|
||||
'use strict';
|
||||
|
||||
require('./chunk-KWYLOVWT.cjs');
|
||||
var chunk33LRP2HS_cjs = require('./chunk-33LRP2HS.cjs');
|
||||
var chunkPAKJNZBJ_cjs = require('./chunk-PAKJNZBJ.cjs');
|
||||
var chunkOHUFSPVO_cjs = require('./chunk-OHUFSPVO.cjs');
|
||||
var chunkS7BSPELE_cjs = require('./chunk-S7BSPELE.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;}}};
|
||||
// src/lib/hash-compute/HashComputer.ts
|
||||
var HashComputer = class {
|
||||
constructor(targetHash) {
|
||||
this.targetHash = targetHash;
|
||||
}
|
||||
async computeMissingHash(stream, metadata) {
|
||||
const neededHashes = this.targetHash.filter((hashName) => !metadata[hashName]);
|
||||
if (neededHashes.length === 0) {
|
||||
return;
|
||||
}
|
||||
const cids = await chunkOHUFSPVO_cjs.computeCIDs({ stream, algorithms: neededHashes });
|
||||
for (const [index, cid] of cids.entries()) {
|
||||
const hashType = neededHashes[index];
|
||||
metadata[hashType] = cid;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Object.defineProperty(exports, "computeCIDs", {
|
||||
enumerable: true,
|
||||
get: function () { return chunk33LRP2HS_cjs.a; }
|
||||
enumerable: true,
|
||||
get: function () { return chunkOHUFSPVO_cjs.computeCIDs; }
|
||||
});
|
||||
Object.defineProperty(exports, "CID_ALGORITHM", {
|
||||
enumerable: true,
|
||||
get: function () { return chunkPAKJNZBJ_cjs.c; }
|
||||
enumerable: true,
|
||||
get: function () { return chunkS7BSPELE_cjs.CID_ALGORITHM; }
|
||||
});
|
||||
Object.defineProperty(exports, "CID_ALGORITHM_CODES", {
|
||||
enumerable: true,
|
||||
get: function () { return chunkPAKJNZBJ_cjs.a; }
|
||||
enumerable: true,
|
||||
get: function () { return chunkS7BSPELE_cjs.CID_ALGORITHM_CODES; }
|
||||
});
|
||||
Object.defineProperty(exports, "CID_ALGORITHM_NAMES", {
|
||||
enumerable: true,
|
||||
get: function () { return chunkPAKJNZBJ_cjs.b; }
|
||||
enumerable: true,
|
||||
get: function () { return chunkS7BSPELE_cjs.CID_ALGORITHM_NAMES; }
|
||||
});
|
||||
exports.HashComputer = a;
|
||||
exports.HashComputer = HashComputer;
|
||||
//# sourceMappingURL=out.js.map
|
||||
//# sourceMappingURL=index-browser.cjs.map
|
||||
Vendored
+1
-1
@@ -1 +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"]}
|
||||
{"version":3,"sources":["../src/lib/hash-compute/HashComputer.ts"],"names":[],"mappings":";;;;;;;;;;;AAKO,IAAM,eAAN,MAAkB;AAAA,EAErB,YAAoB,YAAmC;AAAnC;AAAA,EACpB;AAAA,EAEA,MAAM,mBAAmB,QAAkB,UAAwC;AAE/E,UAAM,eAAe,KAAK,WAAW,OAAO,cAAY,CAAC,SAAS,QAAQ,CAAC;AAG3E,QAAI,aAAa,WAAW,GAAG;AAC3B;AAAA,IACJ;AAGA,UAAM,OAAO,MAAM,YAAY,EAAC,QAAQ,YAAW,aAAY,CAAC;AAGhE,eAAW,CAAC,OAAO,GAAG,KAAK,KAAK,QAAQ,GAAG;AACvC,YAAM,WAAW,aAAa,KAAK;AACnC,eAAS,QAAQ,IAAI;AAAA,IACzB;AAAA,EACJ;AACJ","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
-5
@@ -1,10 +1,26 @@
|
||||
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';
|
||||
import { computeCIDs } from './chunk-SV45D2HN.js';
|
||||
export { computeCIDs } from './chunk-SV45D2HN.js';
|
||||
export { CID_ALGORITHM, CID_ALGORITHM_CODES, CID_ALGORITHM_NAMES } from './chunk-HTZ763NS.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;}}};
|
||||
// src/lib/hash-compute/HashComputer.ts
|
||||
var HashComputer = class {
|
||||
constructor(targetHash) {
|
||||
this.targetHash = targetHash;
|
||||
}
|
||||
async computeMissingHash(stream, metadata) {
|
||||
const neededHashes = this.targetHash.filter((hashName) => !metadata[hashName]);
|
||||
if (neededHashes.length === 0) {
|
||||
return;
|
||||
}
|
||||
const cids = await computeCIDs({ stream, algorithms: neededHashes });
|
||||
for (const [index, cid] of cids.entries()) {
|
||||
const hashType = neededHashes[index];
|
||||
metadata[hashType] = cid;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export { a as HashComputer };
|
||||
export { HashComputer };
|
||||
//# sourceMappingURL=out.js.map
|
||||
//# sourceMappingURL=index-browser.js.map
|
||||
Vendored
+1
-1
@@ -1 +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"]}
|
||||
{"version":3,"sources":["../src/lib/hash-compute/HashComputer.ts"],"names":[],"mappings":";;;;;;;;;;;AAKO,IAAM,eAAN,MAAkB;AAAA,EAErB,YAAoB,YAAmC;AAAnC;AAAA,EACpB;AAAA,EAEA,MAAM,mBAAmB,QAAkB,UAAwC;AAE/E,UAAM,eAAe,KAAK,WAAW,OAAO,cAAY,CAAC,SAAS,QAAQ,CAAC;AAG3E,QAAI,aAAa,WAAW,GAAG;AAC3B;AAAA,IACJ;AAGA,UAAM,OAAO,MAAM,YAAY,EAAC,QAAQ,YAAW,aAAY,CAAC;AAGhE,eAAW,CAAC,OAAO,GAAG,KAAK,KAAK,QAAQ,GAAG;AACvC,YAAM,WAAW,aAAa,KAAK;AACnC,eAAS,QAAQ,IAAI;AAAA,IACzB;AAAA,EACJ;AACJ","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
+7
-7
@@ -1,21 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
require('./chunk-KWYLOVWT.cjs');
|
||||
var chunkPAKJNZBJ_cjs = require('./chunk-PAKJNZBJ.cjs');
|
||||
var chunkS7BSPELE_cjs = require('./chunk-S7BSPELE.cjs');
|
||||
|
||||
|
||||
|
||||
Object.defineProperty(exports, "CID_ALGORITHM", {
|
||||
enumerable: true,
|
||||
get: function () { return chunkPAKJNZBJ_cjs.c; }
|
||||
enumerable: true,
|
||||
get: function () { return chunkS7BSPELE_cjs.CID_ALGORITHM; }
|
||||
});
|
||||
Object.defineProperty(exports, "CID_ALGORITHM_CODES", {
|
||||
enumerable: true,
|
||||
get: function () { return chunkPAKJNZBJ_cjs.a; }
|
||||
enumerable: true,
|
||||
get: function () { return chunkS7BSPELE_cjs.CID_ALGORITHM_CODES; }
|
||||
});
|
||||
Object.defineProperty(exports, "CID_ALGORITHM_NAMES", {
|
||||
enumerable: true,
|
||||
get: function () { return chunkPAKJNZBJ_cjs.b; }
|
||||
enumerable: true,
|
||||
get: function () { return chunkS7BSPELE_cjs.CID_ALGORITHM_NAMES; }
|
||||
});
|
||||
//# sourceMappingURL=out.js.map
|
||||
//# sourceMappingURL=index-interface.cjs.map
|
||||
Vendored
+1
-1
@@ -1,4 +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';
|
||||
export { CID_ALGORITHM, CID_ALGORITHM_CODES, CID_ALGORITHM_NAMES } from './chunk-HTZ763NS.js';
|
||||
//# sourceMappingURL=out.js.map
|
||||
//# sourceMappingURL=index-interface.js.map
|
||||
Vendored
+470
-37
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
+442
-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
+4
-4
@@ -1,11 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
var chunkKZVIGNTH_cjs = require('./chunk-KZVIGNTH.cjs');
|
||||
require('./chunk-33LRP2HS.cjs');
|
||||
require('./chunk-PAKJNZBJ.cjs');
|
||||
var chunkY5FIE5OK_cjs = require('./chunk-Y5FIE5OK.cjs');
|
||||
require('./chunk-OHUFSPVO.cjs');
|
||||
require('./chunk-S7BSPELE.cjs');
|
||||
|
||||
|
||||
|
||||
module.exports = chunkKZVIGNTH_cjs.a;
|
||||
module.exports = chunkY5FIE5OK_cjs.computeCIDs;
|
||||
//# sourceMappingURL=out.js.map
|
||||
//# sourceMappingURL=worker.cjs.map
|
||||
Vendored
+3
-3
@@ -1,5 +1,5 @@
|
||||
export { a as default } from './chunk-6UBSWOQL.js';
|
||||
import './chunk-A6J5HDTV.js';
|
||||
import './chunk-YCFZVUZC.js';
|
||||
export { computeCIDs as default } from './chunk-LTWPBXM5.js';
|
||||
import './chunk-SV45D2HN.js';
|
||||
import './chunk-HTZ763NS.js';
|
||||
//# sourceMappingURL=out.js.map
|
||||
//# sourceMappingURL=worker.js.map
|
||||
Reference in New Issue
Block a user