QuaZioDevice::atEnd() and bytesAvailable() (might break ABI, but
probably safe)
This commit is contained in:
parent
84e2472a27
commit
d4c34ce65b
4 changed files with 45 additions and 2 deletions
|
@ -42,6 +42,7 @@ class QuaZIODevicePrivate {
|
|||
int outBufPos;
|
||||
int outBufSize;
|
||||
bool zBufError;
|
||||
bool atEnd;
|
||||
int doFlush(QString &error);
|
||||
};
|
||||
|
||||
|
@ -53,7 +54,8 @@ QuaZIODevicePrivate::QuaZIODevicePrivate(QIODevice *io):
|
|||
outBuf(NULL),
|
||||
outBufPos(0),
|
||||
outBufSize(0),
|
||||
zBufError(false)
|
||||
zBufError(false),
|
||||
atEnd(false)
|
||||
{
|
||||
zins.zalloc = (alloc_func) NULL;
|
||||
zins.zfree = (free_func) NULL;
|
||||
|
@ -318,3 +320,13 @@ bool QuaZIODevice::isSequential() const
|
|||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QuaZIODevice::atEnd() const
|
||||
{
|
||||
return (openMode() == NotOpen) || d->atEnd;
|
||||
}
|
||||
|
||||
qint64 QuaZIODevice::bytesAvailable() const
|
||||
{
|
||||
return (atEnd() ? 0 : 1) + QIODevice::bytesAvailable();
|
||||
}
|
||||
|
|
|
@ -87,6 +87,10 @@ public:
|
|||
QIODevice *getIoDevice() const;
|
||||
/// Returns true.
|
||||
virtual bool isSequential() const;
|
||||
/// Returns true iff the end of the compressed stream is reached.
|
||||
virtual bool atEnd() const;
|
||||
/// Returns the number of the bytes buffered.
|
||||
virtual qint64 bytesAvailable() const;
|
||||
protected:
|
||||
/// Implementation of QIODevice::readData().
|
||||
virtual qint64 readData(char *data, qint64 maxSize);
|
||||
|
|
|
@ -52,6 +52,32 @@ void TestQuaZIODevice::read()
|
|||
QVERIFY(!testDevice.isOpen());
|
||||
}
|
||||
|
||||
void TestQuaZIODevice::readMany()
|
||||
{
|
||||
QByteArray buf(256, 0);
|
||||
z_stream zouts;
|
||||
zouts.zalloc = (alloc_func) NULL;
|
||||
zouts.zfree = (free_func) NULL;
|
||||
zouts.opaque = NULL;
|
||||
deflateInit(&zouts, Z_DEFAULT_COMPRESSION);
|
||||
zouts.next_in = reinterpret_cast<Bytef*>(const_cast<char*>("testtest"));
|
||||
zouts.avail_in = 8;
|
||||
zouts.next_out = reinterpret_cast<Bytef*>(buf.data());
|
||||
zouts.avail_out = buf.size();
|
||||
deflate(&zouts, Z_FINISH);
|
||||
deflateEnd(&zouts);
|
||||
QBuffer testBuffer(&buf);
|
||||
testBuffer.open(QIODevice::ReadOnly);
|
||||
QuaZIODevice testDevice(&testBuffer);
|
||||
QVERIFY(testDevice.open(QIODevice::ReadOnly));
|
||||
char outBuf[4];
|
||||
QCOMPARE(testDevice.read(outBuf, 4), static_cast<qint64>(4));
|
||||
QVERIFY(!testDevice.atEnd());
|
||||
QVERIFY(testDevice.bytesAvailable() > 0);
|
||||
testDevice.close();
|
||||
QVERIFY(!testDevice.isOpen());
|
||||
}
|
||||
|
||||
void TestQuaZIODevice::write()
|
||||
{
|
||||
QByteArray buf(256, 0);
|
||||
|
|
|
@ -31,6 +31,7 @@ class TestQuaZIODevice: public QObject {
|
|||
Q_OBJECT
|
||||
private slots:
|
||||
void read();
|
||||
void readMany();
|
||||
void write();
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue