nsis64 / Source / Tests / decompress.cpp

#include "decompress.h"

#include <string.h> // for memset

#define EXEHEAD
#define NSIS_CONFIG_COMPRESSION_SUPPORT

extern "C" {
#define NSIS_COMPRESS_USE_BZIP2
#include "../bzip2/bzlib.h"
#undef NSIS_COMPRESS_USE_BZIP2

#define NSIS_COMPRESS_USE_LZMA
#include "../7zip/LZMADecode.h"
#undef NSIS_COMPRESS_USE_LZMA

#define NSIS_COMPRESS_USE_ZLIB
#include "../zlib/ZLIB.H"
#undef NSIS_COMPRESS_USE_ZLIB
}

#define DECOMPRESSOR(name, type, initf, dec, u)   \
  name::name() {                                  \
    vs = new type;                                \
    memset(vs, 0, sizeof(type));                  \
  }                                               \
                                                  \
  name::~name() {                                 \
    delete (type *) vs;                           \
    vs = 0;                                       \
  }                                               \
                                                  \
  void name::setNextIn(void *buffer, int size) {  \
    type *s = (type *) vs;                        \
    s->next_in = (u *) buffer;                    \
    s->avail_in = size;                           \
  }                                               \
                                                  \
  void name::setNextOut(void *buffer, int size) { \
    type *s = (type *) vs;                        \
    s->next_out = (u *) buffer;                   \
    s->avail_out = size;                          \
  }                                               \
                                                  \
  int name::getAvailOut() {                       \
    type *s = (type *) vs;                        \
    return s->avail_out;                          \
  }                                               \
                                                  \
  void name::init() {                             \
    type *s = (type *) vs;                        \
    initf(s);                                     \
  }                                               \
                                                  \
  int name::decompress() {                        \
    type *s = (type *) vs;                        \
    return dec(s);                                \
  }

DECOMPRESSOR(lzmaDecompressor, lzma_stream, lzmaInit, lzmaDecode, unsigned char);
DECOMPRESSOR(bzip2Decompressor, DState, BZ2_bzDecompressInit, BZ2_bzDecompress, char);
DECOMPRESSOR(zlibDecompressor, z_stream, inflateReset, inflate, unsigned char);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.