- if (m_iolimit == 2) {
- m_eof = TRUE;
- return *this;
- }
- if (m_position_i+size > m_length)
- size = m_length-m_position_i;
-
- memcpy((void *)((unsigned long)buffer+m_position_i), m_buffer, size);
- m_position_i += size;
- m_lastread = size;
-
- return *this;
+ const wxFileOffset lenFile = stream.GetLength();
+ if ( lenFile == wxInvalidOffset )
+ {
+ m_i_streambuf = NULL;
+ m_lasterror = wxSTREAM_EOF;
+ return;
+ }
+
+ const size_t len = wx_truncate_cast(size_t, lenFile);
+ wxASSERT_MSG( len == lenFile + size_t(0), wxT("huge files not supported") );
+
+ m_i_streambuf = new wxStreamBuffer(wxStreamBuffer::read);
+ m_i_streambuf->SetBufferIO(len); // create buffer
+ stream.CopyTo(m_i_streambuf->GetBufferStart(), len);
+ m_i_streambuf->SetIntPosition(0); // seek to start pos
+ m_i_streambuf->Fixed(true);
+ m_length = len;