summaryrefslogtreecommitdiffstats
path: root/heimdall-frontend/source/GZipFile.cpp
diff options
context:
space:
mode:
authorBenjamin Dobell <benjamin.dobell+git@glassechidna.com.au>2015-03-09 16:49:32 +0100
committerBenjamin Dobell <benjamin.dobell+git@glassechidna.com.au>2015-03-09 16:53:28 +0100
commit6971b49f85d9ddeb2da968a594d65affec3d2b44 (patch)
tree620c821e72045b3b547982efb3d068d5354de9ce /heimdall-frontend/source/GZipFile.cpp
parentCompleted basic firmware file selection functionality (diff)
downloadHeimdall-6971b49f85d9ddeb2da968a594d65affec3d2b44.tar
Heimdall-6971b49f85d9ddeb2da968a594d65affec3d2b44.tar.gz
Heimdall-6971b49f85d9ddeb2da968a594d65affec3d2b44.tar.bz2
Heimdall-6971b49f85d9ddeb2da968a594d65affec3d2b44.tar.lz
Heimdall-6971b49f85d9ddeb2da968a594d65affec3d2b44.tar.xz
Heimdall-6971b49f85d9ddeb2da968a594d65affec3d2b44.tar.zst
Heimdall-6971b49f85d9ddeb2da968a594d65affec3d2b44.zip
Diffstat (limited to 'heimdall-frontend/source/GZipFile.cpp')
-rw-r--r--heimdall-frontend/source/GZipFile.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/heimdall-frontend/source/GZipFile.cpp b/heimdall-frontend/source/GZipFile.cpp
new file mode 100644
index 0000000..af75f39
--- /dev/null
+++ b/heimdall-frontend/source/GZipFile.cpp
@@ -0,0 +1,51 @@
+#import "GZipFile.h"
+
+using namespace HeimdallFrontend;
+
+GZipFile::GZipFile(const QString& path) :
+ file(path),
+ gzFile(nullptr)
+{
+}
+
+GZipFile::~GZipFile()
+{
+ Close();
+
+ if (temporary)
+ {
+ file.remove();
+ }
+}
+
+bool GZipFile::Open(Mode mode)
+{
+ if (!file.isOpen() && !file.open(mode == GZipFile::ReadOnly ? QFile::ReadOnly : QFile::WriteOnly))
+ {
+ return (false);
+ }
+
+ gzFile = gzdopen(file.handle(), mode == GZipFile::ReadOnly ? "rb" : "wb");
+ return (gzFile != nullptr);
+}
+
+void GZipFile::Close()
+{
+ file.close();
+ gzclose(gzFile);
+}
+
+int GZipFile::Read(void *buffer, int length)
+{
+ return (length >= 0 && !file.isWritable() ? gzread(gzFile, buffer, length) : -1);
+}
+
+bool GZipFile::Write(void *buffer, int length)
+{
+ return (length >= 0 && gzwrite(gzFile, buffer, length) == length);
+}
+
+qint64 GZipFile::Offset() const
+{
+ return gzoffset(gzFile);
+}