• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
kqiodevicegzip_p.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2001,2005 Nicolas GOUTTE <nicog@snafu.de>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 // TODO: more error report and control
21 
22 #include <tqstring.h>
23 #include "kqiodevicegzip_p.h"
24 
25 KQIODeviceGZip::KQIODeviceGZip(const TQString& filename)
26 {
27  m_gzfile=0;
28  m_ungetchar=-1;
29  m_filename=filename;
30  setFlags(IO_Sequential); // We have no direct access, so it is sequential!
31  // NOTE: "sequential" also means that you cannot use size()
32 }
33 
34 KQIODeviceGZip::~KQIODeviceGZip(void)
35 {
36  if (m_gzfile)
37  close();
38 }
39 
40 bool KQIODeviceGZip::open(TQ_OpenMode mode)
41 {
42  if (m_gzfile)
43  close(); // One file is already open, so close it first.
44  if (m_filename.isEmpty())
45  return false; // No file name, cannot open!
46 
47  if (IO_ReadOnly==mode)
48  {
49  m_gzfile=gzopen(TQFile::encodeName(m_filename),"rb");
50  }
51  else if (IO_WriteOnly==mode)
52  {
53  m_gzfile=gzopen(TQFile::encodeName(m_filename),"wb9"); // Always set best compression
54  }
55  else
56  {
57  // We only support read only or write only, nothing else!
58  return false;
59  }
60  return (m_gzfile!=0);
61 }
62 
63 void KQIODeviceGZip::close(void)
64 {
65  if (m_gzfile)
66  {
67  gzclose(m_gzfile);
68  m_gzfile=0;
69  }
70 }
71 
72 void KQIODeviceGZip::flush(void)
73 {
74  // Always try to flush, do not return any error!
75  if (m_gzfile)
76  {
77  gzflush(m_gzfile,Z_SYNC_FLUSH);
78  }
79 }
80 
81 #ifdef USE_QT4
82 qint64 KQIODeviceGZip::size(void) const
83 #else // USE_QT4
84 TQIODevice::Offset KQIODeviceGZip::size(void) const
85 #endif // USE_QT4
86 {
87  return 0; // You cannot determine size!
88 }
89 
90 TQIODevice::Offset KQIODeviceGZip::at() const
91 {
92  if (!m_gzfile)
93  return 0;
94  return gztell(m_gzfile);
95 }
96 
97 bool KQIODeviceGZip::at(TQIODevice::Offset pos)
98 {
99  if (!m_gzfile)
100  return false;
101  return (gzseek(m_gzfile,pos,SEEK_SET)>=0);
102 }
103 
104 bool KQIODeviceGZip::atEnd() const
105 {
106  if (!m_gzfile)
107  return true;
108  return gzeof(m_gzfile);
109 }
110 
111 bool KQIODeviceGZip::reset(void)
112 {
113  if (!m_gzfile)
114  return false; //Say we arew at end of file
115  return (gzrewind(m_gzfile)>=0);
116 }
117 
118 TQT_TQIO_LONG KQIODeviceGZip::tqreadBlock( char *data, TQT_TQIO_ULONG maxlen )
119 {
120  TQ_LONG result=0;
121  if (m_gzfile)
122  {
123  result=gzread(m_gzfile,data,maxlen);
124  if (result<0) result=0;
125  }
126  return result;
127 }
128 
129 TQT_TQIO_LONG KQIODeviceGZip::tqwriteBlock( const char *data, TQT_TQIO_ULONG len )
130 {
131  TQ_ULONG result=0;
132  if (m_gzfile)
133  {
134  result=gzwrite(m_gzfile,(char*)data,len);
135  }
136  return result;
137 }
138 
139 int KQIODeviceGZip::getch()
140 {
141  if (m_ungetchar>0)
142  {
143  const int ch=m_ungetchar;
144  m_ungetchar=-1;
145  return ch;
146  }
147  if (!m_gzfile)
148  return -1;
149  return gzgetc(m_gzfile);
150 }
151 
152 int KQIODeviceGZip::putch( int ch)
153 {
154  if (!m_gzfile)
155  return -1;
156  return gzputc(m_gzfile,ch);
157 }
158 
159 int KQIODeviceGZip::ungetch(int ch)
160 {
161  m_ungetchar=ch;
162  return ch;
163 }
flush
kndbgstream & flush(kndbgstream &s)
Does nothing.
Definition: kdebug.h:589
KStdAction::close
TDEAction * close(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.8.8
This website is maintained by Timothy Pearson.