unsigned reserved[3];
} LZ4F_decompressOptions_t;
+
/* Resource management */
LZ4F_errorCode_t LZ4F_createDecompressionContext(LZ4F_decompressionContext_t* ctxPtr, unsigned version);
* Object can release its memory using LZ4F_freeDecompressionContext();
*/
+
/* Decompression */
size_t LZ4F_getFrameInfo(LZ4F_decompressionContext_t ctx,
* LZ4F_getFrameInfo() can also be used *after* starting decompression, on a valid LZ4F_decompressionContext_t.
* The number of bytes read from srcBuffer will be provided within *srcSizePtr (necessarily <= original value).
* You are expected to resume decompression from where it stopped (srcBuffer + *srcSizePtr)
- * The function result is an hint of the better srcSize to use for next call to LZ4F_decompress,
+ * The function result is an hint of how many srcSize bytes LZ4F_decompress() expects for next call,
* or an error code which can be tested using LZ4F_isError().
*/
*
* The number of bytes regenerated into dstBuffer will be provided within *dstSizePtr (necessarily <= original value).
*
- * The number of bytes effectively used from srcBuffer will be provided within *srcSizePtr (necessarily <= original value).
- * If the number of bytes read is < number of bytes provided, then the decompression operation is not complete.
- * This typically happens when dstBuffer is not large enough to contain all decoded data.
- * LZ4F_decompress() will have to be called again, starting from where it stopped (srcBuffer + *srcSizePtr)
+ * The number of bytes read from srcBuffer will be provided within *srcSizePtr (necessarily <= original value).
+ * If number of bytes read is < number of bytes provided, then decompression operation is not completed.
+ * It typically happens when dstBuffer is not large enough to contain all decoded data.
+ * LZ4F_decompress() must be called again, starting from where it stopped (srcBuffer + *srcSizePtr)
* The function will check this condition, and refuse to continue if it is not respected.
- * dstBuffer is supposed to be flushed between calls to the function, since its content will be rewritten.
- * Different dst arguments can be used between each calls.
*
- * The function result is an hint of the better srcSize to use for next call to LZ4F_decompress.
- * Basically, it's the size of the current (or remaining) compressed block + header of next block.
- * Respecting the hint provides some boost to performance, since it does not need intermediate buffers.
+ * dstBuffer is supposed to be flushed between each call to the function, since its content will be overwritten.
+ * dst arguments can be changed at will with each consecutive call to the function.
+ *
+ * The function result is an hint of how many srcSize bytes LZ4F_decompress() expects for next call.
+ * Schematically, it's the size of the current (or remaining) compressed block + header of next block.
+ * Respecting the hint provides some boost to performance, since it does skip intermediate buffers.
* This is just a hint, you can always provide any srcSize you want.
- * When a frame is fully decoded, the function result will be 0.
- * If decompression failed, function result is an error code which can be tested using LZ4F_isError().
+ * When a frame is fully decoded, the function result will be 0. (no more data expected)
+ * If decompression failed, function result is an error code, which can be tested using LZ4F_isError().
*/
/**************************************
Tuning Parameter
**************************************/
-#define LZ4HC_DEFAULT_COMPRESSIONLEVEL 8
+static const int LZ4HC_compressionLevel_default = 8;
/**************************************
Includes
**************************************/
-#include "lz4.h"
#include "lz4hc.h"
#define OPTIMAL_ML (int)((ML_MASK-1)+MINMATCH)
+static const int g_maxCompressionLevel = 16;
+
/**************************************
Local Types
}
-#define MAX_COMPRESSION_LEVEL 16
static int LZ4HC_compress_generic (
void* ctxvoid,
const char* source,
/* init */
- if (compressionLevel > MAX_COMPRESSION_LEVEL) compressionLevel = MAX_COMPRESSION_LEVEL;
- if (compressionLevel == 0) compressionLevel = LZ4HC_DEFAULT_COMPRESSIONLEVEL;
- maxNbAttempts = 1 << compressionLevel;
+ if (compressionLevel > g_maxCompressionLevel) compressionLevel = g_maxCompressionLevel;
+ if (compressionLevel < 1) compressionLevel = LZ4HC_compressionLevel_default;
+ maxNbAttempts = 1 << (compressionLevel-1);
ctx->end += inputSize;
ip++;
# define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
#endif
-// GCC does not support _rotl outside of Windows
-#if !defined(_WIN32)
-# define _rotl(x,r) ((x << r) | (x >> (32 - r)))
-#endif
-
//**************************************
// Basic Types
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
You can contact the author at :
- - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
- LZ4 source repository : http://code.google.com/p/lz4/
+ - LZ4 public forum : https://group.google.com/forum/#!forum/lz4c
*/
#pragma once
#endif
+/* Main function */
int BMK_benchFile(char** fileNamesTable, int nbFiles, int cLevel);
-// Parameters
+/* Set Parameters */
void BMK_SetBlocksize(int bsize);
void BMK_SetNbIterations(int nbLoops);
void BMK_SetPause(void);
/*
- LZ4cli.c - LZ4 Command Line Interface
+ LZ4cli - LZ4 Command Line Interface
Copyright (C) Yann Collet 2011-2014
+
GPL v2 License
This program is free software; you can redistribute it and/or modify
// Includes
//****************************
#include <stdio.h> // fprintf, fopen, fread, _fileno, stdin, stdout
-#include <stdlib.h> // malloc
+#include <stdlib.h> // exit, calloc, free
#include <string.h> // strcmp, strlen
-#include <time.h> // clock
-#include "lz4.h"
-#include "lz4hc.h"
-#include "xxhash.h"
-#include "bench.h"
+#include "bench.h" // BMK_benchFile, BMK_SetNbIterations, BMK_SetBlocksize, BMK_SetPause
#include "lz4io.h"
#endif
-//**************************************
-// Compiler-specific functions
-//**************************************
-#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
-
-#if defined(_MSC_VER) // Visual Studio
-# define swap32 _byteswap_ulong
-#elif (GCC_VERSION >= 403) || defined(__clang__)
-# define swap32 __builtin_bswap32
-#else
- static inline unsigned int swap32(unsigned int x)
- {
- return ((x << 24) & 0xff000000 ) |
- ((x << 8) & 0x00ff0000 ) |
- ((x >> 8) & 0x0000ff00 ) |
- ((x >> 24) & 0x000000ff );
- }
-#endif
-
-
//****************************
// Constants
//****************************
-#define COMPRESSOR_NAME "LZ4 Compression CLI"
+#define COMPRESSOR_NAME "LZ4 command line interface"
#ifndef LZ4_VERSION
# define LZ4_VERSION "r125"
#endif
//**************************************
// Macros
//**************************************
-#define DISPLAY(...) fprintf(stderr, __VA_ARGS__)
-#define DISPLAYLEVEL(l, ...) if (displayLevel>=l) { DISPLAY(__VA_ARGS__); }
+#define DISPLAY(...) fprintf(stderr, __VA_ARGS__)
+#define DISPLAYLEVEL(l, ...) if (displayLevel>=l) { DISPLAY(__VA_ARGS__); }
+static unsigned displayLevel = 2; // 0 : no display // 1: errors // 2 : + result + interaction + warnings ; // 3 : + progression; // 4 : + information
//**************************************
-// Local Parameters
+// Local Variables
//**************************************
static char* programName;
-static int displayLevel = 2; // 0 : no display // 1: errors // 2 : + result + interaction + warnings ; // 3 : + progression; // 4 : + information
//**************************************
DISPLAY( " -l : compress using Legacy format (Linux kernel compression)\n");
DISPLAY( " -B# : Block size [4-7](default : 7)\n");
DISPLAY( " -BD : Block dependency (improve compression ratio)\n");
- DISPLAY( " -BX : enable block checksum (default:disabled)\n");
+ //DISPLAY( " -BX : enable block checksum (default:disabled)\n"); // Option currently inactive
DISPLAY( " -Sx : disable stream checksum (default:enabled)\n");
DISPLAY( "Benchmark arguments :\n");
DISPLAY( " -b : benchmark file(s)\n");
{
if (legacy_format)
{
- DISPLAYLEVEL(3, "! Generating compressed LZ4 using Legacy format (deprecated !) ! \n");
+ DISPLAYLEVEL(3, "! Generating compressed LZ4 using Legacy format (deprecated) ! \n");
LZ4IO_compressFilename_Legacy(input_filename, output_filename, cLevel);
}
else
static const int minBlockSizeID = 4;
static const int maxBlockSizeID = 7;
+
//**************************************
// Exceptions
//**************************************
static unsigned LZ4IO_GetMilliSpan(clock_t nPrevious)
{
-#define CLOCKS_PER_MSEC (CLOCKS_PER_SEC/1000)
clock_t nCurrent = clock();
- unsigned nSpan = (unsigned)((nCurrent - nPrevious) / CLOCKS_PER_MSEC);
+ unsigned nSpan = (unsigned)(((nCurrent - nPrevious) * 1000) / CLOCKS_PER_SEC);
return nSpan;
}
unsigned long long filesize = 0;
char* in_buff;
char* out_buff;
- unsigned int blockSize;
// Allocate Memory
in_buff = (char*)malloc(LZ4_compressBound(LEGACY_BLOCKSIZE));
{
int decodeSize;
size_t sizeCheck;
+ unsigned int blockSize;
// Block Size
sizeCheck = fread(in_buff, 1, 4, finput);