blob: af75f39ab6cd06d7e3677ae0b937e77e42f90549 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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);
}
|