Support info.size on wide-char systems via upgrade to C++17 #3943

This commit is contained in:
Lovell Fuller
2024-11-04 18:16:29 +00:00
parent 7bdf419eb1
commit 06b08bf10f
8 changed files with 43 additions and 48 deletions

View File

@@ -3,6 +3,7 @@
#include <algorithm>
#include <cmath>
#include <filesystem>
#include <map>
#include <memory>
#include <numeric>
@@ -20,17 +21,6 @@
#include "operations.h"
#include "pipeline.h"
#ifdef _WIN32
#define STAT64_STRUCT __stat64
#define STAT64_FUNCTION _stat64
#elif defined(_LARGEFILE64_SOURCE)
#define STAT64_STRUCT stat64
#define STAT64_FUNCTION stat64
#else
#define STAT64_STRUCT stat
#define STAT64_FUNCTION stat
#endif
class PipelineWorker : public Napi::AsyncWorker {
public:
PipelineWorker(Napi::Function callback, PipelineBaton *baton,
@@ -1306,9 +1296,11 @@ class PipelineWorker : public Napi::AsyncWorker {
Callback().Call(Receiver().Value(), { env.Null(), data, info });
} else {
// Add file size to info
struct STAT64_STRUCT st;
if (STAT64_FUNCTION(baton->fileOut.data(), &st) == 0) {
info.Set("size", static_cast<uint32_t>(st.st_size));
if (baton->formatOut != "dz" || sharp::IsDzZip(baton->fileOut)) {
try {
uint32_t const size = static_cast<uint32_t>(std::filesystem::file_size(baton->fileOut));
info.Set("size", size);
} catch (...) {}
}
Callback().Call(Receiver().Value(), { env.Null(), info });
}