@@ -17,7 +17,7 @@ class ReaderBuffer final : public std::streambuf {
1717 ReaderBuffer (const impl::CompoundFileReader &reader,
1818 const impl::CompoundFileEntry &entry,
1919 std::unique_ptr<std::istream> stream,
20- const std::size_t buffer_size = 4098 )
20+ const std::size_t buffer_size = 4096 )
2121 : m_reader{&reader}, m_entry{&entry}, m_stream{std::move (stream)},
2222 m_buffer (buffer_size, ' \0 ' ) {}
2323
@@ -37,6 +37,11 @@ class ReaderBuffer final : public std::streambuf {
3737 return traits_type::to_int_type (*gptr ());
3838 }
3939
40+ std::streampos seekpos (const std::streampos sp,
41+ const std::ios_base::openmode which) override {
42+ return seekoff (sp, std::ios_base::beg, which);
43+ }
44+
4045 std::streampos seekoff (const std::streamoff off,
4146 const std::ios_base::seekdir dir,
4247 const std::ios_base::openmode which) override {
@@ -49,9 +54,14 @@ class ReaderBuffer final : public std::streambuf {
4954 if (dir == std::ios_base::beg) {
5055 new_pos = off;
5156 } else if (dir == std::ios_base::cur) {
52- new_pos = m_offset - (egptr () - gptr ()) + off;
57+ const std::streampos current_pos =
58+ static_cast <std::streampos>(m_offset) +
59+ static_cast <std::streampos>(gptr () - eback ());
60+ new_pos = current_pos + off;
5361 } else if (dir == std::ios_base::end) {
54- new_pos = m_entry->size + off;
62+ new_pos = static_cast <std::streampos>(m_entry->size ) + off;
63+ } else {
64+ throw std::logic_error (" Invalid seek direction" );
5565 }
5666
5767 if (new_pos < 0 || static_cast <std::uint64_t >(new_pos) > m_entry->size ) {
0 commit comments