mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-22 11:46:13 +00:00
Fix #2404 (Refactor make_file_body to improve file handling and scope management)
This commit is contained in:
1 parent
3792ce0da7
commit
cb8365349f
1 file changed
+6
-3
@@ -1062,9 +1062,12 @@ make_file_provider(const std::string &name, const std::string &filepath,
|
|||||||
|
|
||||||
inline std::pair<size_t, ContentProvider>
|
inline std::pair<size_t, ContentProvider>
|
||||||
make_file_body(const std::string &filepath) {
|
make_file_body(const std::string &filepath) {
|
||||||
std::ifstream f(filepath, std::ios::binary | std::ios::ate);
|
size_t size = 0;
|
||||||
if (!f) { return {0, ContentProvider{}}; }
|
{
|
||||||
auto size = static_cast<size_t>(f.tellg());
|
std::ifstream f(filepath, std::ios::binary | std::ios::ate);
|
||||||
|
if (!f) { return {0, ContentProvider{}}; }
|
||||||
|
size = static_cast<size_t>(f.tellg());
|
||||||
|
}
|
||||||
|
|
||||||
ContentProvider provider = [filepath](size_t offset, size_t length,
|
ContentProvider provider = [filepath](size_t offset, size_t length,
|
||||||
DataSink &sink) -> bool {
|
DataSink &sink) -> bool {
|
||||||
|
|||||||
Reference in new issue
Block a user