cleaning up code
This commit is contained in:
parent
a56dcbfcf8
commit
81fa33b55a
@ -872,6 +872,23 @@ typedef struct {
|
||||
} fileInfo_t;
|
||||
|
||||
|
||||
int calcFrameHeaderSize(BYTE frameHeaderDescriptor){
|
||||
int frameContentSizeBytes = 0;
|
||||
int windowDescriptorBytes;
|
||||
int dictionaryIDBytes;
|
||||
int frameContentSizeFlag = frameHeaderDescriptor >> 6;
|
||||
int singleSegmentFlag = (frameHeaderDescriptor & (1 << 5)) >> 5;
|
||||
int dictionaryIDFlag = frameHeaderDescriptor & 3;
|
||||
if(frameContentSizeFlag!=0){
|
||||
frameContentSizeBytes = 1 << frameContentSizeFlag;
|
||||
}
|
||||
else if(singleSegmentFlag){
|
||||
frameContentSizeBytes = 1;
|
||||
}
|
||||
windowDescriptorBytes = singleSegmentFlag ? 0 : 1;
|
||||
dictionaryIDBytes = dictionaryIDFlag ? 1 << (dictionaryIDFlag - 1): 0;
|
||||
return 4 + 1 + windowDescriptorBytes + frameContentSizeBytes + dictionaryIDBytes;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads information from file, stores in *info
|
||||
@ -896,17 +913,9 @@ int getFileInfo(fileInfo_t* info, const char* inFileName){
|
||||
magicNumber = MEM_readLE32(magicNumberBuffer);
|
||||
if(magicNumber==ZSTD_MAGICNUMBER){
|
||||
BYTE frameHeaderDescriptor;
|
||||
int frameContentSizeFlag;
|
||||
int singleSegmentFlag;
|
||||
int contentChecksumFlag;
|
||||
int dictionaryIDFlag;
|
||||
int frameContentSizeBytes=0;
|
||||
int windowDescriptorBytes;
|
||||
int dictionaryIDBytes;
|
||||
int totalFrameHeaderBytes;
|
||||
BYTE* frameHeader;
|
||||
U64 additional;
|
||||
int lastBlock;
|
||||
int lastBlock = 0;
|
||||
size_t readBytes = fread(&frameHeaderDescriptor, 1, 1, srcFile);
|
||||
info->numActualFrames++;
|
||||
if(readBytes != 1){
|
||||
@ -914,19 +923,7 @@ int getFileInfo(fileInfo_t* info, const char* inFileName){
|
||||
exit(1);
|
||||
}
|
||||
/* calculate actual frame header size */
|
||||
frameContentSizeFlag = frameHeaderDescriptor >> 6;
|
||||
singleSegmentFlag = (frameHeaderDescriptor & (1 << 5)) >> 5;
|
||||
contentChecksumFlag = (frameHeaderDescriptor & (1 << 2)) >> 2;
|
||||
dictionaryIDFlag = frameHeaderDescriptor & 3;
|
||||
if(frameContentSizeFlag!=0){
|
||||
frameContentSizeBytes = 1 << frameContentSizeFlag;
|
||||
}
|
||||
else if(singleSegmentFlag){
|
||||
frameContentSizeBytes = 1;
|
||||
}
|
||||
windowDescriptorBytes = singleSegmentFlag ? 0 : 1;
|
||||
dictionaryIDBytes = dictionaryIDFlag ? 1 << (dictionaryIDFlag - 1): 0;
|
||||
totalFrameHeaderBytes = 4 + 1 + windowDescriptorBytes + frameContentSizeBytes + dictionaryIDBytes;
|
||||
totalFrameHeaderBytes = calcFrameHeaderSize(frameHeaderDescriptor);
|
||||
|
||||
/* reset to beginning of from and read entire header */
|
||||
fseek(srcFile, -5, SEEK_CUR);
|
||||
@ -938,21 +935,17 @@ int getFileInfo(fileInfo_t* info, const char* inFileName){
|
||||
}
|
||||
|
||||
/* get decompressed file size */
|
||||
additional = ZSTD_getFrameContentSize(frameHeader, totalFrameHeaderBytes);
|
||||
if(additional!=ZSTD_CONTENTSIZE_UNKNOWN && additional!=ZSTD_CONTENTSIZE_ERROR){
|
||||
info->decompressedSize += additional;
|
||||
}
|
||||
else{
|
||||
info->canComputeDecompSize = 0;
|
||||
}
|
||||
|
||||
/* check if checksum is used */
|
||||
if(contentChecksumFlag){
|
||||
info->usesCheck = 1;
|
||||
{
|
||||
U64 additional = ZSTD_getFrameContentSize(frameHeader, totalFrameHeaderBytes);
|
||||
if(additional!=ZSTD_CONTENTSIZE_UNKNOWN && additional!=ZSTD_CONTENTSIZE_ERROR){
|
||||
info->decompressedSize += additional;
|
||||
}
|
||||
else{
|
||||
info->canComputeDecompSize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* skip the rest of the blocks in the frame */
|
||||
lastBlock = 0;
|
||||
do{
|
||||
BYTE blockHeaderBuffer[3];
|
||||
U32 blockHeader;
|
||||
@ -967,8 +960,15 @@ int getFileInfo(fileInfo_t* info, const char* inFileName){
|
||||
blockSize = (blockHeader - (blockHeader & 7)) >> 3;
|
||||
fseek(srcFile, blockSize, SEEK_CUR);
|
||||
}while(lastBlock != 1);
|
||||
if(contentChecksumFlag){
|
||||
fseek(srcFile, 4, SEEK_CUR);
|
||||
{
|
||||
/* check if checksum is used */
|
||||
int contentChecksumFlag = (frameHeaderDescriptor & (1 << 2)) >> 2;
|
||||
if(contentChecksumFlag){
|
||||
info->usesCheck = 1;
|
||||
}
|
||||
if(contentChecksumFlag){
|
||||
fseek(srcFile, 4, SEEK_CUR);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(magicNumber==ZSTD_MAGIC_SKIPPABLE_START){
|
||||
@ -987,64 +987,64 @@ int getFileInfo(fileInfo_t* info, const char* inFileName){
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
void displayInfo(const char* inFileName, fileInfo_t* info, int displayLevel){
|
||||
double compressedSizeMB = (double)info->compressedSize/(1 MB);
|
||||
double decompressedSizeMB = (double)info->decompressedSize/(1 MB);
|
||||
|
||||
if(displayLevel<=2){
|
||||
if(info->usesCheck && info->canComputeDecompSize){
|
||||
DISPLAY("Skippable Non-Skippable Compressed Uncompressed Ratio Check Filename\n");
|
||||
DISPLAY("%9d %13d %7.2f MB %7.2f MB %5.3f XXH64 %s\n",
|
||||
info->numSkippableFrames, info->numActualFrames, compressedSizeMB, decompressedSizeMB,
|
||||
compressedSizeMB/decompressedSizeMB, inFileName);
|
||||
}
|
||||
else if(!info->usesCheck){
|
||||
DISPLAY("Skippable Non-Skippable Compressed Uncompressed Ratio Check Filename\n");
|
||||
DISPLAY("%9d %13d %7.2f MB %7.2f MB %5.3f %s\n",
|
||||
info->numSkippableFrames, info->numActualFrames, compressedSizeMB, decompressedSizeMB,
|
||||
compressedSizeMB/decompressedSizeMB, inFileName);
|
||||
}
|
||||
else if(!info->canComputeDecompSize){
|
||||
DISPLAY("Skippable Non-Skippable Compressed Uncompressed Ratio Check Filename\n");
|
||||
DISPLAY("%9d %13d %7.2f MB XXH64 %s\n",
|
||||
info->numSkippableFrames, info->numActualFrames, compressedSizeMB, inFileName);
|
||||
}
|
||||
else{
|
||||
DISPLAY("Skippable Non-Skippable Filename\n");
|
||||
DISPLAY("%9d %13d %7.2f MB %s\n",
|
||||
info->numSkippableFrames, info->numActualFrames, compressedSizeMB, inFileName);
|
||||
}
|
||||
}
|
||||
else{
|
||||
DISPLAY("# Zstandard Frames: %d\n", info->numActualFrames);
|
||||
DISPLAY("# Skippable Frames: %d\n", info->numSkippableFrames);
|
||||
DISPLAY("Compressed Size: %.2f MB (%llu B)\n", compressedSizeMB, info->compressedSize);
|
||||
if(info->canComputeDecompSize){
|
||||
DISPLAY("Decompressed Size: %.2f MB (%llu B)\n", decompressedSizeMB, info->decompressedSize);
|
||||
DISPLAY("Ratio: %.4f\n", compressedSizeMB/decompressedSizeMB);
|
||||
}
|
||||
if(info->usesCheck){
|
||||
DISPLAY("Check: XXH64\n");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int FIO_listFile(const char* inFileName, int displayLevel){
|
||||
const char* const suffixPtr = strrchr(inFileName, '.');
|
||||
DISPLAY("FILE DETECTED: %s\n", inFileName);
|
||||
DISPLAY("File: %s\n", inFileName);
|
||||
if(!suffixPtr || strcmp(suffixPtr, ZSTD_EXTENSION)){
|
||||
DISPLAYLEVEL(1, "file %s was not compressed with zstd -- ignoring\n", inFileName);
|
||||
DISPLAY("\n");
|
||||
DISPLAYLEVEL(1, "file %s was not compressed with zstd -- ignoring\n\n", inFileName);
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
double compressedSizeMB;
|
||||
double decompressedSizeMB;
|
||||
fileInfo_t* info = (fileInfo_t*)malloc(sizeof(fileInfo_t));
|
||||
int error = getFileInfo(info, inFileName);
|
||||
if(error==1){
|
||||
DISPLAY("An error occurred with getting file info\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
compressedSizeMB = (double)info->compressedSize/(1 MB);
|
||||
decompressedSizeMB = (double)info->decompressedSize/(1 MB);
|
||||
|
||||
if(displayLevel<=2){
|
||||
if(info->usesCheck && info->canComputeDecompSize){
|
||||
DISPLAY("Skippable Non-Skippable Compressed Uncompressed Ratio Check Filename\n");
|
||||
DISPLAY("%9d %13d %7.2f MB %7.2f MB %5.3f XXH64 %s\n",
|
||||
info->numSkippableFrames, info->numActualFrames, compressedSizeMB, decompressedSizeMB,
|
||||
compressedSizeMB/decompressedSizeMB, inFileName);
|
||||
}
|
||||
else if(!info->usesCheck){
|
||||
DISPLAY("Skippable Non-Skippable Compressed Uncompressed Ratio Check Filename\n");
|
||||
DISPLAY("%9d %13d %7.2f MB %7.2f MB %5.3f %s\n",
|
||||
info->numSkippableFrames, info->numActualFrames, compressedSizeMB, decompressedSizeMB,
|
||||
compressedSizeMB/decompressedSizeMB, inFileName);
|
||||
}
|
||||
else if(!info->canComputeDecompSize){
|
||||
DISPLAY("Skippable Non-Skippable Compressed Uncompressed Ratio Check Filename\n");
|
||||
DISPLAY("%9d %13d %7.2f MB XXH64 %s\n",
|
||||
info->numSkippableFrames, info->numActualFrames, compressedSizeMB, inFileName);
|
||||
}
|
||||
else{
|
||||
DISPLAY("Skippable Non-Skippable Filename\n");
|
||||
DISPLAY("%9d %13d %7.2f MB %s\n",
|
||||
info->numSkippableFrames, info->numActualFrames, compressedSizeMB, inFileName);
|
||||
}
|
||||
}
|
||||
else{
|
||||
DISPLAY("# Zstandard Frames: %d\n", info->numActualFrames);
|
||||
DISPLAY("# Skippable Frames: %d\n", info->numSkippableFrames);
|
||||
DISPLAY("Compressed Size: %.2f MB (%llu B)\n", compressedSizeMB, info->compressedSize);
|
||||
if(info->canComputeDecompSize){
|
||||
DISPLAY("Decompressed Size: %.2f MB (%llu B)\n", decompressedSizeMB, info->decompressedSize);
|
||||
DISPLAY("Ratio: %.4f\n", compressedSizeMB/decompressedSizeMB);
|
||||
}
|
||||
if(info->usesCheck){
|
||||
DISPLAY("Check: XXH64\n");
|
||||
}
|
||||
}
|
||||
displayInfo(inFileName, info, displayLevel);
|
||||
}
|
||||
DISPLAY("\n");
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user