From 1ab48408d13344ff0e46bd397d7dc89889e48fba Mon Sep 17 00:00:00 2001 From: Michael Wetherell Date: Fri, 27 Oct 2006 08:54:00 +0000 Subject: [PATCH] Add FindLength() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42497 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/fileback.h | 6 ++++++ src/common/fileback.cpp | 28 +++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/include/wx/fileback.h b/include/wx/fileback.h index 2f98bb7198..5fda9c0c50 100644 --- a/include/wx/fileback.h +++ b/include/wx/fileback.h @@ -57,7 +57,13 @@ class WXDLLIMPEXP_BASE wxBackedInputStream : public wxInputStream public: wxBackedInputStream(const wxBackingFile& backer); + // If the length of the backer's parent stream is unknown then GetLength() + // returns wxInvalidOffset until the parent has been read to the end. wxFileOffset GetLength() const; + + // Returns the length, reading the parent stream to the end if necessary. + wxFileOffset FindLength() const; + bool IsSeekable() const { return true; } protected: diff --git a/src/common/fileback.cpp b/src/common/fileback.cpp index 06d32ae99e..bc5f2ff9dd 100644 --- a/src/common/fileback.cpp +++ b/src/common/fileback.cpp @@ -271,6 +271,29 @@ wxBackedInputStream::wxBackedInputStream(const wxBackingFile& backer) { } +wxFileOffset wxBackedInputStream::GetLength() const +{ + return m_backer.m_impl->GetLength(); +} + +wxFileOffset wxBackedInputStream::FindLength() const +{ + wxFileOffset len = GetLength(); + + if (len == wxInvalidOffset && IsOk()) { + // read a byte at 7ff...ffe + wxFileOffset pos = 1; + pos <<= sizeof(pos) * 8 - 1; + pos = ~pos - 1; + char ch; + size_t size = 1; + m_backer.m_impl->ReadAt(pos, &ch, &size); + len = GetLength(); + } + + return len; +} + size_t wxBackedInputStream::OnSysRead(void *buffer, size_t size) { if (!IsOk()) @@ -281,11 +304,6 @@ size_t wxBackedInputStream::OnSysRead(void *buffer, size_t size) return size; } -wxFileOffset wxBackedInputStream::GetLength() const -{ - return m_backer.m_impl->GetLength(); -} - wxFileOffset wxBackedInputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode) { switch (mode) { -- 2.45.2