aboutsummaryrefslogtreecommitdiffstats
path: root/src/input
diff options
context:
space:
mode:
Diffstat (limited to 'src/input')
-rw-r--r--src/input/InputStream.hxx18
-rw-r--r--src/input/plugins/RewindInputPlugin.cxx14
2 files changed, 24 insertions, 8 deletions
diff --git a/src/input/InputStream.hxx b/src/input/InputStream.hxx
index 13f6af32b..5f754940b 100644
--- a/src/input/InputStream.hxx
+++ b/src/input/InputStream.hxx
@@ -64,6 +64,7 @@ public:
*/
Cond &cond;
+protected:
/**
* indicates whether the stream is ready for reading and
* whether the other attributes in this struct are valid
@@ -80,7 +81,6 @@ public:
*/
offset_type size;
-public:
/**
* the current offset within the stream
*/
@@ -218,6 +218,13 @@ public:
}
gcc_pure
+ bool KnownSize() const {
+ assert(ready);
+
+ return size >= 0;
+ }
+
+ gcc_pure
offset_type GetSize() const {
assert(ready);
@@ -240,6 +247,15 @@ public:
}
gcc_pure
+ offset_type GetRest() const {
+ assert(ready);
+ assert(size >= 0);
+ assert(offset >= 0);
+
+ return size - offset;
+ }
+
+ gcc_pure
bool IsSeekable() const {
assert(ready);
diff --git a/src/input/plugins/RewindInputPlugin.cxx b/src/input/plugins/RewindInputPlugin.cxx
index 80f3beea1..eee395a8b 100644
--- a/src/input/plugins/RewindInputPlugin.cxx
+++ b/src/input/plugins/RewindInputPlugin.cxx
@@ -93,7 +93,7 @@ private:
* buffer contain more data for the next read operation?
*/
bool ReadingFromBuffer() const {
- return tail > 0 && offset < input->offset;
+ return tail > 0 && offset < input->GetOffset();
}
/**
@@ -116,7 +116,7 @@ private:
SetReady();
}
- offset = src->offset;
+ offset = src->GetOffset();
}
};
@@ -127,7 +127,7 @@ RewindInputStream::Read(void *ptr, size_t read_size, Error &error)
/* buffered read */
assert(head == (size_t)offset);
- assert(tail == (size_t)input->offset);
+ assert(tail == (size_t)input->GetOffset());
if (read_size > tail - head)
read_size = tail - head;
@@ -142,7 +142,7 @@ RewindInputStream::Read(void *ptr, size_t read_size, Error &error)
size_t nbytes = input->Read(ptr, read_size, error);
- if (input->offset > (InputPlugin::offset_type)sizeof(buffer))
+ if (input->GetOffset() > (offset_type)sizeof(buffer))
/* disable buffering */
tail = 0;
else if (tail == (size_t)offset) {
@@ -151,7 +151,7 @@ RewindInputStream::Read(void *ptr, size_t read_size, Error &error)
memcpy(buffer + tail, ptr, nbytes);
tail += nbytes;
- assert(tail == (size_t)input->offset);
+ assert(tail == (size_t)input->GetOffset());
}
CopyAttributes();
@@ -172,7 +172,7 @@ RewindInputStream::Seek(InputPlugin::offset_type new_offset, int whence,
assert(!ReadingFromBuffer() ||
head == (size_t)offset);
- assert(tail == (size_t)input->offset);
+ assert(tail == (size_t)input->GetOffset());
head = (size_t)new_offset;
offset = new_offset;
@@ -194,7 +194,7 @@ InputStream *
input_rewind_open(InputStream *is)
{
assert(is != nullptr);
- assert(is->offset == 0);
+ assert(is->GetOffset() == 0);
if (is->IsReady() && is->IsSeekable())
/* seekable resources don't need this plugin */