Skip to content
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

zipfile.ZipFile.write should accept fp as argument #56189

Closed
proppy mannequin opened this issue May 2, 2011 · 4 comments
Closed

zipfile.ZipFile.write should accept fp as argument #56189

proppy mannequin opened this issue May 2, 2011 · 4 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@proppy
Copy link
Mannequin

proppy mannequin commented May 2, 2011

BPO 11980
Nosy @terryjreedy, @serhiy-storchaka
Files
  • zipfile-add-writefp.patch: patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2016-05-14.21:15:10.825>
    created_at = <Date 2011-05-02.16:34:51.720>
    labels = ['type-feature', 'library']
    title = 'zipfile.ZipFile.write should accept fp as argument'
    updated_at = <Date 2016-05-14.21:15:10.824>
    user = 'https://bugs.python.org/proppy'

    bugs.python.org fields:

    activity = <Date 2016-05-14.21:15:10.824>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-05-14.21:15:10.825>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2011-05-02.16:34:51.720>
    creator = 'proppy'
    dependencies = []
    files = ['21871']
    hgrepos = []
    issue_num = 11980
    keywords = ['patch']
    message_count = 4.0
    messages = ['134989', '135039', '135396', '265543']
    nosy_count = 4.0
    nosy_names = ['terry.reedy', 'alanmcintyre', 'proppy', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'rejected'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue11980'
    versions = ['Python 3.3']

    @proppy
    Copy link
    Mannequin Author

    proppy mannequin commented May 2, 2011

    Currently it only accept a filename (and writestr only accept bytes).

    @proppy proppy mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels May 2, 2011
    @proppy
    Copy link
    Mannequin Author

    proppy mannequin commented May 3, 2011

    Here is a tentative implementation.

    Feel free to review it.

    @terryjreedy
    Copy link
    Member

    zipfile.ZipFile takes a file arg that can be a 'path to a file (a string) or a file-like object'. The .write() method takes a filename arg. I would think that the proposal should be what the title says, to expand that to a file arg, either a path or 'file', as with ZipFile itself. I cannot think of any reason not to do that.

    The patch adds a separate .writefp method with the file and arcname switched and the compression_type omitted. The code is mostly a duplicated subset of .write. While is proves the concept, none of the differences strike me as good. I think instead there should just be one method that branches, where appropriate, on the type of 'file', just as ZipFile.__init__ does. I admit that I do not understand what .write is supposed to do or does do when filename is a directory.

    The patch includes a test. It still needs doc and News patches, but those come after the basic patch is done.

    @serhiy-storchaka
    Copy link
    Member

    A more general feature is implemented in bpo-26039. Now you can write to ZIP archive the content of opened file object with following two lines:

            with zipf.open('file.txt', 'wb') as target:
                shutil.copyfileobj(source, target)

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants