59 setErrorString(tr(
"File is already open"));
64 setErrorString(tr(
"Append mode not supported"));
69 if ((mode & (ReadOnly | WriteOnly)) == 0) {
70 setErrorString(tr(
"File access mode not specified"));
75 if ((mode & ReadOnly) && (mode & WriteOnly)) {
76 setErrorString(tr(
"Read and write modes both specified"));
102 if (mode & WriteOnly) {
104 if (!
m_qfile.open(QIODevice::WriteOnly)) {
105 setErrorString(tr(
"Failed to open file for writing"));
112 setErrorString(tr(
"Failed to open file handle for writing"));
125 setErrorString(tr(
"Failed to open bzip2 stream for writing"));
132 setErrorString(QString());
137 if (mode & ReadOnly) {
139 if (!
m_qfile.open(QIODevice::ReadOnly)) {
140 setErrorString(tr(
"Failed to open file for reading"));
147 setErrorString(tr(
"Failed to open file handle for reading"));
159 setErrorString(tr(
"Failed to open bzip2 stream for reading"));
168 setErrorString(QString());
173 setErrorString(tr(
"Internal error (open for neither read nor write)"));
182 setErrorString(tr(
"File not open"));
189 if (openMode() & WriteOnly) {
190 unsigned int in = 0, out = 0;
191 BZ2_bzWriteClose(&bzError,
m_bzFile, 0, &in, &out);
193 if (bzError != BZ_OK) {
194 setErrorString(tr(
"bzip2 stream write close error"));
204 if (openMode() & ReadOnly) {
205 BZ2_bzReadClose(&bzError,
m_bzFile);
206 if (bzError != BZ_OK) {
207 setErrorString(tr(
"bzip2 stream read close error"));
217 setErrorString(tr(
"Internal error (close for neither read nor write)"));
227 int read = BZ2_bzRead(&bzError,
m_bzFile, data,
int(maxSize));
231 if (bzError != BZ_OK) {
232 if (bzError != BZ_STREAM_END) {
233 cerr <<
"BZipFileDevice::readData: error condition" << endl;
234 setErrorString(tr(
"bzip2 stream read error"));
250 BZ2_bzWrite(&bzError,
m_bzFile, (
void *)data,
int(maxSize));
254 if (bzError != BZ_OK) {
255 cerr <<
"BZipFileDevice::writeData: error condition" << endl;
256 setErrorString(
"bzip2 stream write error");
qint64 writeData(const char *data, qint64 maxSize) override
BZipFileDevice(QString fileName)
virtual ~BZipFileDevice()
virtual bool isOK() const
bool open(OpenMode mode) override
qint64 readData(char *data, qint64 maxSize) override