• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kioslave

kbzip2filter.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2000 David Faure <faure@kde.org>
00003 
00004    $Id: kbzip2filter.cpp 465272 2005-09-29 09:47:40Z mueller $
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License version 2 as published by the Free Software Foundation.
00009 
00010    This library 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 GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <config.h>
00022 
00023 #if defined( HAVE_BZIP2_SUPPORT )
00024 
00025 // we don't need that
00026 #define BZ_NO_STDIO
00027 extern "C" {
00028     #include <bzlib.h>
00029 }
00030 
00031 #ifdef NEED_BZ2_PREFIX
00032         #define bzDecompressInit(x,y,z) BZ2_bzDecompressInit(x,y,z)
00033         #define bzDecompressEnd(x) BZ2_bzDecompressEnd(x)
00034         #define bzCompressEnd(x)  BZ2_bzCompressEnd(x)
00035         #define bzDecompress(x) BZ2_bzDecompress(x)
00036         #define bzCompress(x,y) BZ2_bzCompress(x, y)
00037         #define bzCompressInit(x,y,z,a) BZ2_bzCompressInit(x, y, z, a);
00038 #endif
00039 
00040 #include <kdebug.h>
00041 #include <klibloader.h>
00042 
00043 #include "kbzip2filter.h"
00044 
00045 // For docu on this, see /usr/doc/bzip2-0.9.5d/bzip2-0.9.5d/manual_3.html
00046 
00047 class KBzip2FilterFactory : public KLibFactory
00048 {
00049 public:
00050     KBzip2FilterFactory() : KLibFactory() {}
00051     virtual ~KBzip2FilterFactory(){}
00052     QObject *createObject( QObject *, const char *, const char*, const QStringList & )
00053     {
00054         return new KBzip2Filter;
00055     }
00056 };
00057 
00058 K_EXPORT_COMPONENT_FACTORY( kbzip2filter, KBzip2FilterFactory )
00059 
00060 // Not really useful anymore
00061 class KBzip2Filter::KBzip2FilterPrivate
00062 {
00063 public:
00064     bz_stream zStream;
00065 };
00066 
00067 KBzip2Filter::KBzip2Filter()
00068 {
00069     d = new KBzip2FilterPrivate;
00070     d->zStream.bzalloc = 0;
00071     d->zStream.bzfree = 0;
00072     d->zStream.opaque = 0;
00073     m_mode = 0;
00074 }
00075 
00076 
00077 KBzip2Filter::~KBzip2Filter()
00078 {
00079     delete d;
00080 }
00081 
00082 void KBzip2Filter::init( int mode )
00083 {
00084     d->zStream.next_in = 0;
00085     d->zStream.avail_in = 0;
00086     if ( mode == IO_ReadOnly )
00087     {
00088         (void)bzDecompressInit(&d->zStream, 0, 0);
00089         //kdDebug(7118) << "bzDecompressInit returned " << result << endl;
00090         // No idea what to do with result :)
00091     } else if ( mode == IO_WriteOnly ) {
00092         (void)bzCompressInit(&d->zStream, 5, 0, 0);
00093         //kdDebug(7118) << "bzDecompressInit returned " << result << endl;
00094     } else
00095         kdWarning(7118) << "Unsupported mode " << mode << ". Only IO_ReadOnly and IO_WriteOnly supported" << endl;
00096     m_mode = mode;
00097 }
00098 
00099 void KBzip2Filter::terminate()
00100 {
00101     if ( m_mode == IO_ReadOnly )
00102     {
00103         int result = bzDecompressEnd(&d->zStream);
00104         kdDebug(7118) << "bzDecompressEnd returned " << result << endl;
00105     } else if ( m_mode == IO_WriteOnly )
00106     {
00107         int result = bzCompressEnd(&d->zStream);
00108         kdDebug(7118) << "bzCompressEnd returned " << result << endl;
00109     } else
00110         kdWarning(7118) << "Unsupported mode " << m_mode << ". Only IO_ReadOnly and IO_WriteOnly supported" << endl;
00111 }
00112 
00113 
00114 void KBzip2Filter::reset()
00115 {
00116     kdDebug(7118) << "KBzip2Filter::reset" << endl;
00117     // bzip2 doesn't seem to have a reset call...
00118     terminate();
00119     init( m_mode );
00120 }
00121 
00122 void KBzip2Filter::setOutBuffer( char * data, uint maxlen )
00123 {
00124     d->zStream.avail_out = maxlen;
00125     d->zStream.next_out = data;
00126 }
00127 
00128 void KBzip2Filter::setInBuffer( const char *data, unsigned int size )
00129 {
00130     d->zStream.avail_in = size;
00131     d->zStream.next_in = const_cast<char *>(data);
00132 }
00133 
00134 int KBzip2Filter::inBufferAvailable() const
00135 {
00136     return d->zStream.avail_in;
00137 }
00138 
00139 int KBzip2Filter::outBufferAvailable() const
00140 {
00141     return d->zStream.avail_out;
00142 }
00143 
00144 KBzip2Filter::Result KBzip2Filter::uncompress()
00145 {
00146     //kdDebug(7118) << "Calling bzDecompress with avail_in=" << inBufferAvailable() << " avail_out=" << outBufferAvailable() << endl;
00147     int result = bzDecompress(&d->zStream);
00148     if ( result != BZ_OK )
00149     {
00150         kdDebug(7118) << "bzDecompress returned " << result << endl;
00151         kdDebug(7118) << "KBzip2Filter::uncompress " << ( result == BZ_OK ? OK : ( result == BZ_STREAM_END ? END : ERROR ) ) << endl;
00152     }
00153 
00154     switch (result) {
00155         case BZ_OK:
00156                 return OK;
00157         case BZ_STREAM_END:
00158                 return END;
00159         default:
00160                 return ERROR;
00161     }
00162 }
00163 
00164 KBzip2Filter::Result KBzip2Filter::compress( bool finish )
00165 {
00166     //kdDebug(7118) << "Calling bzCompress with avail_in=" << inBufferAvailable() << " avail_out=" << outBufferAvailable() << endl;
00167     int result = bzCompress(&d->zStream, finish ? BZ_FINISH : BZ_RUN );
00168 
00169     switch (result) {
00170         case BZ_OK:
00171         case BZ_FLUSH_OK:
00172         case BZ_RUN_OK:
00173         case BZ_FINISH_OK:
00174                 return OK;
00175                 break;
00176         case BZ_STREAM_END:
00177                 kdDebug(7118) << "  bzCompress returned " << result << endl;
00178                 return END;
00179         break;
00180         default:
00181                 kdDebug(7118) << "  bzCompress returned " << result << endl;
00182                 return ERROR;
00183                 break;
00184     }
00185 }
00186 
00187 #endif

kioslave

Skip menu "kioslave"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal