1 /**************************************************************************/ 2 /* */ 3 /* Copyright (c) 2001, 2011 NoMachine (http://www.nomachine.com) */ 4 /* Copyright (c) 2008-2014 Oleksandr Shneyder <o.shneyder@phoca-gmbh.de> */ 5 /* Copyright (c) 2014-2016 Ulrich Sibiller <uli42@gmx.de> */ 6 /* Copyright (c) 2014-2016 Mihai Moldovan <ionic@ionic.de> */ 7 /* Copyright (c) 2011-2016 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>*/ 8 /* Copyright (c) 2015-2016 Qindel Group (http://www.qindel.com) */ 9 /* */ 10 /* NXCOMP, NX protocol compression and NX extensions to this software */ 11 /* are copyright of the aforementioned persons and companies. */ 12 /* */ 13 /* Redistribution and use of the present software is allowed according */ 14 /* to terms specified in the file LICENSE.nxcomp which comes in the */ 15 /* source distribution. */ 16 /* */ 17 /* All rights reserved. */ 18 /* */ 19 /* NOTE: This software has received contributions from various other */ 20 /* contributors, only the core maintainers and supporters are listed as */ 21 /* copyright holders. Please contact us, if you feel you should be listed */ 22 /* as copyright holder, as well. */ 23 /* */ 24 /**************************************************************************/ 25 26 #ifndef StaticCompressor_H 27 #define StaticCompressor_H 28 29 #include "Z.h" 30 31 class EncodeBuffer; 32 class DecodeBuffer; 33 34 class StaticCompressor 35 { 36 public: 37 38 StaticCompressor(int compressionLevel, int compressionThreshold); 39 40 ~StaticCompressor(); 41 42 int compressBuffer(const unsigned char *plainBuffer, const unsigned int plainSize, 43 unsigned char *&compressedBuffer, unsigned int &compressedSize, 44 EncodeBuffer &encodeBuffer); 45 46 int compressBuffer(const unsigned char *plainBuffer, const unsigned int plainSize, 47 unsigned char *&compressedBuffer, unsigned int &compressedSize); 48 49 int decompressBuffer(unsigned char *plainBuffer, unsigned int plainSize, 50 const unsigned char *&compressedBuffer, unsigned int &compressedSize, 51 DecodeBuffer &decodeBuffer); 52 53 int decompressBuffer(unsigned char *plainBuffer, const unsigned int plainSize, 54 const unsigned char *compressedBuffer, const unsigned compressedSize); 55 isCompressionLevel(int compressionLevel)56 static int isCompressionLevel(int compressionLevel) 57 { 58 return (compressionLevel == Z_DEFAULT_COMPRESSION || 59 (compressionLevel >= Z_NO_COMPRESSION && 60 compressionLevel <= Z_BEST_COMPRESSION)); 61 } 62 fullReset()63 int fullReset() 64 { 65 return (deflateReset(&compressionStream_) == Z_OK && 66 inflateReset(&decompressionStream_) == Z_OK); 67 } 68 69 private: 70 71 z_stream compressionStream_; 72 z_stream decompressionStream_; 73 74 unsigned char *buffer_; 75 unsigned int bufferSize_; 76 77 int threshold_; 78 }; 79 80 #endif 81