+// ----------------------------------------------------------------------------
+// wxBufferedInputStream
+// ----------------------------------------------------------------------------
+wxBufferedInputStream::wxBufferedInputStream(wxInputStream& s)
+ : wxFilterInputStream(s)
+{
+ m_i_streambuf = new wxStreamBuffer(*this, wxStreamBuffer::read);
+ m_i_streambuf->SetBufferIO(1024);
+}
+
+wxBufferedInputStream::~wxBufferedInputStream()
+{
+ off_t unused_bytes=m_i_streambuf->GetBufferPos()-m_i_streambuf->GetBufferEnd();
+ m_parent_i_stream->SeekI(unused_bytes,wxFromCurrent);
+
+ delete m_i_streambuf;
+}
+
+char wxBufferedInputStream::Peek()
+{
+ return m_i_streambuf->Peek();
+}
+
+wxInputStream& wxBufferedInputStream::Read(void *buffer, size_t size)
+{
+ size_t retsize;
+ char *buf = (char *)buffer;
+
+ retsize = GetWBack(buf, size);
+ m_lastcount = retsize;
+ if (retsize == size)
+ {
+ m_lasterror = wxStream_NOERROR;
+ return *this;
+ }
+ size -= retsize;
+ buf += retsize;
+
+ m_i_streambuf->Read(buf, size);
+
+ return *this;
+}
+
+off_t wxBufferedInputStream::SeekI(off_t pos, wxSeekMode mode)
+{
+ return m_i_streambuf->Seek(pos, mode);
+}
+
+off_t wxBufferedInputStream::TellI() const
+{
+ return m_i_streambuf->Tell();
+}
+
+size_t wxBufferedInputStream::OnSysRead(void *buffer, size_t bufsize)
+{
+ return m_parent_i_stream->Read(buffer, bufsize).LastRead();
+}
+
+off_t wxBufferedInputStream::OnSysSeek(off_t seek, wxSeekMode mode)
+{
+ return m_parent_i_stream->SeekI(seek, mode);
+}
+
+off_t wxBufferedInputStream::OnSysTell() const
+{
+ return m_parent_i_stream->TellI();
+}
+
+
+// ----------------------------------------------------------------------------
+// wxBufferedOutputStream
+// ----------------------------------------------------------------------------
+
+wxBufferedOutputStream::wxBufferedOutputStream(wxOutputStream& s)
+ : wxFilterOutputStream(s)
+{
+ m_o_streambuf = new wxStreamBuffer(*this, wxStreamBuffer::write);
+ m_o_streambuf->SetBufferIO(1024);
+}
+
+wxBufferedOutputStream::~wxBufferedOutputStream()
+{
+ Sync();
+ delete m_o_streambuf;
+}
+
+wxOutputStream& wxBufferedOutputStream::Write(const void *buffer, size_t size)
+{
+ m_lastcount = 0;
+ m_o_streambuf->Write(buffer, size);
+ return *this;
+}
+
+off_t wxBufferedOutputStream::SeekO(off_t pos, wxSeekMode mode)
+{
+ Sync();
+ return m_o_streambuf->Seek(pos, mode);
+}
+
+off_t wxBufferedOutputStream::TellO() const
+{
+ return m_o_streambuf->Tell();
+}
+
+void wxBufferedOutputStream::Sync()
+{
+ m_o_streambuf->FlushBuffer();
+ m_parent_o_stream->Sync();
+}
+
+size_t wxBufferedOutputStream::OnSysWrite(const void *buffer, size_t bufsize)
+{
+ return m_parent_o_stream->Write(buffer, bufsize).LastWrite();
+}
+
+off_t wxBufferedOutputStream::OnSysSeek(off_t seek, wxSeekMode mode)
+{
+ return m_parent_o_stream->SeekO(seek, mode);
+}
+
+off_t wxBufferedOutputStream::OnSysTell() const
+{
+ return m_parent_o_stream->TellO();
+}
+
+size_t wxBufferedOutputStream::GetSize() const
+{
+ return m_parent_o_stream->GetSize() + m_o_streambuf->GetIntPosition();
+}
+