Debian Codegraph @

Source/czlib.h

raw
1 /*
2 * czlib.h
3 *
4 * This file is a part of NSIS.
5 *
6 * Copyright (C) 1999-2026 Nullsoft and Contributors
7 *
8 * Licensed under the zlib/libpng license (the "License");
9 * you may not use this file except in compliance with the License.
10 *
11 * Licence details can be found in the file COPYING.
12 *
13 * This software is provided 'as-is', without any express or implied
14 * warranty.
15 *
16 * Unicode support by Jim Park -- 08/24/2007
17 */
18
19 #ifndef __CZLIB_H__
20 #define __CZLIB_H__
21
22 #include "compressor.h"
23 #include <zlib.h>
24
25 class CZlib : public ICompressor {
26 public:
27 virtual ~CZlib() {}
28
29 virtual int Init(int level, unsigned int dict_size) {
30 stream = new z_stream;
31 if (!stream) return Z_MEM_ERROR;
32
33 stream->zalloc = (alloc_func)Z_NULL;
34 stream->zfree = (free_func)Z_NULL;
35 stream->opaque = (voidpf)Z_NULL;
36 return deflateInit2(stream, level,
37 Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY);
38 }
39
40 virtual int End() {
41 int ret = deflateEnd(stream);
42 delete stream;
43 return ret;
44 }
45
46 virtual int Compress(bool finish) {
47 return deflate(stream, finish?Z_FINISH:0);
48 }
49
50 virtual void SetNextIn(char *in, unsigned int size) {
51 stream->next_in = (unsigned char*)in;
52 stream->avail_in = size;
53 }
54
55 virtual void SetNextOut(char *out, unsigned int size) {
56 stream->next_out = (unsigned char*)out;
57 stream->avail_out = size;
58 }
59
60 virtual char* GetNextOut() {
61 return (char*)stream->next_out;
62 }
63
64 virtual unsigned int GetAvailIn() {
65 return stream->avail_in;
66 }
67
68 virtual unsigned int GetAvailOut() {
69 return stream->avail_out;
70 }
71
72 virtual const TCHAR* GetName() {
73 return _T("zlib");
74 }
75
76 virtual const TCHAR* GetErrStr(int err) {
77 switch (err)
78 {
79 case Z_STREAM_ERROR:
80 return _T("invalid stream - bad call");
81 case Z_DATA_ERROR:
82 return _T("data error");
83 case Z_MEM_ERROR:
84 return _T("not enough memory");
85 case Z_BUF_ERROR:
86 return _T("buffer error - bad call");
87 case Z_VERSION_ERROR:
88 return _T("version error");
89 default:
90 return _T("unknown error");
91 }
92 }
93
94 private:
95 z_stream *stream;
96 };
97
98 #endif