Skip to content

Commit

Permalink
Optimize checksum calculation on verify
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanA101a committed Mar 10, 2024
1 parent 8863e95 commit d97e86e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/fileimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*
*/

#define CHUNK_SIZE 1024
#include "fileimpl.h"
#include <zim/error.h>
#include "_dirent.h"
Expand Down Expand Up @@ -550,7 +551,7 @@ class Grouping

struct zim_MD5_CTX md5ctx;
zim_MD5Init(&md5ctx);

unsigned char ch[CHUNK_SIZE];
offset_type checksumPos = header.getChecksumPos();
offset_type toRead = checksumPos;
Expand All @@ -564,8 +565,12 @@ class Grouping
zim_MD5Update(&md5ctx, ch, CHUNK_SIZE);
toRead-=stream.gcount();
}

// It reads the remaining amount of file when we reach the end of the file

// Previous read was good, so we have exited the previous `while` because
// `toRead<CHUNK_SIZE`. Let's try to read `toRead` chars and process them later.
// Else, the previous `while` exited because we didn't succeed to read
// `CHUNK_SIZE`, and we still have some data to process before changing part.
// It reads the remaining amount of part when we reach the end of the file
if(stream.good()){
stream.read(reinterpret_cast<char*>(ch),toRead);
}
Expand Down

0 comments on commit d97e86e

Please sign in to comment.