summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Zakian <2895723+tzakian@users.noreply.github.com>2019-01-09 18:49:49 (GMT)
committerTim Zakian <2895723+tzakian@users.noreply.github.com>2019-01-09 18:49:49 (GMT)
commit81937422514f5b6847d1a99cd5315449ec59566e (patch)
treef7fd4d6b2c5c28540dfb3444ffb58406eea9dbbb
parentd6eac9c5cf376570595e07115304fbbbdeb32a06 (diff)
downloadlz4-81937422514f5b6847d1a99cd5315449ec59566e.zip
lz4-81937422514f5b6847d1a99cd5315449ec59566e.tar.gz
lz4-81937422514f5b6847d1a99cd5315449ec59566e.tar.bz2
Make LZ4F_getBlockSize public and publis in experimental section
-rw-r--r--lib/lz4frame.c15
-rw-r--r--lib/lz4frame.h1
-rw-r--r--tests/frametest.c22
3 files changed, 30 insertions, 8 deletions
diff --git a/lib/lz4frame.c b/lib/lz4frame.c
index 705832d..3f81ef0 100644
--- a/lib/lz4frame.c
+++ b/lib/lz4frame.c
@@ -265,22 +265,21 @@ unsigned LZ4F_getVersion(void) { return LZ4F_VERSION; }
int LZ4F_compressionLevel_max(void) { return LZ4HC_CLEVEL_MAX; }
-
-/*-************************************
-* Private functions
-**************************************/
-#define MIN(a,b) ( (a) < (b) ? (a) : (b) )
-
-static size_t LZ4F_getBlockSize(unsigned blockSizeID)
+size_t LZ4F_getBlockSize(unsigned blockSizeID)
{
static const size_t blockSizes[4] = { 64 KB, 256 KB, 1 MB, 4 MB };
if (blockSizeID == 0) blockSizeID = LZ4F_BLOCKSIZEID_DEFAULT;
+ if (blockSizeID < 4 || blockSizeID > 7) return err0r(LZ4F_ERROR_maxBlockSize_invalid);
blockSizeID -= 4;
- if (blockSizeID > 3) return err0r(LZ4F_ERROR_maxBlockSize_invalid);
return blockSizes[blockSizeID];
}
+/*-************************************
+* Private functions
+**************************************/
+#define MIN(a,b) ( (a) < (b) ? (a) : (b) )
+
static BYTE LZ4F_headerChecksum (const void* header, size_t length)
{
U32 const xxh = XXH32(header, length, 0);
diff --git a/lib/lz4frame.h b/lib/lz4frame.h
index 7c7c34e..68f4118 100644
--- a/lib/lz4frame.h
+++ b/lib/lz4frame.h
@@ -483,6 +483,7 @@ typedef enum { LZ4F_LIST_ERRORS(LZ4F_GENERATE_ENUM)
LZ4FLIB_STATIC_API LZ4F_errorCodes LZ4F_getErrorCode(size_t functionResult);
+LZ4FLIB_STATIC_API size_t LZ4F_getBlockSize(unsigned);
/**********************************
* Bulk processing dictionary API
diff --git a/tests/frametest.c b/tests/frametest.c
index b93f4fe..75fd062 100644
--- a/tests/frametest.c
+++ b/tests/frametest.c
@@ -658,6 +658,28 @@ int basicTests(U32 seed, double compressibility)
CHECK( LZ4F_freeCompressionContext(cctx) ); cctx = NULL;
}
+ DISPLAYLEVEL(3, "getBlockSize test: \n");
+ { size_t result;
+ for (unsigned blockSizeID = 4; blockSizeID < 8; ++blockSizeID) {
+ result = LZ4F_getBlockSize(blockSizeID);
+ CHECK(result);
+ DISPLAYLEVEL(3, "Returned block size of %zu bytes for blockID %u \n",
+ result, blockSizeID);
+ }
+
+ /* Test an invalid input that's too large */
+ result = LZ4F_getBlockSize(8);
+ if(!LZ4F_isError(result) ||
+ LZ4F_getErrorCode(result) != LZ4F_ERROR_maxBlockSize_invalid)
+ goto _output_error;
+
+ /* Test an invalid input that's too small */
+ result = LZ4F_getBlockSize(3);
+ if(!LZ4F_isError(result) ||
+ LZ4F_getErrorCode(result) != LZ4F_ERROR_maxBlockSize_invalid)
+ goto _output_error;
+ }
+
DISPLAYLEVEL(3, "Skippable frame test : \n");
{ size_t decodedBufferSize = COMPRESSIBLE_NOISE_LENGTH;