Skip to content

Commit

Permalink
Cleanup code LZ4 and rename enum ffLz4 to ffActual
Browse files Browse the repository at this point in the history
  • Loading branch information
remittor committed Nov 29, 2019
1 parent e1f2fe2 commit 24cc0a1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
17 changes: 8 additions & 9 deletions src/lz4lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@

namespace lz4 {

bool is_legacy_frame(DWORD magic)
Format check_frame_magic(DWORD magic)
{
return (magic == LEGACY_MAGICNUMBER) ? true : false;
}

bool check_frame_magic(DWORD magic)
{
return (magic == LZ4F_MAGICNUMBER || magic == LEGACY_MAGICNUMBER) ? true : false;
if (is_legacy_frame(magic))
return ffLegacy;

return (magic == LZ4F_MAGICNUMBER) ? ffActual : ffUnknown;
}

int check_file_header(HANDLE hFile, UINT64 file_size)
Expand Down Expand Up @@ -40,9 +38,10 @@ int check_file_header(HANDLE hFile, UINT64 file_size)
FIN_IF(!x, -5);
FIN_IF(dwRead != sizeof(header.magic), -6);

FIN_IF(lz4::check_frame_magic(header.magic) == FALSE, -7);
Format fmt = lz4::check_frame_magic(header.magic);
FIN_IF(fmt == ffUnknown, -7);

hr = 0;
hr = (int)fmt;

fin:
return hr;
Expand Down
11 changes: 8 additions & 3 deletions src/lz4lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ const DWORD BLOCKUNCOMPRES_FLAG = 0x80000000UL; // LZ4F_BLOCKUNCOMPRESSED_FLAG
enum Format : char {
ffUnknown = 0,
ffLegacy = 1, // legacy LZ4 frame
ffLz4 = 2, // actual LZ4 frame
ffActual = 2, // actual LZ4 frame
};

bool is_legacy_frame(DWORD magic);
bool check_frame_magic(DWORD magic);
__forceinline
bool is_legacy_frame(DWORD magic)
{
return (magic == LEGACY_MAGICNUMBER) ? true : false;
}

Format check_frame_magic(DWORD magic);
int check_file_header(HANDLE hFile, UINT64 file_size);
int check_file_header(LPCWSTR filename);

Expand Down
2 changes: 1 addition & 1 deletion src/wcx_arcfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ int arcfile::update_type(HANDLE hFile)
FIN_IF(finfo.frameType != LZ4F_frame, 0);

m_type = atLz4;
m_lz4format = lz4::ffLz4;
m_lz4format = lz4::ffActual;

if (finfo.data_size) {
int sz = 0;
Expand Down

0 comments on commit 24cc0a1

Please sign in to comment.