AbZip  1.0.0
Compressor.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 Andy Bray
4 **
5 ** This file is part of AbZip.
6 **
7 ** AbZip is free software: you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation, either version 3 of the License, or
10 ** (at your option) any later version.
11 **
12 ** AbZip is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU General Public License
18 ** along with AbZip. If not, see <http://www.gnu.org/licenses/>.
19 **
20 ****************************************************************************/
21 
22 #ifndef COMPRESSOR_H
23 #define COMPRESSOR_H
24 
25 #include "encryption.h"
26 
27 #include <QIODevice>
28 
29 #define DEFAULT_BUFSIZE (16384)
30 
32 enum tMethod
33 {
34  methodStore = 0,
35  methodDeflate = 8
36 #ifdef USE_BZIP2
37  ,methodBzip2 = 12
38 #endif
39 };
40 
41 
43 {
44 public:
45  explicit Compressor(QIODevice* inDev, QIODevice* outDev);
46  virtual ~Compressor();
47 
48  enum ErrorCode
49  {
50  Ok,
51  ZlibInitFailed,
52  ZlibEndFailed,
53  ZlibError,
54  ReadFailed,
55  WriteFailed,
56  UnknownError
57  };
58 
59  static Compressor* createCompressor( quint32 Type, int level, QIODevice* inDev, QIODevice* outDev = 0 );
60  static Compressor* createDecompressor( quint32 Type, QIODevice* inDev, QIODevice* outDev = 0 );
61 
62 
63  virtual bool compressData( Encryption* = 0){ return false; }
64  virtual bool decompressData( qint64, Encryption* = 0){ return false; }
65 
66 
67  bool setError( int err, QString msg = QString() ){ error = err; errorMessage = msg; return false;}
68  QString errorString( ){ return errorMessage; }
69 
70  quint32 crc;
71  quint64 compressedSize;
72  quint64 uncompressedSize;
73 
74  void checkIfBinary( char* , quint32 );
75  bool isAscii;
76 
77 protected:
78 
79 
80  QIODevice* inDevice;
81  QIODevice* outDevice;
82 
83  char *inBuffer; // Buffer for reading data
84  char *outBuffer; // Buffer for writing data
85 
86  int error;
87  QString errorMessage;
88 };
89 
90 #endif // COMPRESSOR_H
Definition: Compressor.h:42
Definition: encryption.h:40