diff --git a/include/wx/zipstrm.h b/include/wx/zipstrm.h index e8c01f0648..4b8b4cf346 100644 --- a/include/wx/zipstrm.h +++ b/include/wx/zipstrm.h @@ -35,6 +35,7 @@ public: ~wxZipInputStream(); virtual size_t GetSize() const {return m_Size;} + virtual bool Eof() const; protected: virtual size_t OnSysRead(void *buffer, size_t bufsize); diff --git a/samples/console/console.cpp b/samples/console/console.cpp index 1ee6711835..00a3e9f086 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -47,7 +47,7 @@ //#define TEST_LIST //#define TEST_LOG //#define TEST_LONGLONG -#define TEST_MIME +//#define TEST_MIME //#define TEST_INFO_FUNCTIONS //#define TEST_SOCKETS //#define TEST_STRINGS @@ -55,6 +55,7 @@ //#define TEST_TIMER //#define TEST_VCARD //#define TEST_WCHAR +#define TEST_ZIP // ---------------------------------------------------------------------------- // test class for container objects @@ -1576,6 +1577,33 @@ static void TestUtf8() #endif // TEST_WCHAR +// ---------------------------------------------------------------------------- +// ZIP stream +// ---------------------------------------------------------------------------- + +#ifdef TEST_ZIP + +#include "wx/zipstrm.h" + +static void TestZipStreamRead() +{ + puts("*** Testing ZIP reading ***\n"); + + wxZipInputStream istr(_T("idx.zip"), _T("IDX.txt")); + printf("Archive size: %u\n", istr.GetSize()); + + puts("Dumping the file:"); + while ( !istr.Eof() ) + { + putchar(istr.GetC()); + fflush(stdout); + } + + puts("\n----- done ------"); +} + +#endif // TEST_ZIP + // ---------------------------------------------------------------------------- // date time // ---------------------------------------------------------------------------- @@ -3454,6 +3482,10 @@ int main(int argc, char **argv) TestUtf8(); #endif // TEST_WCHAR +#ifdef TEST_ZIP + TestZipStreamRead(); +#endif // TEST_ZIP + wxUninitialize(); return 0; diff --git a/src/common/zipstrm.cpp b/src/common/zipstrm.cpp index c8a864bd72..fb191d35c3 100644 --- a/src/common/zipstrm.cpp +++ b/src/common/zipstrm.cpp @@ -73,13 +73,32 @@ wxZipInputStream::~wxZipInputStream() } } +bool wxZipInputStream::Eof() const +{ + wxASSERT_MSG( m_Pos <= (off_t)m_Size, + _T("wxZipInputStream: invalid current position") ); + + return m_Pos >= (off_t)m_Size; +} size_t wxZipInputStream::OnSysRead(void *buffer, size_t bufsize) { - if (m_Pos + bufsize > m_Size) bufsize = m_Size - m_Pos; + wxASSERT_MSG( m_Pos <= (off_t)m_Size, + _T("wxZipInputStream: invalid current position") ); + + if ( m_Pos >= (off_t)m_Size ) + { + m_lasterror = wxStream_EOF; + return 0; + } + + if (m_Pos + bufsize > m_Size) + bufsize = m_Size - m_Pos; + unzReadCurrentFile((unzFile)m_Archive, buffer, bufsize); m_Pos += bufsize; + return bufsize; }