@@ -3,15 +3,18 @@ import UtilPath from './path.js'
33import UtilHash from './hash.js'
44import UtilProgress from './progress.js'
55
6- function getFileSummary ( base = '' , paths = [ ] , queue = null ) {
6+ async function getFileSummary ( base = '' , paths = [ ] , queue = null ) {
77 const countTotal = paths . length
88 const progress = UtilProgress . createProgressbar ( { total : countTotal } )
99 const summary = [ ]
10+ const hashChunkConfig = UtilHash . getHashChunkPlots ( { name : 'single plot' , offset : 0 , limit : 100 * 1024 } )
1011
1112 _ . each ( paths , async path => {
1213 await queue . add ( ( ) => {
1314 const filename = UtilPath . relative ( base , path )
14- const md5 = UtilHash . getHash ( path , { offset : 0 , limit : 100 * 1024 } )
15+ const md5 = UtilHash . getHashByChunks ( path , {
16+ chunks : hashChunkConfig
17+ } )
1518
1619 const pack = {
1720 path,
@@ -24,6 +27,44 @@ function getFileSummary (base = '', paths = [], queue = null) {
2427 } )
2528 } )
2629
30+ await queue . onIdle ( )
31+
32+ return summary
33+ }
34+
35+ async function rehashFileSummary ( files = [ ] , queue = null ) {
36+ const countTotal = files . length
37+ const progress = UtilProgress . createProgressbar ( { total : countTotal } )
38+ const summary = [ ]
39+
40+ _ . each ( files , async file => {
41+ await queue . add ( ( ) => {
42+ const path = file . path
43+ const chunkConfig = UtilHash . getHashChunkPlots ( {
44+ name : 'distribution plots' ,
45+ file : path ,
46+ chunks : 10 ,
47+ offset : 0 ,
48+ limit : 10 * 1024
49+ } )
50+ const filename = file . filename
51+ const md5 = UtilHash . getHashByChunks ( path , {
52+ chunks : chunkConfig
53+ } )
54+
55+ const pack = {
56+ path,
57+ filename,
58+ md5
59+ }
60+
61+ summary . push ( pack )
62+ progress . tick ( )
63+ } )
64+ } )
65+
66+ await queue . onIdle ( )
67+
2768 return summary
2869}
2970
@@ -62,6 +103,21 @@ function getCompareSummary (lhs = [], rhs = []) {
62103 return summary
63104}
64105
106+ async function revalidateCompareSummary ( summary = [ ] , lhsQueue = null , rhsQueue = null ) {
107+ const summaryUnsame = _ . filter ( summary , v => v . type !== 'same' )
108+ const summarySame = _ . filter ( summary , v => v . type === 'same' )
109+
110+ const lhs = _ . chain ( summarySame ) . map ( v => v . lhs || [ ] ) . flattenDeep ( ) . value ( )
111+ const lhsRehashed = await rehashFileSummary ( lhs , lhsQueue )
112+ const rhs = _ . chain ( summarySame ) . map ( v => v . rhs || [ ] ) . flattenDeep ( ) . value ( )
113+ const rhsRehashed = await rehashFileSummary ( rhs , rhsQueue )
114+ const summaryRehashed = getCompareSummary ( lhsRehashed , rhsRehashed )
115+
116+ const summaryNew = _ . concat ( [ ] , summaryUnsame , summaryRehashed )
117+
118+ return summaryNew
119+ }
120+
65121function getCompareReport ( summary = [ ] ) {
66122 const template = `<!DOCTYPE html>
67123<html>
@@ -190,6 +246,8 @@ function getCompareReport (summary = []) {
190246
191247export default {
192248 getFileSummary,
249+ rehashFileSummary,
193250 getCompareSummary,
251+ revalidateCompareSummary,
194252 getCompareReport
195253}
0 commit comments