2006-10-28 19:45:02 +00:00
|
|
|
/*
|
|
|
|
* czlib.h
|
|
|
|
*
|
|
|
|
* This file is a part of NSIS.
|
|
|
|
*
|
2021-01-01 20:27:52 +00:00
|
|
|
* Copyright (C) 1999-2021 Nullsoft and Contributors
|
2006-10-28 19:45:02 +00:00
|
|
|
*
|
|
|
|
* 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.
|
2010-03-24 17:22:56 +00:00
|
|
|
*
|
|
|
|
* Unicode support by Jim Park -- 08/24/2007
|
2006-10-28 19:45:02 +00:00
|
|
|
*/
|
|
|
|
|
2002-08-02 10:01:35 +00:00
|
|
|
#ifndef __CZLIB_H__
|
|
|
|
#define __CZLIB_H__
|
|
|
|
|
|
|
|
#include "compressor.h"
|
2010-02-07 21:24:09 +00:00
|
|
|
#include <zlib.h>
|
2002-08-02 10:01:35 +00:00
|
|
|
|
|
|
|
class CZlib : public ICompressor {
|
|
|
|
public:
|
2006-04-28 13:23:29 +00:00
|
|
|
virtual ~CZlib() {}
|
|
|
|
|
2015-09-19 18:54:02 +00:00
|
|
|
virtual int Init(int level, unsigned int dict_size) {
|
2002-08-02 10:01:35 +00:00
|
|
|
stream = new z_stream;
|
|
|
|
if (!stream) return Z_MEM_ERROR;
|
2010-02-07 21:24:09 +00:00
|
|
|
|
|
|
|
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);
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 18:54:02 +00:00
|
|
|
virtual int End() {
|
2002-08-02 10:01:35 +00:00
|
|
|
int ret = deflateEnd(stream);
|
|
|
|
delete stream;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-09-19 18:54:02 +00:00
|
|
|
virtual int Compress(bool finish) {
|
2002-08-02 10:01:35 +00:00
|
|
|
return deflate(stream, finish?Z_FINISH:0);
|
|
|
|
}
|
|
|
|
|
2015-09-19 18:54:02 +00:00
|
|
|
virtual void SetNextIn(char *in, unsigned int size) {
|
2002-08-02 10:01:35 +00:00
|
|
|
stream->next_in = (unsigned char*)in;
|
|
|
|
stream->avail_in = size;
|
|
|
|
}
|
|
|
|
|
2015-09-19 18:54:02 +00:00
|
|
|
virtual void SetNextOut(char *out, unsigned int size) {
|
2002-08-02 10:01:35 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-09-19 18:54:02 +00:00
|
|
|
virtual const TCHAR* GetName() {
|
2010-03-24 17:22:56 +00:00
|
|
|
return _T("zlib");
|
2003-02-07 23:04:25 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 18:54:02 +00:00
|
|
|
virtual const TCHAR* GetErrStr(int err) {
|
2004-05-08 17:40:29 +00:00
|
|
|
switch (err)
|
|
|
|
{
|
|
|
|
case Z_STREAM_ERROR:
|
2010-03-24 17:22:56 +00:00
|
|
|
return _T("invalid stream - bad call");
|
2004-05-08 17:40:29 +00:00
|
|
|
case Z_DATA_ERROR:
|
2010-03-24 17:22:56 +00:00
|
|
|
return _T("data error");
|
2004-05-08 17:40:29 +00:00
|
|
|
case Z_MEM_ERROR:
|
2010-03-24 17:22:56 +00:00
|
|
|
return _T("not enough memory");
|
2004-05-08 17:40:29 +00:00
|
|
|
case Z_BUF_ERROR:
|
2010-03-24 17:22:56 +00:00
|
|
|
return _T("buffer error - bad call");
|
2004-05-08 17:40:29 +00:00
|
|
|
case Z_VERSION_ERROR:
|
2010-03-24 17:22:56 +00:00
|
|
|
return _T("version error");
|
2004-05-08 17:40:29 +00:00
|
|
|
default:
|
2010-03-24 17:22:56 +00:00
|
|
|
return _T("unknown error");
|
2004-05-08 17:40:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-02 10:01:35 +00:00
|
|
|
private:
|
|
|
|
z_stream *stream;
|
|
|
|
};
|
|
|
|
|
2004-03-12 20:43:54 +00:00
|
|
|
#endif
|