Skip to content

Bug? - ZipArchive modifies underlying stream even if no archive changes made #34506

@bgribaudo

Description

@bgribaudo

If a ZipArchive instance is created with ZipArchiveMode.Update then disposed without being used to modify the archive, the underlying stream is still modified. If that underlying stream is a FileStream, this results in the associated file's modified timestamp being updated.

void Test() {
  using var stream = new FileStream("Test.zip", FileMode.Open, FileAccess.ReadWrite);
  using (var zip = new ZipArchive(stream, ZipArchiveMode.Update))
  {
     // do nothing
  } // even though the archive was unchanged from the user's perspective, stream is still updated, which changes Test.zip's modified timestamp
}

In contrast, FileStream does not exhibit this behavior. Simply opening a modifiable FileStream does not change the underlying file's modified timestamp.

Is how ZipArchive modifies its backing stream even when the archive is unmodified by the user a bug or a feature? :-)

What would be the chances of ZipArchive's manners being improved to avoid modifying its backing stream in this case?

Thanks!

-- dotnet version: 3.1.200

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.IO.Compressionhelp wanted[up-for-grabs] Good issue for external contributorsin-prThere is an active PR which will close this issue when it is merged

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions