Add FindLength()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42497 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -57,7 +57,13 @@ class WXDLLIMPEXP_BASE wxBackedInputStream : public wxInputStream
|
|||||||
public:
|
public:
|
||||||
wxBackedInputStream(const wxBackingFile& backer);
|
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;
|
wxFileOffset GetLength() const;
|
||||||
|
|
||||||
|
// Returns the length, reading the parent stream to the end if necessary.
|
||||||
|
wxFileOffset FindLength() const;
|
||||||
|
|
||||||
bool IsSeekable() const { return true; }
|
bool IsSeekable() const { return true; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@@ -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)
|
size_t wxBackedInputStream::OnSysRead(void *buffer, size_t size)
|
||||||
{
|
{
|
||||||
if (!IsOk())
|
if (!IsOk())
|
||||||
@@ -281,11 +304,6 @@ size_t wxBackedInputStream::OnSysRead(void *buffer, size_t size)
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFileOffset wxBackedInputStream::GetLength() const
|
|
||||||
{
|
|
||||||
return m_backer.m_impl->GetLength();
|
|
||||||
}
|
|
||||||
|
|
||||||
wxFileOffset wxBackedInputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode)
|
wxFileOffset wxBackedInputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode)
|
||||||
{
|
{
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
Reference in New Issue
Block a user