src/corelib/io/qbuffer.cpp
changeset 33 3e2da88830cd
parent 18 2f34d5167611
--- a/src/corelib/io/qbuffer.cpp	Tue Jul 06 15:10:48 2010 +0300
+++ b/src/corelib/io/qbuffer.cpp	Wed Aug 18 10:37:55 2010 +0300
@@ -62,6 +62,9 @@
     QByteArray defaultBuf;
     int ioIndex;
 
+    virtual qint64 peek(char *data, qint64 maxSize);
+    virtual QByteArray peek(qint64 maxSize);
+
 #ifndef QT_NO_QOBJECT
     // private slots
     void _q_emitSignals();
@@ -83,6 +86,21 @@
 }
 #endif
 
+qint64 QBufferPrivate::peek(char *data, qint64 maxSize)
+{
+    qint64 readBytes = qMin(maxSize, static_cast<qint64>(buf->size()) - pos);
+    memcpy(data, buf->constData() + pos, readBytes);
+    return readBytes;
+}
+
+QByteArray QBufferPrivate::peek(qint64 maxSize)
+{
+    qint64 readBytes = qMin(maxSize, static_cast<qint64>(buf->size()) - pos);
+    if (pos == 0 && maxSize >= buf->size())
+        return *buf;
+    return QByteArray(buf->constData() + pos, readBytes);
+}
+
 /*!
     \class QBuffer
     \reentrant