New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modification to enable producing consistent binary output #495

Merged
merged 2 commits into from Apr 14, 2018

Conversation

2 participants
@ziembla
Contributor

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

2 checks passed

codeclimate All good!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@jmcnamara

This comment has been minimized.

Owner

jmcnamara commented Apr 14, 2018

Merged. Thanks.

@ziembla

This comment has been minimized.

Contributor

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