2 * This file is part of jSpeed.
4 * jSpeed is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * jSpeed 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
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with jSpeed. If not, see <http://www.gnu.org/licenses/>.
19 #include <QtCore/QString>
20 #include <QtCore/QByteArray>
21 #include <QtCore/QDebug>
22 #include "zipreader.h"
26 int const BUFFER_SIZE = 16384;
29 ZipReader::ZipReader(QString const& filename): Reader(),
30 filename_(filename), zip_(0), error_("")
34 bool ZipReader::open()
38 zip_ = zip_open(filename_.toLatin1().data(), 0, &error);
42 error_ = "Not a valid zip file";
50 bool ZipReader::readFile(QString const& filename, QByteArray& data)
54 file = zip_fopen(zip_, filename.toLatin1().data(), 0);
58 error_ = QString(zip_strerror(zip_));
62 char buffer[BUFFER_SIZE];
68 while((read = zip_fread(file, buffer, BUFFER_SIZE)) > 0)
70 data.append(buffer, read);
76 bool ZipReader::fileExists(QString const& filename) const
78 return zip_name_locate(zip_, filename.toLatin1().data(), 0) != -1;
81 bool ZipReader::close()
83 if(zip_close(zip_) == 0)
92 QString const& ZipReader::errorString() const