-
Notifications
You must be signed in to change notification settings - Fork 5
/
file_reader_into_stream.h
37 lines (31 loc) · 988 Bytes
/
file_reader_into_stream.h
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
#pragma once
#include <cstdint>
#include <string>
#include "sys/errno.h"
#include "sequential_file_reader.h"
#include "messages.h"
#include "utils.h"
template <class StreamWriter>
class FileReaderIntoStream : public SequentialFileReader {
public:
FileReaderIntoStream(const std::string& filename, std::int32_t id, StreamWriter& writer)
: SequentialFileReader(filename)
, m_writer(writer)
, m_id(id)
{
}
using SequentialFileReader::SequentialFileReader;
using SequentialFileReader::operator=;
protected:
virtual void OnChunkAvailable(const void* data, size_t size) override
{
const std::string remote_filename = extract_basename(GetFilePath());
auto fc = MakeFileContent(m_id, remote_filename, data, size);
if (! m_writer.Write(fc)) {
raise_from_system_error_code("The server aborted the connection.", ECONNRESET);
}
}
private:
StreamWriter& m_writer;
std::uint32_t m_id;
};