🐛 Don't read additional 12 bytes after each file
This commit is contained in:
parent
f64412ebfe
commit
2299d8ed6e
1 changed files with 5 additions and 3 deletions
|
@ -70,10 +70,13 @@ int main(int argc, char *argv[]) {
|
||||||
getBytes(NULL, additionalLength, false);
|
getBytes(NULL, additionalLength, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long remainingBytes = state.fileSize;
|
||||||
|
|
||||||
//If file is encrypted, skip 12-byte encryption header
|
//If file is encrypted, skip 12-byte encryption header
|
||||||
if (state.isEncrypted) {
|
if (state.isEncrypted) {
|
||||||
getBytes(compressedChunk, ENCRYPTION_HEADER_LENGTH, false);
|
getBytes(compressedChunk, ENCRYPTION_HEADER_LENGTH, false);
|
||||||
decrypt(compressedChunk, ENCRYPTION_HEADER_LENGTH);
|
decrypt(compressedChunk, ENCRYPTION_HEADER_LENGTH);
|
||||||
|
remainingBytes -= 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Initialize xdelta3
|
//Initialize xdelta3
|
||||||
|
@ -87,14 +90,13 @@ int main(int argc, char *argv[]) {
|
||||||
inflateInit(compressedChunk, uncompressedChunk, BUFFER_SIZE);
|
inflateInit(compressedChunk, uncompressedChunk, BUFFER_SIZE);
|
||||||
|
|
||||||
//Read actual file
|
//Read actual file
|
||||||
unsigned long remainingBytes = state.fileSize;
|
|
||||||
bool needToRead = true;
|
bool needToRead = true;
|
||||||
bool hasReachedEnd = false;
|
bool hasReachedEnd = false;
|
||||||
unsigned long chunkSize;
|
unsigned long chunkSize;
|
||||||
unsigned long uncompressedPosition = 0UL;
|
unsigned long uncompressedPosition = 0UL;
|
||||||
while (remainingBytes > 0 || !hasReachedEnd) {
|
while (remainingBytes > 0 || !hasReachedEnd) {
|
||||||
if (needToRead) {
|
if (needToRead && remainingBytes > 0) {
|
||||||
chunkSize = min(BUFFER_SIZE - uncompressedPosition, remainingBytes);
|
chunkSize = min(BUFFER_SIZE, remainingBytes);
|
||||||
getBytes(compressedChunk, chunkSize, chunkSize == remainingBytes);
|
getBytes(compressedChunk, chunkSize, chunkSize == remainingBytes);
|
||||||
remainingBytes -= chunkSize;
|
remainingBytes -= chunkSize;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue