forked from blastrock/pkgj
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilehttp.cpp
More file actions
43 lines (35 loc) · 790 Bytes
/
Copy pathfilehttp.cpp
File metadata and controls
43 lines (35 loc) · 790 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
38
39
40
41
42
43
#include "filehttp.hpp"
#include "log.hpp"
FileHttp::FileHttp(const std::string& path) : override_path(path)
{
}
void FileHttp::start(const std::string& url, uint64_t offset)
{
LOGF("[Debug] Simulated HTTP download: {}", url);
f.open(override_path.empty() ? url : override_path);
f.seekg(offset, std::ios::beg);
}
int64_t FileHttp::read(uint8_t* buffer, uint64_t size)
{
f.read(reinterpret_cast<char*>(buffer), size);
return f.gcount();
}
void FileHttp::abort()
{
}
int FileHttp::get_status()
{
return 200;
}
int64_t FileHttp::get_length()
{
const uint64_t pos = f.tellg();
f.seekg(0, std::ios::end);
const uint64_t size = f.tellg();
f.seekg(pos, std::ios::beg);
return size;
}
FileHttp::operator bool() const
{
return f.is_open();
}