-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileSeekStream.cpp
49 lines (41 loc) · 1.14 KB
/
FileSeekStream.cpp
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
38
39
40
41
42
43
44
45
46
47
48
49
#include "FileSeekStream.h"
using namespace sf;
FileSeekStream::FileSeekStream() { }
//When initialized, innerStream is opened and moved to the offset where the file to be streamed from lies.
FileSeekStream::FileSeekStream(const char* path, Int64 offset, Int64 length) {
this->length = length;
this->offset = offset;
this->maxPos = offset + length;
innerStream.open(path);
innerStream.seek(offset);
}
Int64 FileSeekStream::read(void* data, Int64 size) {
return innerStream.read(data, size);
}
Int64 FileSeekStream::seek(Int64 position) {
result = innerStream.seek(offset + position);
if (result > maxPos)
return -1;
return result - offset;
}
//Mocks the position of the stream
Int64 FileSeekStream::tell() {
result = innerStream.tell() - offset;
if (result < 0 || result > length)
return -1;
return result;
}
Int64 FileSeekStream::getSize() {
return length;
}
//Alternative to a constructor
bool FileSeekStream::setData(const char* path, Int64 offset, Int64 length)
{
this->offset = offset;
this->length = length;
this->maxPos = offset + length;
if (!innerStream.open(path))
return false;
innerStream.seek(offset);
return true;
}