]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Reduced console display on loading lots of files with `zstd --train`. Reported by...
authorYann Collet <yann.collet.73@gmail.com>
Mon, 9 May 2016 02:44:45 +0000 (04:44 +0200)
committerYann Collet <yann.collet.73@gmail.com>
Mon, 9 May 2016 02:44:45 +0000 (04:44 +0200)
NEWS
lib/common/util.h
lib/legacy/zstd_v05.h
programs/dibio.c
programs/fileio.c

diff --git a/NEWS b/NEWS
index d4abd36f975421a72c08f3bf7e822ad598efe9bb..573310d711643e5b67ca77ffc4c888a11f3e1dcc 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+v0.6.1
+Fixed : Legacy codec v0.5 compatible with dictionary decompression
+Fixed : Decoder corruption error (#173)
+
 v0.6.0
 Stronger high compression modes, thanks to Przemyslaw Skibinski
 API : ZSTD_getFrameParams() provides size of decompressed content
index 1de1efd86e92d45c13d1b851e0808402bcb2e04b..186ecb9988dc5ad627f91f7c02f0a9708432f21a 100644 (file)
@@ -95,7 +95,6 @@ extern "C" {
 #endif
 
 
-
 /*-****************************************
 *  Utility functions
 ******************************************/
@@ -116,8 +115,8 @@ UTIL_STATIC void UTIL_waitForNextTick(UTIL_time_t ticksPerSecond)
     (void)ticksPerSecond;
 
     UTIL_getTime(clockStart);
-    do { 
-        UTIL_getTime(clockEnd); 
+    do {
+        UTIL_getTime(clockEnd);
     } while (UTIL_getSpanTimeNano(ticksPerSecond, clockStart, clockEnd) == 0);
 }
 
index 340a7a83028b257826639b526738f6b97c648f5a..8ef6bb25a21bf950c1906125a770370211d3f46e 100644 (file)
@@ -102,7 +102,7 @@ size_t ZSTDv05_decompressContinue(ZSTDv05_DCtx* dctx, void* dst, size_t dstCapac
 *************************/
 typedef struct ZBUFFv05_DCtx_s ZBUFFv05_DCtx;
 ZBUFFv05_DCtx* ZBUFFv05_createDCtx(void);
-size_t      ZBUFFv05_freeDCtx(ZBUFFv05_DCtx* dctx);
+size_t         ZBUFFv05_freeDCtx(ZBUFFv05_DCtx* dctx);
 
 size_t ZBUFFv05_decompressInit(ZBUFFv05_DCtx* dctx);
 size_t ZBUFFv05_decompressInitDictionary(ZBUFFv05_DCtx* dctx, const void* dict, size_t dictSize);
index fe947bd8af2369744ad3b0b44de5863f05352d6c..816a6565932d61efb5c149094b914537cdac8a5e 100644 (file)
@@ -76,6 +76,19 @@ static const size_t maxMemory = (sizeof(size_t) == 4) ? (2 GB - 64 MB) : ((size_
 #define DISPLAYLEVEL(l, ...) if (g_displayLevel>=l) { DISPLAY(__VA_ARGS__); }
 static unsigned g_displayLevel = 0;   /* 0 : no display;   1: errors;   2: default;  4: full information */
 
+#define DISPLAYUPDATE(l, ...) if (g_displayLevel>=l) { \
+            if ((DIB_GetMilliSpan(g_time) > refreshRate) || (g_displayLevel>=4)) \
+            { g_time = clock(); DISPLAY(__VA_ARGS__); \
+            if (g_displayLevel>=4) fflush(stdout); } }
+static const unsigned refreshRate = 150;
+static clock_t g_time = 0;
+
+static unsigned DIB_GetMilliSpan(clock_t nPrevious)
+{
+    clock_t const nCurrent = clock();
+    return (unsigned)(((nCurrent - nPrevious) * 1000) / CLOCKS_PER_SEC);
+}
+
 
 /*-*************************************
 *  Exceptions
@@ -118,7 +131,7 @@ static void DiB_loadFiles(void* buffer, size_t bufferSize,
         unsigned long long fileSize = UTIL_getFileSize(fileNamesTable[n]);
         FILE* f = fopen(fileNamesTable[n], "rb");
         if (f==NULL) EXM_THROW(10, "impossible to open file %s", fileNamesTable[n]);
-        DISPLAYLEVEL(2, "Loading %s...       \r", fileNamesTable[n]);
+        DISPLAYUPDATE(2, "Loading %s...       \r", fileNamesTable[n]);
         if (fileSize > bufferSize-pos) fileSize = 0;  /* stop there, not enough memory to load all files */
         readSize = fread(buff+pos, 1, (size_t)fileSize, f);
         if (readSize != (size_t)fileSize) EXM_THROW(11, "could not read %s", fileNamesTable[n]);
@@ -166,17 +179,14 @@ static void DiB_fillNoise(void* buffer, size_t length)
 static void DiB_saveDict(const char* dictFileName,
                          const void* buff, size_t buffSize)
 {
-    FILE* f;
-    size_t n;
-
-    f = fopen(dictFileName, "wb");
+    FILE* f = fopen(dictFileName, "wb");
     if (f==NULL) EXM_THROW(3, "cannot open %s ", dictFileName);
 
-    n = fwrite(buff, 1, buffSize, f);
-    if (n!=buffSize) EXM_THROW(4, "%s : write error", dictFileName)
+    { size_t const n = fwrite(buff, 1, buffSize, f);
+      if (n!=buffSize) EXM_THROW(4, "%s : write error", dictFileName) }
 
-    n = (size_t)fclose(f);
-    if (n!=0) EXM_THROW(5, "%s : flush error", dictFileName)
+    { size_t const n = (size_t)fclose(f);
+      if (n!=0) EXM_THROW(5, "%s : flush error", dictFileName) }
 }
 
 
index aeb34847d6fcab7424acbd585bb51ac452c4545d..9433dbeed1eb8bbbf420842e3616aede4b8d82c0 100644 (file)
@@ -126,6 +126,11 @@ void FIO_setNotificationLevel(unsigned level) { g_displayLevel=level; }
 static const unsigned refreshRate = 150;
 static clock_t g_time = 0;
 
+static unsigned FIO_GetMilliSpan(clock_t nPrevious)
+{
+    clock_t const nCurrent = clock();
+    return (unsigned)(((nCurrent - nPrevious) * 1000) / CLOCKS_PER_SEC);
+}
 
 
 /*-*************************************
@@ -157,14 +162,6 @@ void FIO_setMaxWLog(unsigned maxWLog) { g_maxWLog = maxWLog; }
 /*-*************************************
 *  Functions
 ***************************************/
-static unsigned FIO_GetMilliSpan(clock_t nPrevious)
-{
-    clock_t nCurrent = clock();
-    unsigned nSpan = (unsigned)(((nCurrent - nPrevious) * 1000) / CLOCKS_PER_SEC);
-    return nSpan;
-}
-
-
 static FILE* FIO_openSrcFile(const char* srcFileName)
 {
     FILE* f;