summaryrefslogtreecommitdiffstats
path: root/programs
diff options
context:
space:
mode:
Diffstat (limited to 'programs')
-rw-r--r--programs/lz4cli.c14
-rw-r--r--programs/lz4io.c25
-rw-r--r--programs/lz4io.h4
3 files changed, 33 insertions, 10 deletions
diff --git a/programs/lz4cli.c b/programs/lz4cli.c
index 46a95cd..759f336 100644
--- a/programs/lz4cli.c
+++ b/programs/lz4cli.c
@@ -134,7 +134,8 @@ static int usage_advanced(const char* exeName)
DISPLAY( " -r : operate recursively on directories (sets also -m) \n");
#endif
DISPLAY( " -l : compress using Legacy format (Linux kernel compression)\n");
- DISPLAY( " -B# : Block size [4-7] (default : 7) \n");
+ DISPLAY( " -B# : cut file into independent blocks of size # bytes [32+] \n");
+ DISPLAY( " or predefined block size [4-7] (default: 7) \n");
DISPLAY( " -BD : Block dependency (improve compression ratio) \n");
DISPLAY( " -BX : enable block checksum (default:disabled) \n");
DISPLAY( "--no-frame-crc : disable stream checksum (default:enabled) \n");
@@ -146,8 +147,6 @@ static int usage_advanced(const char* exeName)
DISPLAY( " -b# : benchmark file(s), using # compression level (default : 1) \n");
DISPLAY( " -e# : test all compression levels from -bX to # (default : 1)\n");
DISPLAY( " -i# : minimum evaluation time in seconds (default : 3s) \n");
- DISPLAY( " -B# : cut file into independent blocks of size # bytes [32+] \n");
- DISPLAY( " or predefined block size [4-7] (default: 7) \n");
if (g_lz4c_legacy_commands) {
DISPLAY( "Legacy arguments : \n");
DISPLAY( " -c0 : fast compression \n");
@@ -497,11 +496,12 @@ int main(int argc, const char** argv)
DISPLAYLEVEL(2, "using blocks of size %u KB \n", (U32)(blockSize>>10));
} else {
if (B < 32) badusage(exeName);
- BMK_setBlockSize(B);
- if (B >= 1024) {
- DISPLAYLEVEL(2, "bench: using blocks of size %u KB \n", (U32)(B>>10));
+ blockSize = LZ4IO_setBlockSize(B);
+ BMK_setBlockSize(blockSize);
+ if (blockSize >= 1024) {
+ DISPLAYLEVEL(2, "using blocks of size %u KB \n", (U32)(blockSize>>10));
} else {
- DISPLAYLEVEL(2, "bench: using blocks of size %u bytes \n", (U32)(B));
+ DISPLAYLEVEL(2, "using blocks of size %u bytes \n", (U32)(blockSize));
}
}
break;
diff --git a/programs/lz4io.c b/programs/lz4io.c
index cdc4c27..17ff9a1 100644
--- a/programs/lz4io.c
+++ b/programs/lz4io.c
@@ -110,6 +110,7 @@ static clock_t g_time = 0;
static int g_overwrite = 1;
static int g_testMode = 0;
static int g_blockSizeId = LZ4IO_BLOCKSIZEID_DEFAULT;
+static int g_blockSize = 0;
static int g_blockChecksum = 0;
static int g_streamChecksum = 1;
static int g_blockIndependence = 1;
@@ -178,7 +179,25 @@ size_t LZ4IO_setBlockSizeID(unsigned bsid)
static const unsigned maxBlockSizeID = 7;
if ((bsid < minBlockSizeID) || (bsid > maxBlockSizeID)) return 0;
g_blockSizeId = bsid;
- return blockSizeTable[g_blockSizeId-minBlockSizeID];
+ g_blockSize = blockSizeTable[g_blockSizeId-minBlockSizeID];
+ return g_blockSize;
+}
+
+size_t LZ4IO_setBlockSize(size_t blockSize)
+{
+ static const size_t minBlockSize = 32;
+ static const size_t maxBlockSize = 4 MB;
+ unsigned bsid = 0;
+ if (blockSize < minBlockSize) blockSize = minBlockSize;
+ if (blockSize > maxBlockSize) blockSize = maxBlockSize;
+ g_blockSize = blockSize;
+ blockSize--;
+ /* find which of { 64k, 256k, 1MB, 4MB } is closest to blockSize */
+ while (blockSize >>= 2)
+ bsid++;
+ if (bsid < 7) bsid = 7;
+ g_blockSizeId = bsid-3;
+ return g_blockSize;
}
int LZ4IO_setBlockMode(LZ4IO_blockMode_t blockMode)
@@ -499,7 +518,7 @@ static LZ4F_CDict* LZ4IO_createCDict(void) {
static cRess_t LZ4IO_createCResources(void)
{
- const size_t blockSize = (size_t)LZ4IO_GetBlockSize_FromBlockId (g_blockSizeId);
+ const size_t blockSize = g_blockSize;
cRess_t ress;
LZ4F_errorCode_t const errorCode = LZ4F_createCompressionContext(&(ress.ctx), LZ4F_VERSION);
@@ -543,7 +562,7 @@ static int LZ4IO_compressFilename_extRess(cRess_t ress, const char* srcFileName,
void* const srcBuffer = ress.srcBuffer;
void* const dstBuffer = ress.dstBuffer;
const size_t dstBufferSize = ress.dstBufferSize;
- const size_t blockSize = (size_t)LZ4IO_GetBlockSize_FromBlockId (g_blockSizeId);
+ const size_t blockSize = g_blockSize;
size_t readSize;
LZ4F_compressionContext_t ctx = ress.ctx; /* just a pointer */
LZ4F_preferences_t prefs;
diff --git a/programs/lz4io.h b/programs/lz4io.h
index 22c5e3e..33de41f 100644
--- a/programs/lz4io.h
+++ b/programs/lz4io.h
@@ -78,6 +78,10 @@ int LZ4IO_setTestMode(int yes);
return : 0 if error, blockSize if OK */
size_t LZ4IO_setBlockSizeID(unsigned blockSizeID);
+/* blockSize : valid values : 32 -> 4MB
+ return : 0 if error, actual blocksize if OK */
+size_t LZ4IO_setBlockSize(size_t blockSize);
+
/* Default setting : independent blocks */
typedef enum { LZ4IO_blockLinked=0, LZ4IO_blockIndependent} LZ4IO_blockMode_t;
int LZ4IO_setBlockMode(LZ4IO_blockMode_t blockMode);