File: czlib.h

package info (click to toggle)
nsis 3.08-3%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 12,952 kB
  • sloc: cpp: 38,735; ansic: 27,199; python: 1,352; asm: 712; xml: 409; pascal: 215; makefile: 211; javascript: 67
file content (98 lines) | stat: -rwxr-xr-x 2,260 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * czlib.h
 * 
 * This file is a part of NSIS.
 * 
 * Copyright (C) 1999-2021 Nullsoft and Contributors
 * 
 * Licensed under the zlib/libpng license (the "License");
 * you may not use this file except in compliance with the License.
 * 
 * Licence details can be found in the file COPYING.
 * 
 * This software is provided 'as-is', without any express or implied
 * warranty.
 *
 * Unicode support by Jim Park -- 08/24/2007
 */

#ifndef __CZLIB_H__
#define __CZLIB_H__

#include "compressor.h"
#include <zlib.h>

class CZlib : public ICompressor {
  public:
    virtual ~CZlib() {}

    virtual int Init(int level, unsigned int dict_size) {
      stream = new z_stream;
      if (!stream) return Z_MEM_ERROR;

      stream->zalloc = (alloc_func)Z_NULL;
      stream->zfree = (free_func)Z_NULL;
      stream->opaque = (voidpf)Z_NULL;
      return deflateInit2(stream, level,
        Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY);
    }

    virtual int End() {
      int ret = deflateEnd(stream);
      delete stream;
      return ret;
    }

    virtual int Compress(bool finish) {
      return deflate(stream, finish?Z_FINISH:0);
    }

    virtual void SetNextIn(char *in, unsigned int size) {
      stream->next_in = (unsigned char*)in;
      stream->avail_in = size;
    }

    virtual void SetNextOut(char *out, unsigned int size) {
      stream->next_out = (unsigned char*)out;
      stream->avail_out = size;
    }

    virtual char* GetNextOut() {
      return (char*)stream->next_out;
    }

    virtual unsigned int GetAvailIn() {
      return stream->avail_in;
    }

    virtual unsigned int GetAvailOut() {
      return stream->avail_out;
    }

    virtual const TCHAR* GetName() {
      return _T("zlib");
    }

    virtual const TCHAR* GetErrStr(int err) {
      switch (err)
      {
      case Z_STREAM_ERROR:
        return _T("invalid stream - bad call");
      case Z_DATA_ERROR:
        return _T("data error");
      case Z_MEM_ERROR:
        return _T("not enough memory");
      case Z_BUF_ERROR:
        return _T("buffer error - bad call");
      case Z_VERSION_ERROR:
        return _T("version error");
      default:
        return _T("unknown error");
      }
    }

  private:
    z_stream *stream;
};

#endif