30 class QuaGzipFilePrivate {
34 inline QuaGzipFilePrivate() : gzd(
NULL) {}
35 inline QuaGzipFilePrivate(
const QString &fileName)
36 : fileName(fileName), gzd(
NULL) {}
37 template <
typename FileId>
38 bool open(FileId
id, QIODevice::OpenMode mode, QString &
error);
39 gzFile
open(
int fd,
const char *modeString);
40 gzFile
open(
const QString &
name,
const char *modeString);
43 gzFile QuaGzipFilePrivate::open(
const QString &
name,
const char *modeString) {
44 return gzopen(QFile::encodeName(
name).constData(), modeString);
47 gzFile QuaGzipFilePrivate::open(
int fd,
const char *modeString) {
48 return gzdopen(fd, modeString);
51 template <
typename FileId>
52 bool QuaGzipFilePrivate::open(FileId
id,
53 QIODevice::OpenMode mode,
56 modeString[0] = modeString[1] =
'\0';
58 error = QString::fromUtf8(
59 "QIODevice::Append is not "
60 "supported for GZIP");
63 if ((mode & QIODevice::ReadOnly) != 0 &&
64 (mode & QIODevice::WriteOnly) != 0) {
65 error = QString::fromUtf8(
66 "Opening gzip for both reading"
67 " and writing is not supported");
69 }
else if ((mode & QIODevice::ReadOnly) != 0) {
71 }
else if ((mode & QIODevice::WriteOnly) != 0) {
74 error = QString::fromUtf8(
75 "You can open a gzip either for reading"
76 " or for writing. Which is it?");
79 gzd =
open(
id, modeString);
81 error = QString::fromUtf8(
"Could not gzopen() file");
91 : QIODevice(parent), d(new QuaGzipFilePrivate()) {}
94 : QIODevice(parent), d(new QuaGzipFilePrivate(fileName)) {}
104 d->fileName = fileName;
113 if (!d->open(d->fileName, mode,
error)) {
114 setErrorString(
error);
117 return QIODevice::open(mode);
122 if (!d->open(fd, mode,
error)) {
123 setErrorString(
error);
126 return QIODevice::open(mode);
137 return gzread(d->gzd, (voidp)data, (
unsigned)maxSize);
141 if (maxSize == 0)
return 0;
142 int written = gzwrite(d->gzd, (voidp)data, (
unsigned)maxSize);
QString getFileName() const
Returns the name of the GZIP file.
virtual ~QuaGzipFile()
Destructor.
virtual bool open(QIODevice::OpenMode mode)
Opens the file.
void setFileName(const QString &fileName)
Sets the name of the GZIP file to be opened.
virtual void close()
Closes the file.
virtual bool isSequential() const
Returns true.
virtual qint64 writeData(const char *data, qint64 maxSize)
Implementation of QIODevice::writeData().
QuaGzipFile()
Empty constructor.
virtual qint64 readData(char *data, qint64 maxSize)
Implementation of QIODevice::readData().
virtual bool flush()
Flushes data to file.
static void error(char *msg)
Tensor Append(const Tensor &self, const Tensor &other, const utility::optional< int64_t > &axis)
Appends the two tensors, along the given axis into a new tensor. Both the tensors must have same data...