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