Closed Togtja closed 3 years ago
Afaik when doing this:
std::ifstream inp("test.txt");
zip.add(inp, "test.txt");
inp has lost its filename so it'll be difficult to get its timestamp.
That is true, but when you call zip.add("test.txt");
you can grap the file date.
In the case of zip.add(inp, "test.txt")
I beleve the default time date should be now()
i.e the date/time you currently are in right now
We can add helper Class methods:
Timestamp(filepath) = timestamp for filepath
Timestamp() = now()
And pass them as default paramas #97 is merged, I will close this
When zipping files on a system, make the timestamp of the file a part of the zipping.
Currently, unless you specify the timestamp yourself, Zipper gives an empty
std::tm
:The file timestamp will look like this:
Now currently, as stated you can give a timestamp yourself, so the workaround would be something like this:
One issue is that converting
std::chrono::file_clock
tostd::chrono::system_clock
to then usesystem_clock
'sto_time_t
, now there should be UNIX and Windows call to more accurately get a file's timestamp.C++20
seeks to fix this issue. Another is the very minor inaccuracy as I call::now()
twice to convert to the time. see SO for more details.Anyways the result in this: It is decades more accurate than what is currently here, and cross-platform. However to be very proper (before
C++20
), then a timestamp on unix would look something like this:On Windows, you probably need to call GetFileTime from the API. I am not a windows machine for the moment, so can't draft anything.
It would be really nice if the timestamp got set automatically when calling the
bool Zipper::add(const std::string& fileOrFolderPath, zipFlags flags)
constructor, as there you have to open the file/folder and can also do this read. `