Skip to content

Modification to enable producing consistent binary output#495

Merged
jmcnamara merged 2 commits into
jmcnamara:masterfrom
ziembla:ziembla-mod
Apr 14, 2018
Merged

Modification to enable producing consistent binary output#495
jmcnamara merged 2 commits into
jmcnamara:masterfrom
ziembla:ziembla-mod

Conversation

@ziembla
Copy link
Copy Markdown
Contributor

@ziembla ziembla commented Mar 28, 2018

Enabling consistent binary output by taking creation time from the metadata (if set) and:

  1. using ZipInfo structure with that date for in-memory zipping

  2. setting temporary files' modification time to that date with file-based zipping.

For more info see issue #494.

Usage:

from datetime import datetime
import xlsxwriter
import zipfile

options, properties = {}, {}
options = {'in_memory': True}
properties = {'created':  datetime(2017, 12, 31, 23, 59, 58)}
# properties = {'created':  datetime.now().date()}

path = 'demo.xlsx'

with xlsxwriter.Workbook(path, options) as workbook:
    if properties:
        workbook.set_properties(properties)
    worksheet = workbook.add_worksheet()
    worksheet.write('A1', 'abc')

with zipfile.ZipFile(path, 'r') as archive:
    for info in sorted(archive.infolist(), key=lambda i: i.filename):
        print("{} {}".format(datetime(*info.date_time).strftime("%Y-%m-%d %H:%M:%S"), info.filename))

@jmcnamara jmcnamara merged commit ce5cbab into jmcnamara:master Apr 14, 2018
@jmcnamara
Copy link
Copy Markdown
Owner

Merged. Thanks.

@ziembla
Copy link
Copy Markdown
Contributor Author

ziembla commented Apr 23, 2018

The pleasure is mine :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants