+ return (m_stream->m_lastcount = orig_size);
+}
+
+size_t wxStreamBuffer::Write(wxStreamBuffer *sbuf)
+{
+ char buf[BUF_TEMP_SIZE];
+ size_t s = 0, bytes_count = BUF_TEMP_SIZE, b_count2;
+
+ while (bytes_count == BUF_TEMP_SIZE) {
+ b_count2 = sbuf->Read(buf, bytes_count);
+ bytes_count = Write(buf, b_count2);
+ if (b_count2 > bytes_count)
+ sbuf->WriteBack(buf+bytes_count, b_count2-bytes_count);
+ s += bytes_count;
+ }
+ return s;
+}
+
+off_t wxStreamBuffer::Seek(off_t pos, wxSeekMode mode)
+{
+ off_t ret_off, diff, last_access;
+
+ last_access = GetLastAccess();
+
+ if (!m_flushable) {
+ diff = pos + GetIntPosition();
+ if (diff < 0 || diff > last_access)
+ return wxInvalidOffset;
+ SetIntPosition(diff);
+ return diff;
+ }
+
+ switch (mode) {
+ case wxFromStart: {
+ // We'll try to compute an internal position later ...
+ ret_off = m_stream->OnSysSeek(pos, wxFromStart);
+ ResetBuffer();
+ return ret_off;
+ }
+ case wxFromCurrent: {
+ diff = pos + GetIntPosition();
+
+ if ( (diff > last_access) || (diff < 0) ) {
+ ret_off = m_stream->OnSysSeek(pos, wxFromCurrent);
+ ResetBuffer();
+ return ret_off;
+ } else {
+ SetIntPosition(diff);
+ return pos;
+ }
+ }
+ case wxFromEnd:
+ // Hard to compute: always seek to the requested position.
+ ret_off = m_stream->OnSysSeek(pos, wxFromEnd);
+ ResetBuffer();
+ return ret_off;
+ }
+ return wxInvalidOffset;
+}
+
+off_t wxStreamBuffer::Tell() const
+{
+ off_t pos;
+
+ if (m_flushable) {
+ pos = m_stream->OnSysTell();
+ if (pos == wxInvalidOffset)
+ return wxInvalidOffset;
+ return pos - GetLastAccess() + GetIntPosition();
+ } else
+ return GetIntPosition();
+}
+
+size_t wxStreamBuffer::GetDataLeft()
+{
+ if (m_buffer_end == m_buffer_pos && m_flushable)
+ FillBuffer();
+ return m_buffer_end-m_buffer_pos;
+}
+
+// ----------------------------------------------------------------------------
+// wxStreamBase
+// ----------------------------------------------------------------------------
+
+wxStreamBase::wxStreamBase()
+{
+ m_lasterror = wxStream_NOERROR;
+ m_lastcount = 0;
+}
+
+wxStreamBase::~wxStreamBase()
+{
+}
+
+size_t wxStreamBase::OnSysRead(void *WXUNUSED(buffer), size_t WXUNUSED(size))
+{
+ return 0;
+}
+
+size_t wxStreamBase::OnSysWrite(const void *WXUNUSED(buffer), size_t WXUNUSED(bufsize))
+{
+ return 0;
+}
+
+off_t wxStreamBase::OnSysSeek(off_t WXUNUSED(seek), wxSeekMode WXUNUSED(mode))
+{
+ return wxInvalidOffset;
+}
+
+off_t wxStreamBase::OnSysTell() const
+{
+ return wxInvalidOffset;