|
8 | 8 |
|
9 | 9 | #define CHUNK_SIZE 65536 |
10 | 10 |
|
11 | | -#ifdef MANAPIHTTP_BROTLI_DEPENDENCY |
| 11 | + |
| 12 | +static manapi::future<manapi::error::status> compress_file_init (manapi::filesystem::fstream &input, manapi::filesystem::fstream &output, std::string src, std::string dest, manapi::async::cancellation_action &cancellation) { |
| 13 | + auto ires = manapi::filesystem::fstream::create (std::move(src), manapi::async::cancellation_action::unit(cancellation)); |
| 14 | + auto ores = manapi::filesystem::fstream::create (std::move(dest), manapi::async::cancellation_action::unit(cancellation)); |
| 15 | + |
| 16 | + if (!ires) |
| 17 | + co_return ires.err(); |
| 18 | + |
| 19 | + if (!ores) |
| 20 | + co_return ores.err(); |
| 21 | + |
| 22 | + input = ires.unwrap(); |
| 23 | + output = ores.unwrap(); |
| 24 | + |
| 25 | + auto oires = co_await input.open(manapi::ev::FS_O_RDONLY); |
| 26 | + if (!oires) { |
| 27 | + manapi_log_trace(manapi::debug::LOG_TRACE_MEDIUM, "%s failed due to %.*s", |
| 28 | + "compress:input open", oires.sysmsg().size(), oires.sysmsg().data()); |
| 29 | + co_return std::move(oires); |
| 30 | + } |
| 31 | + auto oores = co_await output.open(manapi::ev::FS_O_CREAT|manapi::ev::FS_O_TRUNC|manapi::ev::FS_O_WRONLY, |
| 32 | + manapi::ev::IRUSR|manapi::ev::IWUSR|manapi::ev::IRGRP); |
| 33 | + if (!oores) { |
| 34 | + manapi_log_trace(manapi::debug::LOG_TRACE_MEDIUM, "%s failed due to %.*s", |
| 35 | + "compress:output open", oores.sysmsg().size(), oores.sysmsg().data()); |
| 36 | + co_return std::move(oores); |
| 37 | + } |
| 38 | + |
| 39 | + co_return manapi::error::status_ok(); |
| 40 | +} |
| 41 | + |
| 42 | + |
| 43 | +#if MANAPIHTTP_BROTLI_DEPENDENCY |
12 | 44 |
|
13 | 45 | # include <brotli/encode.h> |
14 | 46 | # include <brotli/decode.h> |
@@ -53,36 +85,6 @@ manapi::error::status_or<std::string> manapi::compress::brotli_compress_string(s |
53 | 85 | return error::status_internal("brotli: compress failed"); |
54 | 86 | } |
55 | 87 |
|
56 | | -static manapi::future<manapi::error::status> compress_file_init (manapi::filesystem::fstream &input, manapi::filesystem::fstream &output, std::string src, std::string dest, manapi::async::cancellation_action &cancellation) { |
57 | | - auto ires = manapi::filesystem::fstream::create (std::move(src), manapi::async::cancellation_action::unit(cancellation)); |
58 | | - auto ores = manapi::filesystem::fstream::create (std::move(dest), manapi::async::cancellation_action::unit(cancellation)); |
59 | | - |
60 | | - if (!ires) |
61 | | - co_return ires.err(); |
62 | | - |
63 | | - if (!ores) |
64 | | - co_return ores.err(); |
65 | | - |
66 | | - input = ires.unwrap(); |
67 | | - output = ores.unwrap(); |
68 | | - |
69 | | - auto oires = co_await input.open(manapi::ev::FS_O_RDONLY); |
70 | | - if (!oires) { |
71 | | - manapi_log_trace(manapi::debug::LOG_TRACE_MEDIUM, "%s failed due to %.*s", |
72 | | - "compress:input open", oires.sysmsg().size(), oires.sysmsg().data()); |
73 | | - co_return std::move(oires); |
74 | | - } |
75 | | - auto oores = co_await output.open(manapi::ev::FS_O_CREAT|manapi::ev::FS_O_TRUNC|manapi::ev::FS_O_WRONLY, |
76 | | - manapi::ev::IRUSR|manapi::ev::IWUSR|manapi::ev::IRGRP); |
77 | | - if (!oores) { |
78 | | - manapi_log_trace(manapi::debug::LOG_TRACE_MEDIUM, "%s failed due to %.*s", |
79 | | - "compress:output open", oores.sysmsg().size(), oores.sysmsg().data()); |
80 | | - co_return std::move(oores); |
81 | | - } |
82 | | - |
83 | | - co_return manapi::error::status_ok(); |
84 | | -} |
85 | | - |
86 | 88 | manapi::future<manapi::error::status> manapi::compress::brotli_compress_file(std::string src, std::string dest, int quality, int window, int mode, manapi::async::cancellation_action cancellation) { |
87 | 89 | manapi::filesystem::fstream input, output; |
88 | 90 |
|
@@ -189,7 +191,7 @@ manapi::future<manapi::error::status> manapi::compress::brotli_decompress_file(s |
189 | 191 |
|
190 | 192 | #endif |
191 | 193 |
|
192 | | -#ifdef MANAPIHTTP_ZSTD_DEPENDENCY |
| 194 | +#if MANAPIHTTP_ZSTD_DEPENDENCY |
193 | 195 |
|
194 | 196 | # include <zstd.h> |
195 | 197 |
|
|
0 commit comments