Question

In my application, I divided file into the parts and calculate the hash values of each part the write into a txt file. And after I want to merge these parts at this point I just wanna use these hash values for reach the parts,is it possible ? So it is How can i do it ?

Was it helpful?

Solution

All depends what hashing function you used. If this is sha1, md5sum, or antyhing that is not reversible then you need to create a separate 'map' file that will contain hash and corresponding data. Now, having such map, you can read your file containing hashes, and replace these hashes with the appropriate data read from the map file.

hashing-and-dividing-function:

while ( chunk = get_next_chunk())
{
  hash = hashing_function( chunk ) ;
  store( hash ) ;
  if ( !map.find( hash ))
     map[ hash ] = chunk ;
}
map.dump( mapfile ) ;

Restoring:

map.load( mapfile ) ;
while ( hash = get_next_hash())
{
   write( map[ hash ]) ;
}

OTHER TIPS

If the hash is good it's not possible in general; hash functions are designed to be one way. I guess you'll have to iterate on the directory where the parts are and recalculate the hash for each one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top