ebooklib icon indicating copy to clipboard operation
ebooklib copied to clipboard

EpubWriter: use the mtime option as the date_time value of zip metadata

Open Arwalk opened this issue 7 months ago • 0 comments

Hello there, thanks for this great library.

This pull-request changes sligthly the logic to reuse the "mtime" option as the zip-file metadata "date_time".

As I was generating multiple times the same epub with the exact same content, i was surprised to see that md5 hashes weren't matching for successive generations.

the zipfile library takes a new timestamp at each use of the writestr method to set the "date_time" metadata corresponding to the last modification of the zip file.

This pull requests:

  • sets a new datetime in the mtime option when initializing a new EpubWriter object
  • lets this option still be overriden as expected, for the epub metadata
  • reuse this mtime option value to fill the metadata of the zip file when writing.

This means:

  • the zip file date_time metadata is always aligned with the epub metadata (not very important but i guess it can be nice for consistency)
  • when a user sets the mtime option, for the same exact content, the epub file obtained will be exactly the same, byte for byte, allowing reproducible builds.

I guess reproducible builds are not exactly a priority, but this could be useful for testing, publishing, and trusting any tool that uses this library.

Thanks again, i'm waiting for your comments and feedback on this.

Arwalk avatar May 17 '25 20:05 Arwalk