fixes to wxZipInputStream EOF (not) handling
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7598 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -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);
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user