Disk ARchive
2.3.11
|
00001 /*********************************************************************/ 00002 // dar - disk archive - a backup/restoration program 00003 // Copyright (C) 2002-2052 Denis Corbin 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 // 00019 // to contact the author : dar.linux@free.fr 00020 /*********************************************************************/ 00021 // $Id: compressor.hpp,v 1.12.4.3 2009/05/14 17:33:39 edrusb Rel $ 00022 // 00023 /*********************************************************************/ 00026 00027 #ifndef COMPRESSOR_HPP 00028 #define COMPRESSOR_HPP 00029 00030 #include "../my_config.h" 00031 00032 #include "infinint.hpp" 00033 #include "generic_file.hpp" 00034 #include "integers.hpp" 00035 #include "wrapperlib.hpp" 00036 00037 namespace libdar 00038 { 00039 00041 00044 enum compression 00045 { 00046 none = 'n', 00047 zip = 'p', 00048 gzip = 'z', 00049 bzip2 = 'y' 00050 }; 00051 00052 extern compression char2compression(char a); 00053 extern char compression2char(compression c); 00054 extern std::string compression2string(compression c); 00055 00057 class compressor : public generic_file 00058 { 00059 public : 00060 compressor(user_interaction & dialog, compression algo, generic_file & compressed_side, U_I compression_level = 9); 00061 // compressed_side is not owned by the object and will remains 00062 // after the objet destruction 00063 00064 compressor(user_interaction & dialog, compression algo, generic_file *compressed_side, U_I compression_level = 9); 00065 // compressed_side is owned by the object and will be 00066 // deleted a destructor time 00067 00068 ~compressor(); 00069 00070 void flush_write(); // flush all data to compressed_side, and reset the compressor 00071 // for that additional write can be uncompresssed starting at this point. 00072 void flush_read(); // reset decompression engine to be able to read the next block of compressed data 00073 // if not called, furthur read return EOF 00074 void clean_read(); // discard any byte buffered and not yet returned by read() 00075 void clean_write(); // discard any byte buffered and not yet wrote to compressed_side; 00076 00077 compression get_algo() const { return current_algo; }; 00078 00080 00085 void change_algo(compression new_algo, U_I new_compression_level); 00086 00087 00089 00090 void change_algo(compression new_algo) 00091 { 00092 change_algo(new_algo, current_level); 00093 }; 00094 00095 // inherited from generic file 00096 bool skip(const infinint & position) { flush_write(); flush_read(); clean_read(); return compressed->skip(position); }; 00097 bool skip_to_eof() { flush_write(); flush_read(); clean_read(); return compressed->skip_to_eof(); }; 00098 bool skip_relative(S_I x) { flush_write(); flush_read(); clean_read(); return compressed->skip_relative(x); }; 00099 infinint get_position() { return compressed->get_position(); }; 00100 00101 protected : 00102 S_I inherited_read(char *a, size_t size) { return (this->*read_ptr)(a, size); }; 00103 S_I inherited_write(const char *a, size_t size) { return (this->*write_ptr)(a, size); }; 00104 00105 private : 00106 struct xfer 00107 { 00108 wrapperlib wrap; 00109 char *buffer; 00110 U_I size; 00111 00112 xfer(U_I sz, wrapperlib_mode mode); 00113 ~xfer(); 00114 }; 00115 00116 xfer *compr, *decompr; 00117 generic_file *compressed; 00118 bool compressed_owner; 00119 compression current_algo; 00120 U_I current_level; 00121 00122 void init(compression algo, generic_file *compressed_side, U_I compression_level); 00123 void terminate(); 00124 S_I (compressor::*read_ptr) (char *a, size_t size); 00125 S_I none_read(char *a, size_t size); 00126 S_I gzip_read(char *a, size_t size); 00127 // S_I zip_read(char *a, size_t size); 00128 // S_I bzip2_read(char *a, size_t size); // using gzip_read, same code thanks to wrapperlib 00129 00130 S_I (compressor::*write_ptr) (const char *a, size_t size); 00131 S_I none_write(const char *a, size_t size); 00132 S_I gzip_write(const char *a, size_t size); 00133 // S_I zip_write(char *a, size_t size); 00134 // S_I bzip2_write(char *a, size_t size); // using gzip_write, same code thanks to wrapperlib 00135 }; 00136 00137 } // end of namespace 00138 00139 #endif