Skip to content

[API Proposal]: make ZipArchive implement IAsyncDisposable #79586

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

Closed
madelson opened this issue Dec 13, 2022 · 2 comments
Closed

[API Proposal]: make ZipArchive implement IAsyncDisposable #79586

madelson opened this issue Dec 13, 2022 · 2 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.IO.Compression
Milestone

Comments

@madelson
Copy link
Contributor

Background and motivation

Disposing of a ZipArchive writes content to the underlying Stream. It would be nice to be able to do this as an async operation.

In particular, #1560 (20 upvotes) describes how not being async in this case will throw errors when writing to a ZipArchive which is an ASP.NET Core response body stream (since those streams do not allow sync IO by default). Streaming directly into a ZipArchive is a nice way to dynamically generate large file exports (e.g. streaming from a database); it's a shame that this doesn't work out of the box without enabling sync IO.

This change would also make partial progress towards supporting #1541 (95 upvotes).

API Proposal

namespace System.IO.Compression;

public class ZipArchive : IDisposable, IAsyncDisposable
{
    public ValueTask DisposeAsync();
}

API Usage

await using ZipArchive zip = new(Response.Body, ZipArchiveMode.Create, leaveOpen: true);
// generate entries here

Alternative Designs

n/a

Risks

No response

@madelson madelson added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Dec 13, 2022
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Dec 13, 2022
@ghost
Copy link

ghost commented Dec 13, 2022

Tagging subscribers to this area: @dotnet/area-system-io-compression
See info in area-owners.md if you want to be subscribed.

Issue Details

Background and motivation

Disposing of a ZipArchive writes content to the underlying Stream. It would be nice to be able to do this as an async operation.

In particular, #1560 (20 upvotes) describes how not being async in this case will throw errors when writing to a ZipArchive which is an ASP.NET Core response body stream (since those streams do not allow sync IO by default). Streaming directly into a ZipArchive is a nice way to dynamically generate large file exports (e.g. streaming from a database); it's a shame that this doesn't work out of the box without enabling sync IO.

This change would also make partial progress towards supporting #1541 (95 upvotes).

API Proposal

namespace System.IO.Compression;

public class ZipArchive : IDisposable, IAsyncDisposable
{
    public ValueTask DisposeAsync();
}

API Usage

await using ZipArchive zip = new(Response.Body, ZipArchiveMode.Create, leaveOpen: true);
// generate entries here

Alternative Designs

n/a

Risks

No response

Author: madelson
Assignees: -
Labels:

api-suggestion, area-System.IO.Compression, untriaged

Milestone: -

@smasher164 smasher164 removed the untriaged New issue has not been triaged by the area owner label Feb 6, 2023
@smasher164 smasher164 added this to the Future milestone Feb 6, 2023
@carlossanlop
Copy link
Member

Duplicate of #1560

@carlossanlop carlossanlop marked this as a duplicate of #1560 Apr 25, 2023
@ghost ghost locked as resolved and limited conversation to collaborators May 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.IO.Compression
Projects
None yet
Development

No branches or pull requests

3 participants