@@ -36,6 +36,8 @@ export async function* createXorbs(
36
36
event : "file" ;
37
37
path : string ;
38
38
hash : string ;
39
+ /** Percentage of file bytes that were deduplicated (0-1) */
40
+ dedupRatio : number ;
39
41
representation : Array < {
40
42
xorbId : number | string ; // either xorb id (for local xorbs) or xorb hash (for remote xorbs)
41
43
offset : number ;
@@ -74,6 +76,7 @@ export async function* createXorbs(
74
76
event : "file" ;
75
77
path : string ;
76
78
hash : string ;
79
+ dedupRatio : number ;
77
80
representation : Array < {
78
81
xorbId : number | string ;
79
82
offset : number ;
@@ -84,14 +87,15 @@ export async function* createXorbs(
84
87
} > = [ ] ;
85
88
86
89
const remoteXorbHashes : string [ ] = [ "" ] ; // starts at index 1 (to simplify implem a bit)
87
- let bytesSinceRemoteDedup = Infinity ;
88
90
89
91
try {
90
92
for await ( const fileSource of fileSources ) {
93
+ let bytesSinceRemoteDedup = Infinity ;
91
94
const sourceChunks : Array < Uint8Array > = [ ] ;
92
95
93
96
const reader = fileSource . content . stream ( ) . getReader ( ) ;
94
97
let processedBytes = 0 ;
98
+ let dedupedBytes = 0 ; // Track bytes that were deduplicated
95
99
const fileChunks : Array < { hash : string ; length : number } > = [ ] ;
96
100
let currentChunkRangeBeginning = 0 ;
97
101
const fileRepresentation : Array < {
@@ -195,6 +199,7 @@ export async function* createXorbs(
195
199
chunkXorbId = cacheData . xorbIndex ;
196
200
chunkOffset = cacheData . offset ;
197
201
chunkEndOffset = cacheData . endOffset ;
202
+ dedupedBytes += chunk . length ; // Track deduplicated bytes
198
203
}
199
204
bytesSinceRemoteDedup += chunk . length ;
200
205
@@ -270,10 +275,13 @@ export async function* createXorbs(
270
275
) ;
271
276
}
272
277
278
+ const dedupRatio = fileSource . content . size > 0 ? dedupedBytes / fileSource . content . size : 0 ;
279
+
273
280
pendingFileEvents . push ( {
274
281
event : "file" as const ,
275
282
path : fileSource . path ,
276
283
hash : chunkModule . compute_file_hash ( fileChunks ) ,
284
+ dedupRatio,
277
285
representation : fileRepresentation ,
278
286
} ) ;
279
287
}
0 commit comments