-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfileio.cpp
More file actions
41 lines (33 loc) · 847 Bytes
/
fileio.cpp
File metadata and controls
41 lines (33 loc) · 847 Bytes
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
#include "fileio.h"
#include "filelocker.h"
#include "zlib.h"
QByteArray FileIO::readGZFileLocked(const QFile &file)
{
FileLocker locker(file);
gzFile f = gzopen(file.fileName().toLocal8Bit().constData(), "r");
if (f == 0)
return QByteArray();
QByteArray data;
char buffer[1024];
while (!gzeof(f)) {
int len = gzread(f, buffer, 1024);
if (len < 0) {
gzclose(f);
return QByteArray();
}
data.append(buffer, len);
}
gzclose(f);
return data;
}
bool FileIO::writeGZFileLocked(const QFile &file, const QByteArray &data)
{
FileLocker locker(file);
gzFile f = gzopen(file.fileName().toLocal8Bit().constData(), "w");
if (f == 0) {
return false;
}
gzwrite(f, data.data(), data.size());
gzclose(f);
return true;
}