🎨 Simplify code

This commit is contained in:
C-3PO 2019-07-21 22:16:00 +02:00
parent 205642821f
commit e6af0c35de
Signed by: c3po
GPG key ID: 62993C4BB4D86F24

View file

@ -38,14 +38,14 @@ void inflateInit(uint8_t* comprBufferIn, uint8_t* uncomprBufferIn, unsigned long
struct InflateOutput inflateInflate(unsigned long numInputBytes, bool hasMoreBytes) { struct InflateOutput inflateInflate(unsigned long numInputBytes, bool hasMoreBytes) {
if (numInputBytes == 0) { if (numInputBytes == 0) {
//continue in input buffer where we were before //Continue in input buffer where we were before
} else { } else {
//go back to beginning of input buffer //Go back to beginning of input buffer
comprBufferNext = comprBuffer; comprBufferNext = comprBuffer;
remainingInput = numInputBytes; remainingInput = numInputBytes;
} }
//output buffer was previously fully filled and all output was processed. New uncompressed data can be written starting at offset 0 //Output buffer was previously fully filled and all output was processed. New uncompressed data can be written starting at offset 0
if (spaceInOutput == 0) { if (spaceInOutput == 0) {
uncomprBufferNext = (mz_uint8 *)uncomprBuffer; uncomprBufferNext = (mz_uint8 *)uncomprBuffer;
spaceInOutput = uncomprBufferSize; spaceInOutput = uncomprBufferSize;
@ -77,18 +77,17 @@ struct InflateOutput inflateInflate(unsigned long numInputBytes, bool hasMoreByt
spaceInOutput -= out_bytes; spaceInOutput -= out_bytes;
out.numBytesWrittenToOutput += out_bytes; out.numBytesWrittenToOutput += out_bytes;
//Check for errors //Check miniz output
if (status <= TINFL_STATUS_DONE) {
if (status == TINFL_STATUS_DONE) { if (status == TINFL_STATUS_DONE) {
// Decompression completed successfully. // Decompression completed successfully
out.hasReachedEnd = true; out.hasReachedEnd = true;
break; break;
} else { }
// Decompression failed. if (status < TINFL_STATUS_DONE) {
// Decompression failed
fprintf(stderr, "tinfl_decompress() failed with status %i!\n", status); fprintf(stderr, "tinfl_decompress() failed with status %i!\n", status);
errorAndExit(); errorAndExit();
} }
}
if (status == TINFL_STATUS_NEEDS_MORE_INPUT && remainingInput != 0) { if (status == TINFL_STATUS_NEEDS_MORE_INPUT && remainingInput != 0) {
fprintf(stderr, "Received status NEEDS_MORE_INPUT, with remaining input %lu and space in output %lu.\n", remainingInput, spaceInOutput); fprintf(stderr, "Received status NEEDS_MORE_INPUT, with remaining input %lu and space in output %lu.\n", remainingInput, spaceInOutput);