-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_res_writer.h
49 lines (36 loc) · 1.28 KB
/
file_res_writer.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
38
39
40
41
42
43
44
45
46
47
48
49
//
// Created by bdbai on 22-8-17.
//
#include "res_writer.h"
#ifndef MINIP_FILE_RES_WRITER_H
#define MINIP_FILE_RES_WRITER_H
namespace minip {
constexpr size_t SMALL_FILE_THRESHOLD = 64 * 1024;
struct mmap_deleter {
void operator()(uint8_t *p) const noexcept;
size_t length{};
};
struct file_res_writer;
file_res_writer create_file_res_writer(std::string_view path, std::string_view mime_type);
struct file_res_writer : enable_into_dyn_res_writer<file_res_writer> {
bool advance(context &ctx, conn &client_conn);
friend file_res_writer create_file_res_writer(std::string_view path, std::string_view mime_type);
private:
file_res_writer(
std::shared_ptr<uint8_t[]> header,
size_t header_len,
std::shared_ptr<uint8_t> mmap_file,
size_t mmap_file_len
) :
header(std::move(header)),
header_len(header_len),
mmap_file(std::move(mmap_file)),
mmap_file_len(mmap_file_len) {}
std::shared_ptr<uint8_t[]> header;
size_t header_len;
std::shared_ptr<uint8_t> mmap_file;
size_t mmap_file_len;
size_t written{};
};
} // minip
#endif //MINIP_FILE_RES_WRITER_H