File tree Expand file tree Collapse file tree 2 files changed +3
-16
lines changed
Expand file tree Collapse file tree 2 files changed +3
-16
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ import type {
88import {
99 generateChunkKey ,
1010 openDatabase ,
11- computeChunkHash ,
1211 parseChunkIndexFromKey ,
1312 getAllChunkKeysForBaseKey ,
1413 deterministicUUID ,
@@ -419,7 +418,9 @@ export class IDBCache implements AsyncStorage {
419418 const chunk = value . slice ( i , i + this . chunkSize ) ;
420419 const chunkIndex = Math . floor ( i / this . chunkSize ) ;
421420
422- const chunkHash = await computeChunkHash ( chunk , this . cacheBuster ) ;
421+ const chunkHash = await deterministicUUID (
422+ `${ this . cacheKey } :${ this . cacheBuster } :${ chunk } `
423+ ) ;
423424 const chunkKey = generateChunkKey ( baseKey , chunkIndex , chunkHash ) ;
424425 newChunkKeys . add ( chunkKey ) ;
425426
Original file line number Diff line number Diff line change @@ -55,20 +55,6 @@ export function generateChunkKey(
5555 return `${ baseKey } -chunk-${ String ( chunkIndex ) . padStart ( 6 , "0" ) } -${ chunkHash } ` ;
5656}
5757
58- export async function computeChunkHash (
59- chunk : string ,
60- cacheBuster : string
61- ) : Promise < string > {
62- const encoder = new TextEncoder ( ) ;
63- const data = encoder . encode ( `${ cacheBuster } :${ chunk } ` ) ;
64- const hashBuffer = await crypto . subtle . digest ( "SHA-512" , data ) ;
65- const hashArray = Array . from ( new Uint8Array ( hashBuffer ) ) ;
66- const hashHex = hashArray
67- . map ( ( b ) => b . toString ( 16 ) . padStart ( 2 , "0" ) )
68- . join ( "" ) ;
69- return generateUUIDFromHash ( hashHex ) ;
70- }
71-
7258export function parseChunkIndexFromKey ( chunkKey : string ) : number {
7359 const parts = chunkKey . split ( "-chunk-" ) ;
7460 if ( parts . length < 2 ) return - 1 ;
You can’t perform that action at this time.
0 commit comments