]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
edit README.md and remove simple_compressionCCtx.c
authorYi Jin <yijinru@gmail.com>
Mon, 17 Dec 2018 05:09:21 +0000 (21:09 -0800)
committerYi Jin <yijinru@gmail.com>
Mon, 17 Dec 2018 05:09:21 +0000 (21:09 -0800)
examples/.gitignore
examples/Makefile
examples/README.md
examples/simple_compressionCCtx.c [deleted file]

index c92c69897f3274330f8f7251d840d630d22548dd..d682cae38a8d076d4e0e563e29d007f041051d14 100644 (file)
@@ -1,7 +1,7 @@
 #build
 simple_compression
 simple_decompression
-simple_compressionCCtx
+multiple_simple_compression
 dictionary_compression
 dictionary_decompression
 streaming_compression
index 7af6176b1745a84817584487629f227ed0b167b4..25a0a62c2de6ab30afb0100a0a09c8b73b15a455 100644 (file)
@@ -17,7 +17,7 @@ LIB = ../lib/libzstd.a
 default: all
 
 all: simple_compression simple_decompression \
-       simple_compressionCCtx\
+       multiple_simple_compression\
        dictionary_compression dictionary_decompression \
        streaming_compression streaming_decompression \
        multiple_streaming_compression streaming_memory_usage
@@ -31,7 +31,7 @@ simple_compression : simple_compression.c utils.h $(LIB)
 simple_decompression : simple_decompression.c utils.h $(LIB)
        $(CC) $(CPPFLAGS) $(CFLAGS) $< $(LIB) $(LDFLAGS) -o $@
 
-simple_compressionCCtx : simple_compressionCCtx.c utils.h $(LIB)
+multiple_simple_compression : multiple_simple_compression.c utils.h $(LIB)
        $(CC) $(CPPFLAGS) $(CFLAGS) $< $(LIB) $(LDFLAGS) -o $@
 
 dictionary_compression : dictionary_compression.c utils.h $(LIB)
@@ -55,7 +55,7 @@ streaming_memory_usage : streaming_memory_usage.c $(LIB)
 clean:
        @rm -f core *.o tmp* result* *.zst \
         simple_compression simple_decompression \
-       simple_compressionCCtx \
+        multiple_simple_compression \
         dictionary_compression dictionary_decompression \
         streaming_compression streaming_decompression \
         multiple_streaming_compression streaming_memory_usage
@@ -67,7 +67,7 @@ test: all
        @echo -- Simple compression tests
        ./simple_compression tmp
        ./simple_decompression tmp.zst
-       ./simple_compressionCCtx *.c
+       ./multiple_simple_compression *.c
        ./streaming_decompression tmp.zst > /dev/null
        @echo -- Streaming memory usage
        ./streaming_memory_usage
index eba50c9997da01915b5c17e847c751f9dbac45a4..0bff7ac19a29a9cd9cfb0184fbab752089d7bd59 100644 (file)
@@ -11,8 +11,14 @@ Zstandard library : usage examples
   Result remains in memory.
   Introduces usage of : `ZSTD_decompress()`
 
+- [Multiple simple compression](multiple_simple_compression.c) :
+  Compress multiple files (in simple mode) in a single command line.
+  Demonstrates memory preservation technique that
+  minimizes malloc()/free() calls by re-using existing resources.
+  Introduces usage of : `ZSTD_compressCCtx()`
+
 - [Streaming memory usage](streaming_memory_usage.c) :
-  Provides amount of memory used by streaming context
+  Provides amount of memory used by streaming context.
   Introduces usage of : `ZSTD_sizeof_CStream()`
 
 - [Streaming compression](streaming_compression.c) :
@@ -20,7 +26,7 @@ Zstandard library : usage examples
   Introduces usage of : `ZSTD_compressStream()`
 
 - [Multiple Streaming compression](multiple_streaming_compression.c) :
-  Compress multiple files in a single command line.
+  Compress multiple files (in streaming mode) in a single command line.
   Introduces memory usage preservation technique,
   reducing impact of malloc()/free() and memset() by re-using existing resources.
 
