Skip to content

Commit

Permalink
Merge pull request #98 from Cyan4973/dev
Browse files Browse the repository at this point in the history
v0.4.5
  • Loading branch information
Cyan4973 committed Dec 18, 2015
2 parents c95aa91 + 324a3e2 commit ef774a6
Show file tree
Hide file tree
Showing 15 changed files with 769 additions and 412 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# ################################################################

# Version number
export VERSION := 0.4.4
export VERSION := 0.4.5

PRGDIR = programs
ZSTDDIR = lib
Expand Down
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v0.4.5
new : -m/--multiple : compress/decompress multiple files

v0.4.4
Fixed : high compression modes for Windows 32 bits
new : external dictionary API extended to buffered mode and accessible through command line
Expand Down
2 changes: 1 addition & 1 deletion lib/zstd.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ extern "C" {
***************************************/
#define ZSTD_VERSION_MAJOR 0 /* for breaking interface changes */
#define ZSTD_VERSION_MINOR 4 /* for new (non-breaking) interface capabilities */
#define ZSTD_VERSION_RELEASE 3 /* for tweaks, bug-fixes, or development */
#define ZSTD_VERSION_RELEASE 5 /* for tweaks, bug-fixes, or development */
#define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
ZSTDLIB_API unsigned ZSTD_versionNumber (void);

Expand Down
21 changes: 17 additions & 4 deletions lib/zstd_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -2117,7 +2117,7 @@ size_t ZSTD_compressBegin(ZSTD_CCtx* ctx, void* dst, size_t maxDstSize, int comp
}


/** ZSTD_compressEnd
/*! ZSTD_compressEnd
* Write frame epilogue
* @return : nb of bytes written into dst (or an error code) */
size_t ZSTD_compressEnd(ZSTD_CCtx* ctx, void* dst, size_t maxDstSize)
Expand All @@ -2139,6 +2139,7 @@ size_t ZSTD_compressEnd(ZSTD_CCtx* ctx, void* dst, size_t maxDstSize)
size_t ZSTD_compress_advanced (ZSTD_CCtx* ctx,
void* dst, size_t maxDstSize,
const void* src, size_t srcSize,
const void* dict,size_t dictSize,
ZSTD_parameters params)
{
BYTE* const ostart = (BYTE*)dst;
Expand All @@ -2151,9 +2152,15 @@ size_t ZSTD_compress_advanced (ZSTD_CCtx* ctx,
op += oSize;
maxDstSize -= oSize;

/* dictionary */
if (dict)
{
oSize = ZSTD_compress_insertDictionary(ctx, dict, dictSize);
if (ZSTD_isError(oSize)) return oSize;
}

/* body (compression) */
ctx->base = (const BYTE*)src;
oSize = ZSTD_compress_generic (ctx, op, maxDstSize, src, srcSize);
oSize = ZSTD_compressContinue (ctx, op, maxDstSize, src, srcSize);
if(ZSTD_isError(oSize)) return oSize;
op += oSize;
maxDstSize -= oSize;
Expand All @@ -2166,9 +2173,14 @@ size_t ZSTD_compress_advanced (ZSTD_CCtx* ctx,
return (op - ostart);
}

size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize, const void* dict, size_t dictSize, int compressionLevel)
{
return ZSTD_compress_advanced(ctx, dst, maxDstSize, src, srcSize, dict, dictSize, ZSTD_getParams(compressionLevel, srcSize+dictSize));
}

size_t ZSTD_compressCCtx (ZSTD_CCtx* ctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize, int compressionLevel)
{
return ZSTD_compress_advanced(ctx, dst, maxDstSize, src, srcSize, ZSTD_getParams(compressionLevel, srcSize));
return ZSTD_compress_advanced(ctx, dst, maxDstSize, src, srcSize, NULL, 0, ZSTD_getParams(compressionLevel, srcSize));
}

size_t ZSTD_compress(void* dst, size_t maxDstSize, const void* src, size_t srcSize, int compressionLevel)
Expand All @@ -2180,3 +2192,4 @@ size_t ZSTD_compress(void* dst, size_t maxDstSize, const void* src, size_t srcSi
free(ctxBody.workSpace); /* can't free ctxBody, since it's on stack; free heap content */
return result;
}

29 changes: 24 additions & 5 deletions lib/zstd_decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,10 @@ static size_t ZSTD_decompressBlock(
}


size_t ZSTD_decompressDCtx(ZSTD_DCtx* ctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize)
size_t ZSTD_decompress_usingDict(ZSTD_DCtx* ctx,
void* dst, size_t maxDstSize,
const void* src, size_t srcSize,
const void* dict, size_t dictSize)
{
const BYTE* ip = (const BYTE*)src;
const BYTE* iend = ip + srcSize;
Expand All @@ -686,9 +689,19 @@ size_t ZSTD_decompressDCtx(ZSTD_DCtx* ctx, void* dst, size_t maxDstSize, const v
size_t remainingSize = srcSize;
blockProperties_t blockProperties;


/* init */
ctx->vBase = ctx->base = ctx->dictEnd = dst;
ZSTD_resetDCtx(ctx);
if (dict)
{
ZSTD_decompress_insertDictionary(ctx, dict, dictSize);
ctx->dictEnd = ctx->previousDstEnd;
ctx->vBase = (const char*)dst - ((const char*)(ctx->previousDstEnd) - (const char*)(ctx->base));
ctx->base = dst;
}
else
{
ctx->vBase = ctx->base = ctx->dictEnd = dst;
}

/* Frame Header */
{
Expand Down Expand Up @@ -749,10 +762,16 @@ size_t ZSTD_decompressDCtx(ZSTD_DCtx* ctx, void* dst, size_t maxDstSize, const v
return op-ostart;
}


size_t ZSTD_decompressDCtx(ZSTD_DCtx* dctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize)
{
return ZSTD_decompress_usingDict(dctx, dst, maxDstSize, src, srcSize, NULL, 0);
}

size_t ZSTD_decompress(void* dst, size_t maxDstSize, const void* src, size_t srcSize)
{
ZSTD_DCtx ctx;
return ZSTD_decompressDCtx(&ctx, dst, maxDstSize, src, srcSize);
ZSTD_DCtx dctx;
return ZSTD_decompressDCtx(&dctx, dst, maxDstSize, src, srcSize);
}


Expand Down
89 changes: 57 additions & 32 deletions lib/zstd_static.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ typedef struct


/* *************************************
* Advanced function
* Advanced functions
***************************************/
/** ZSTD_getParams
* return ZSTD_parameters structure for a selected compression level and srcSize.
Expand All @@ -91,16 +91,43 @@ ZSTDLIB_API ZSTD_parameters ZSTD_getParams(int compressionLevel, U64 srcSizeHint
* correct params value to remain within authorized range */
ZSTDLIB_API void ZSTD_validateParams(ZSTD_parameters* params);

/** ZSTD_compress_usingDict
* Same as ZSTD_compressCCtx(), using a Dictionary content as prefix
* Note : dict can be NULL, in which case, it's equivalent to ZSTD_compressCCtx() */
ZSTDLIB_API size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx,
void* dst, size_t maxDstSize,
const void* src, size_t srcSize,
const void* dict,size_t dictSize,
int compressionLevel);

/** ZSTD_compress_advanced
* Same as ZSTD_compressCCtx(), with fine-tune control of each compression parameter */
* Same as ZSTD_compress_usingDict(), with fine-tune control of each compression parameter */
ZSTDLIB_API size_t ZSTD_compress_advanced (ZSTD_CCtx* ctx,
void* dst, size_t maxDstSize,
const void* src, size_t srcSize,
const void* dict,size_t dictSize,
ZSTD_parameters params);

/** Decompression context management */
typedef struct ZSTD_DCtx_s ZSTD_DCtx;
ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx(void);
ZSTDLIB_API size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx);

/** ZSTD_decompressDCtx
* Same as ZSTD_decompress, with pre-allocated DCtx structure */
size_t ZSTD_decompressDCtx(ZSTD_DCtx* ctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize);

/** ZSTD_decompress_usingDict
* Same as ZSTD_decompressDCtx, using a Dictionary content as prefix
* Note : dict can be NULL, in which case, it's equivalent to ZSTD_decompressDCtx() */
size_t ZSTD_decompress_usingDict(ZSTD_DCtx* ctx,
void* dst, size_t maxDstSize,
const void* src, size_t srcSize,
const void* dict, size_t dictSize);


/* **************************************
* Streaming functions (bufferless mode)
* Streaming functions (direct mode)
****************************************/
ZSTDLIB_API size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, void* dst, size_t maxDstSize, int compressionLevel);
ZSTDLIB_API size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* ctx, void* dst, size_t maxDstSize, ZSTD_parameters params);
Expand All @@ -110,7 +137,7 @@ ZSTDLIB_API size_t ZSTD_compressContinue(ZSTD_CCtx* cctx, void* dst, size_t maxD
ZSTDLIB_API size_t ZSTD_compressEnd(ZSTD_CCtx* cctx, void* dst, size_t maxDstSize);

/**
Streaming compression, bufferless mode
Streaming compression, direct mode (bufferless)
A ZSTD_CCtx object is required to track streaming operations.
Use ZSTD_createCCtx() / ZSTD_freeCCtx() to manage it.
Expand All @@ -131,13 +158,10 @@ ZSTDLIB_API size_t ZSTD_compressEnd(ZSTD_CCtx* cctx, void* dst, size_t maxDstSiz
Finish a frame with ZSTD_compressEnd(), which will write the epilogue.
Without it, the frame will be considered incomplete by decoders.
You can then re-use ZSTD_CCtx to compress new frames.
*/
You can then reuse ZSTD_CCtx to compress new frames.
*/

typedef struct ZSTD_DCtx_s ZSTD_DCtx;
ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx(void);
ZSTDLIB_API size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx);

ZSTDLIB_API size_t ZSTD_resetDCtx(ZSTD_DCtx* dctx);
ZSTDLIB_API size_t ZSTD_getFrameParams(ZSTD_parameters* params, const void* src, size_t srcSize);
Expand All @@ -160,7 +184,8 @@ ZSTDLIB_API size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t ma
>0 : means there is not enough data into src. Provides the expected size to successfully decode header.
errorCode, which can be tested using ZSTD_isError() (For example, if it's not a ZSTD header)
Then, you can optionally insert a dictionary. This operation must mimic the compressor behavior, otherwise decompression will fail or be corrupted.
Then, you can optionally insert a dictionary.
This operation must mimic the compressor behavior, otherwise decompression will fail or be corrupted.
Then it's possible to start decompression.
Use ZSTD_nextSrcSizeToDecompress() and ZSTD_decompressContinue() alternatively.
Expand Down Expand Up @@ -207,28 +232,28 @@ static const ZSTD_parameters ZSTD_defaultParameters[4][ZSTD_MAX_CLEVEL+1] = {
{ 0, 26, 27, 25, 9, 5, ZSTD_btlazy2 }, /* level 20 */
},
{ /* for srcSize <= 256 KB */
/* W, C, H, S, L, strat */
{ 0, 0, 0, 0, 0, 0, ZSTD_fast }, /* level 0 - never used */
{ 0, 18, 16, 15, 1, 7, ZSTD_fast }, /* level 1 */
{ 0, 18, 16, 16, 1, 7, ZSTD_fast }, /* level 2 */
{ 0, 18, 18, 18, 1, 7, ZSTD_fast }, /* level 3 */
{ 0, 18, 14, 15, 4, 6, ZSTD_greedy }, /* level 4 */
{ 0, 18, 16, 16, 1, 6, ZSTD_lazy }, /* level 5 */
{ 0, 18, 15, 15, 3, 6, ZSTD_lazy }, /* level 6 */
{ 0, 18, 15, 15, 4, 6, ZSTD_lazy }, /* level 7 */
{ 0, 18, 16, 18, 4, 6, ZSTD_lazy }, /* level 8 */
{ 0, 18, 18, 18, 4, 6, ZSTD_lazy }, /* level 9 */
{ 0, 18, 18, 18, 5, 6, ZSTD_lazy }, /* level 10 */
{ 0, 18, 18, 19, 6, 6, ZSTD_lazy }, /* level 11 */
{ 0, 18, 18, 19, 7, 6, ZSTD_lazy }, /* level 12 */
{ 0, 18, 19, 15, 7, 5, ZSTD_btlazy2 }, /* level 13 */
{ 0, 18, 19, 16, 8, 5, ZSTD_btlazy2 }, /* level 14 */
{ 0, 18, 19, 17, 9, 5, ZSTD_btlazy2 }, /* level 15 */
{ 0, 18, 19, 17, 10, 5, ZSTD_btlazy2 }, /* level 16 */
{ 0, 18, 19, 17, 11, 5, ZSTD_btlazy2 }, /* level 17 */
{ 0, 18, 19, 17, 12, 5, ZSTD_btlazy2 }, /* level 18 */
{ 0, 18, 19, 17, 13, 5, ZSTD_btlazy2 }, /* level 19 */
{ 0, 18, 19, 17, 14, 5, ZSTD_btlazy2 }, /* level 20 */
/* W, C, H, S, L, strat */
{ 0, 18, 13, 14, 1, 7, ZSTD_fast }, /* level 0 - never used */
{ 0, 18, 14, 15, 1, 6, ZSTD_fast }, /* level 1 */
{ 0, 18, 14, 15, 1, 5, ZSTD_fast }, /* level 2 */
{ 0, 18, 12, 15, 3, 7, ZSTD_greedy }, /* level 3 */
{ 0, 18, 13, 15, 4, 7, ZSTD_greedy }, /* level 4 */
{ 0, 18, 14, 15, 5, 7, ZSTD_greedy }, /* level 5 */
{ 0, 18, 13, 15, 4, 7, ZSTD_lazy }, /* level 6 */
{ 0, 18, 14, 16, 5, 7, ZSTD_lazy }, /* level 7 */
{ 0, 18, 15, 16, 6, 7, ZSTD_lazy }, /* level 8 */
{ 0, 18, 15, 15, 7, 7, ZSTD_lazy }, /* level 9 */
{ 0, 18, 16, 16, 7, 7, ZSTD_lazy }, /* level 10 */
{ 0, 18, 16, 16, 8, 4, ZSTD_lazy }, /* level 11 */
{ 0, 18, 17, 16, 8, 4, ZSTD_lazy }, /* level 12 */
{ 0, 18, 17, 16, 9, 4, ZSTD_lazy }, /* level 13 */
{ 0, 18, 18, 16, 9, 4, ZSTD_lazy }, /* level 14 */
{ 0, 18, 17, 17, 9, 4, ZSTD_lazy2 }, /* level 15 */
{ 0, 18, 18, 18, 9, 4, ZSTD_lazy2 }, /* level 16 */
{ 0, 18, 18, 18, 10, 4, ZSTD_lazy2 }, /* level 17 */
{ 0, 18, 18, 18, 11, 4, ZSTD_lazy2 }, /* level 18 */
{ 0, 18, 18, 18, 12, 4, ZSTD_lazy2 }, /* level 19 */
{ 0, 18, 18, 18, 13, 4, ZSTD_lazy2 }, /* level 20 */
},
{ /* for srcSize <= 128 KB */
/* W, C, H, S, L, strat */
Expand Down
2 changes: 1 addition & 1 deletion programs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# fullbench32: Same as fullbench, but forced to compile in 32-bits mode
# ##########################################################################

VERSION?= 0.4.4
VERSION?= 0.4.5

DESTDIR?=
PREFIX ?= /usr/local
Expand Down
Loading

0 comments on commit ef774a6

Please sign in to comment.