• 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
25KQIODeviceGZip::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
34KQIODeviceGZip::~KQIODeviceGZip(void)
35{
36 if (m_gzfile)
37 close();
38}
39
40bool KQIODeviceGZip::open(int 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
63void KQIODeviceGZip::close(void)
64{
65 if (m_gzfile)
66 {
67 gzclose(m_gzfile);
68 m_gzfile=0;
69 }
70}
71
72void 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
81TQIODevice::Offset KQIODeviceGZip::size(void) const
82{
83 return 0; // You cannot determine size!
84}
85
86TQIODevice::Offset KQIODeviceGZip::at() const
87{
88 if (!m_gzfile)
89 return 0;
90 return gztell(m_gzfile);
91}
92
93bool KQIODeviceGZip::at(TQIODevice::Offset pos)
94{
95 if (!m_gzfile)
96 return false;
97 return (gzseek(m_gzfile,pos,SEEK_SET)>=0);
98}
99
100bool KQIODeviceGZip::atEnd() const
101{
102 if (!m_gzfile)
103 return true;
104 return gzeof(m_gzfile);
105}
106
107bool KQIODeviceGZip::reset(void)
108{
109 if (!m_gzfile)
110 return false; //Say we arew at end of file
111 return (gzrewind(m_gzfile)>=0);
112}
113
114TQ_LONG KQIODeviceGZip::readBlock( char *data, TQ_ULONG maxlen )
115{
116 TQ_LONG result=0;
117 if (m_gzfile)
118 {
119 result=gzread(m_gzfile,data,maxlen);
120 if (result<0) result=0;
121 }
122 return result;
123}
124
125TQ_LONG KQIODeviceGZip::writeBlock( const char *data, TQ_ULONG len )
126{
127 TQ_ULONG result=0;
128 if (m_gzfile)
129 {
130 result=gzwrite(m_gzfile,(char*)data,len);
131 }
132 return result;
133}
134
135int KQIODeviceGZip::getch()
136{
137 if (m_ungetchar>0)
138 {
139 const int ch=m_ungetchar;
140 m_ungetchar=-1;
141 return ch;
142 }
143 if (!m_gzfile)
144 return -1;
145 return gzgetc(m_gzfile);
146}
147
148int KQIODeviceGZip::putch( int ch)
149{
150 if (!m_gzfile)
151 return -1;
152 return gzputc(m_gzfile,ch);
153}
154
155int KQIODeviceGZip::ungetch(int ch)
156{
157 m_ungetchar=ch;
158 return ch;
159}
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
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.9.4
This website is maintained by Timothy Pearson.