diff --git a/examples/simple_compressionCCtx.c b/examples/simple_compressionCCtx.c
deleted file mode 100644 (file)
index 00279e4..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under both the BSD-style license (found in the
- * LICENSE file in the root directory of this source tree) and the GPLv2 (found
- * in the COPYING file in the root directory of this source tree).
- * You may select, at your option, one of the above-listed licenses.
- */
-
-#include <stdlib.h>    // malloc, free, exit
-#include <stdio.h>     // fprintf, perror, fopen, etc.
-#include <string.h>    // strlen, strcat, memset, strerror
-#include <errno.h>     // errno
-#include <sys/stat.h>  // stat
-#include <zstd.h>      // presumes zstd library is installed
-#include "utils.h"
-
-/* compress with pre-allocated context (ZSTD_CCtx) and input/output buffers*/
-static void compressExpress_orDie(const char* fname, const char* oname,
-                                  ZSTD_CCtx* cctx, void* cBuff, size_t cBuffSize, void* fBuff, size_t fBuffSize)
-{
-    size_t fSize;
-    loadFile_orDie(fname, &fSize, fBuff, fBuffSize);
-
-    size_t const cSize = ZSTD_compressCCtx(cctx, cBuff, cBuffSize, fBuff, fSize, 1);
-    if (ZSTD_isError(cSize)) {
-        fprintf(stderr, "error compressing %s : %s \n", fname, ZSTD_getErrorName(cSize));
-        exit(8);
-    }
-
-    saveFile_orDie(oname, cBuff, cSize);
-
-    /* success */
-    printf("%25s : %6u -> %7u - %s \n", fname, (unsigned)fSize, (unsigned)cSize, oname);
-}
-
-static void getOutFilename(const char* const filename, char* const outFilename)
-{
-    memset(outFilename, 0, 1);
-    strcat(outFilename, filename);
-    strcat(outFilename, ".zst");
-}
-
-/* allocate memory for buffers big enough to compress all files
- * as well as memory for output file names (outFileName)
- */
-void allocMemory_orDie(int argc, const char** argv, char** outFilename,
-                       void** cBuffer, size_t* cBufferSize, void** fBuffer, size_t* fBufferSize) {
-    size_t maxFilenameLength=0;
-    size_t maxFileSize = 0;
-
-    int argNb;
-    for (argNb = 1; argNb < argc; argNb++) {
-      const char* const filename = argv[argNb];
-      size_t const filenameLength = strlen(filename);
-      size_t const fileSize = fsize_orDie(filename);
-
-      if (filenameLength > maxFilenameLength) maxFilenameLength = filenameLength;
-      if (fileSize > maxFileSize) maxFileSize = fileSize;
-    }
-    *cBufferSize = ZSTD_compressBound(maxFileSize);
-    *fBufferSize = maxFileSize;
-
-    /* allocate memory for output file name, input/output buffers for all compression tasks */
-    *outFilename = (char*)malloc_orDie(maxFilenameLength + 5);
-    *cBuffer = malloc_orDie(*cBufferSize);
-    *fBuffer = malloc_orDie(*fBufferSize);
-}
-
-int main(int argc, const char** argv)
-{
-    const char* const exeName = argv[0];
-
-    if (argc<2) {
-        printf("wrong arguments\n");
-        printf("usage:\n");
-        printf("%s FILE(s)\n", exeName);
-        return 1;
-    }
-
-    /* allocate memory for buffers big enough to compress all files
-     * as well as memory for output file name (outFileName)
-     *    fBuffer - buffer for input file data
-     *    cBuffer - buffer for compressed data 
-     */
-    char* outFilename;
-    void* fBuffer;
-    void* cBuffer;
-    size_t fBufferSize;
-    size_t cBufferSize;
-    allocMemory_orDie(argc, argv, &outFilename, &cBuffer, &cBufferSize, &fBuffer, &fBufferSize); 
-
-    /* create a compression context (ZSTD_CCtx) for all compression tasks */
-    ZSTD_CCtx* const cctx = ZSTD_createCCtx();
-    if (cctx==NULL) { fprintf(stderr, "ZSTD_createCCtx() error \n"); exit(10); }
-
-    /* compress files with shared context, input and output buffers */
-    int argNb;
-    for (argNb = 1; argNb < argc; argNb++) {
-      const char* const inFilename = argv[argNb];
-      getOutFilename(inFilename, outFilename);
-      compressExpress_orDie(inFilename, outFilename, cctx, cBuffer, cBufferSize, fBuffer, fBufferSize);
-    }
-
-    /* free momery resources */
-    free(outFilename);
-    free(fBuffer);
-    free(cBuffer);
-    ZSTD_freeCCtx(cctx);   /* never fails */
-
-    printf("compressed %i files \n", argc-1);
-
-    return 0;
-}