sprint 1-alpha
sprint/io/xstream/xgzipfilter.h
Go to the documentation of this file.
00001 /******************************************************************************
00002 *   sprint::xgzip
00003 *
00004 *   Copyright (C) 2005-2011  Paolo Medici <www.pmx.it>
00005 *
00006 *  This library is free software; you can redistribute it and/or
00007 *  modify it under the terms of the GNU Lesser General Public
00008 *  License as published by the Free Software Foundation; either
00009 *  version 2.1 of the License, or (at your option) any later version.
00010 *
00011 *  This library is distributed in the hope that it will be useful,
00012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 *  Lesser General Public License for more details.
00015 *
00016 *  You should have received a copy of the GNU Lesser General Public
00017 *  License along with this library; if not, write to the Free Software
00018 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019 *
00020 *******************************************************************************/
00021 #ifndef _XSTREAM_GZIP_FILTER_H
00022 #define _XSTREAM_GZIP_FILTER_H
00023 
00027 #include <sprint/io/xstream/xstream.h>
00028 #include <zlib.h>
00029 
00030 namespace sprint {
00031   namespace io {
00032 
00034 class gzipf: public xstream {
00036         static const unsigned int BufferSize = 65536 - 256;
00037         
00038         xstream * m_stream;   
00039         int m_mode;           
00040         bool opened;          
00041         
00042         long out_size;     
00043     long in_size;       
00044 
00045         long cur_file_ptr;  
00046         unsigned int crc16; 
00047     unsigned long crc32; 
00048         char b[BufferSize]; 
00049         
00050         z_stream stream;  
00051         
00052         private:
00053         void skip(unsigned int len);
00054         int get(void);
00055         unsigned int get_word(void);
00056     void put_long(unsigned int);
00057         std::string get_string(void);
00058         bool read_header(void);
00059     void write_header(void);
00060         int decode_buffer(char *ptr, unsigned int len);
00061     int flush(void);
00062     bool do_flush(int f);
00063         public:
00064         gzipf(xstream * stream, flag_t open_mode, unsigned int compression_level);
00065         ~gzipf();
00066         bool is_good() const { return opened; }
00067         unsigned int capabilities() const;
00069         state_t state();        
00070         file_size_t length();
00071         file_size_t seek(file_size_t offset, seek_t type);
00073         int write(const char *data, unsigned int size);
00074         int read(char *data, unsigned int size);
00075                 
00076 };
00077 
00078 } 
00079 }
00080 
00081 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines