]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/zstream.cpp
fixed handling of dst offset in wxAlphaBlend()
[wxWidgets.git] / src / common / zstream.cpp
index 09d616bab2cbe04cdf4f987fd637e2809f9689b9..083ac372fbad895ecd1f120cb4e7a8b1607ed1a6 100644 (file)
@@ -9,10 +9,6 @@
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-#pragma implementation "zstream.h"
-#endif
-
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
@@ -56,7 +52,7 @@ wxZlibInputStream::wxZlibInputStream(wxInputStream& stream, int flags)
   m_pos = 0;
 
 #if WXWIN_COMPATIBILITY_2_4
-  // treat compatibilty mode as auto
+  // treat compatibility mode as auto
   m_24compatibilty = flags == wxZLIB_24COMPATIBLE;
   if (m_24compatibilty)
     flags = wxZLIB_AUTO;
@@ -135,14 +131,16 @@ size_t wxZlibInputStream::OnSysRead(void *buffer, size_t size)
         break;
 
     case Z_STREAM_END:
-      // Unread any data taken from past the end of the deflate stream, so that
-      // any additional data can be read from the underlying stream (the crc
-      // in a gzip for example)
-      if (m_inflate->avail_in) {
-        m_parent_i_stream->Ungetch(m_inflate->next_in, m_inflate->avail_in);
-        m_inflate->avail_in = 0;
+      if (m_inflate->avail_out) {
+        // Unread any data taken from past the end of the deflate stream, so that
+        // any additional data can be read from the underlying stream (the crc
+        // in a gzip for example)
+        if (m_inflate->avail_in) {
+          m_parent_i_stream->Ungetch(m_inflate->next_in, m_inflate->avail_in);
+          m_inflate->avail_in = 0;
+        }
+        m_lasterror = wxSTREAM_EOF;
       }
-      m_lasterror = wxSTREAM_EOF;
       break;
 
     case Z_BUF_ERROR:
@@ -162,7 +160,7 @@ size_t wxZlibInputStream::OnSysRead(void *buffer, size_t size)
     default:
       wxString msg(m_inflate->msg, *wxConvCurrent);
       if (!msg)
-        msg.Format(_("zlib error %d"), err);
+        msg = wxString::Format(_("zlib error %d"), err);
       wxLogError(_("Can't read from inflate stream: %s"), msg.c_str());
       m_lasterror = wxSTREAM_READ_ERROR;
   }
@@ -218,7 +216,7 @@ wxZlibOutputStream::wxZlibOutputStream(wxOutputStream& stream,
       memset(m_deflate, 0, sizeof(z_stream_s));
       m_deflate->next_out = m_z_buffer;
       m_deflate->avail_out = m_z_size;
+
       // see zlib.h for documentation on windowBits
       int windowBits = MAX_WBITS;
       switch (flags) {
@@ -228,7 +226,7 @@ wxZlibOutputStream::wxZlibOutputStream(wxOutputStream& stream,
         default:                wxFAIL_MSG(wxT("Invalid zlib flag"));
       }
 
-      if (deflateInit2(m_deflate, level, Z_DEFLATED, windowBits, 
+      if (deflateInit2(m_deflate, level, Z_DEFLATED, windowBits,
                        8, Z_DEFAULT_STRATEGY) == Z_OK)
         return;
     }
@@ -238,20 +236,20 @@ wxZlibOutputStream::wxZlibOutputStream(wxOutputStream& stream,
   m_lasterror = wxSTREAM_WRITE_ERROR;
 }
 
-wxZlibOutputStream::~wxZlibOutputStream()
-{
-  if (m_deflate && m_z_buffer)
-    DoFlush(true);
-  deflateEnd(m_deflate);
-  delete m_deflate;
+bool wxZlibOutputStream::Close()
+ {
+  DoFlush(true);
+   deflateEnd(m_deflate);
+   delete m_deflate;
 
-  delete[] m_z_buffer;
-}
+  m_deflate = NULL;
+   delete[] m_z_buffer;
+  m_z_buffer = NULL;
+  return IsOk();
+ }
 
 void wxZlibOutputStream::DoFlush(bool final)
 {
-  wxASSERT_MSG(m_deflate && m_z_buffer, wxT("Deflate stream not open"));
-
   if (!m_deflate || !m_z_buffer)
     m_lasterror = wxSTREAM_WRITE_ERROR;
   if (!IsOk())
@@ -312,7 +310,7 @@ size_t wxZlibOutputStream::OnSysWrite(const void *buffer, size_t size)
     m_lasterror = wxSTREAM_WRITE_ERROR;
     wxString msg(m_deflate->msg, *wxConvCurrent);
     if (!msg)
-      msg.Format(_("zlib error %d"), err);
+      msg = wxString::Format(_("zlib error %d"), err);
     wxLogError(_("Can't write to deflate stream: %s"), msg.c_str());
   }
 
@@ -322,10 +320,10 @@ size_t wxZlibOutputStream::OnSysWrite(const void *buffer, size_t size)
 }
 
 /* static */ bool wxZlibOutputStream::CanHandleGZip()
-{ 
+{
   return wxZlibInputStream::CanHandleGZip();
 }
 
 #endif
   // wxUSE_ZLIB && wxUSE_STREAMS
-  
+