-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathStorageInputStream.cpp
More file actions
37 lines (30 loc) · 908 Bytes
/
StorageInputStream.cpp
File metadata and controls
37 lines (30 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "StorageInputStream.hpp"
#include "Storage.hpp"
#include <algorithm>
BEGIN_INANITY
StorageInputStream::StorageInputStream(ptr<Storage> storage, bigsize_t offset)
: storage(storage), offset(offset), endOffset(storage->GetBigSize()) {}
StorageInputStream::StorageInputStream(ptr<Storage> storage, bigsize_t offset, bigsize_t size)
: storage(storage), offset(offset), endOffset(std::min(offset + size, storage->GetBigSize())) {}
size_t StorageInputStream::Read(void* data, size_t size)
{
bigsize_t maxSize = endOffset - offset;
if(size > maxSize)
size = (size_t)maxSize;
storage->Read(offset, size, data);
offset += size;
return size;
}
bigsize_t StorageInputStream::Skip(bigsize_t size)
{
bigsize_t maxSize = endOffset - offset;
if(size > maxSize)
size = maxSize;
offset += size;
return size;
}
bool StorageInputStream::IsAtEnd() const
{
return offset >= endOffset;
}
END_INANITY