Skip to content

feat(IZipArchiveService): compatible with older versions#7380

Merged
ArgoZhang merged 10 commits intomainfrom
refactor-zip
Dec 20, 2025
Merged

feat(IZipArchiveService): compatible with older versions#7380
ArgoZhang merged 10 commits intomainfrom
refactor-zip

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Dec 20, 2025

Link issues

fixes #7379

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Extend and align the zip archive service API for string-based file inputs while updating sample documentation to reflect the current asynchronous methods.

New Features:

  • Add overloads to the zip archive service to archive collections of file path strings directly, both to a stream and to a target archive file.

Bug Fixes:

  • Skip directory archive entries with empty names and ensure proper asynchronous disposal when writing archive files.

Enhancements:

  • Reuse existing archive entry logic for new string-based overloads to maintain consistent behavior across the zip service API.

Documentation:

  • Update the ZipArchives sample page to document the complete, current set of asynchronous archive and extract methods with consistent parameter naming.

Copilot AI review requested due to automatic review settings December 20, 2025 10:19
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 20, 2025

Reviewer's Guide

Adds string-based overloads to the zip archive service API, adapts the default implementation to use existing entry-based logic with better async disposal and directory handling, and updates the sample Razor page to reflect the current async API surface.

Sequence diagram for the new string based ArchiveAsync overload

sequenceDiagram
    actor Caller
    participant IZipArchiveService
    participant DefaultZipArchiveService
    participant ArchiveFilesAsync
    participant FileSystem

    Caller->>IZipArchiveService: ArchiveAsync(IEnumerable string files, ArchiveOptions options)
    IZipArchiveService->>DefaultZipArchiveService: ArchiveAsync(IEnumerable string files, ArchiveOptions options)

    activate DefaultZipArchiveService
    DefaultZipArchiveService->>DefaultZipArchiveService: Map files to IEnumerable ArchiveEntry
    DefaultZipArchiveService->>DefaultZipArchiveService: ArchiveAsync(IEnumerable ArchiveEntry entries, ArchiveOptions options)

    DefaultZipArchiveService->>ArchiveFilesAsync: ArchiveFilesAsync(Stream stream, IEnumerable ArchiveEntry entries, ArchiveOptions options)
    activate ArchiveFilesAsync

    loop for each ArchiveEntry
        ArchiveFilesAsync->>FileSystem: Check Directory.Exists(SourceFileName)
        alt is directory
            ArchiveFilesAsync->>ArchiveFilesAsync: Validate EntryName not empty
            alt EntryName empty
                ArchiveFilesAsync-->>ArchiveFilesAsync: continue (skip entry)
            else EntryName not empty
                ArchiveFilesAsync->>ArchiveFilesAsync: Ensure EntryName ends with /
                ArchiveFilesAsync-->>ArchiveFilesAsync: Create directory entry
            end
        else is file
            ArchiveFilesAsync->>FileSystem: Check File.Exists(SourceFileName)
            alt file exists
                ArchiveFilesAsync-->>ArchiveFilesAsync: Create file entry and copy contents
            else file missing
                ArchiveFilesAsync-->>ArchiveFilesAsync: skip entry
            end
        end
    end

    deactivate ArchiveFilesAsync
    DefaultZipArchiveService-->>Caller: Stream (in memory archive)
    deactivate DefaultZipArchiveService
Loading

Class diagram for the updated zip archive service API

classDiagram
    class IZipArchiveService {
        +Task~Stream~ ArchiveAsync(IEnumerable~string~ files, ArchiveOptions options)
        +Task ArchiveAsync(string archiveFile, IEnumerable~string~ files, ArchiveOptions options)
        +Task~Stream~ ArchiveAsync(IEnumerable~ArchiveEntry~ entries, ArchiveOptions options)
        +Task ArchiveAsync(string archiveFile, IEnumerable~ArchiveEntry~ entries, ArchiveOptions options)
    }

    class DefaultZipArchiveService {
        +Task~Stream~ ArchiveAsync(IEnumerable~string~ files, ArchiveOptions options)
        +Task ArchiveAsync(string archiveFile, IEnumerable~string~ files, ArchiveOptions options)
        +Task~Stream~ ArchiveAsync(IEnumerable~ArchiveEntry~ entries, ArchiveOptions options)
        +Task ArchiveAsync(string archiveFile, IEnumerable~ArchiveEntry~ entries, ArchiveOptions options)
        -static Task ArchiveFilesAsync(Stream stream, IEnumerable~ArchiveEntry~ entries, ArchiveOptions options)
    }

    class ArchiveEntry {
        +string SourceFileName
        +string EntryName
        +CompressionLevel CompressionLevel
    }

    class ArchiveOptions {
        +CompressionLevel CompressionLevel
    }

    class CompressionLevel

    IZipArchiveService <|.. DefaultZipArchiveService
    DefaultZipArchiveService --> ArchiveEntry
    DefaultZipArchiveService --> ArchiveOptions
    ArchiveEntry --> CompressionLevel
    ArchiveOptions --> CompressionLevel
Loading

File-Level Changes

Change Details Files
Add string-based overloads to the zip archive service interface and implement them in the default service via adaptation to ArchiveEntry-based methods.
  • Introduce ArchiveAsync(IEnumerable files, ArchiveOptions? options = null) to return an in-memory archive stream.
  • Introduce ArchiveAsync(string archiveFile, IEnumerable files, ArchiveOptions? options = null) to write directly to an archive file path.
  • Implement both overloads in DefaultZipArchiveService by projecting file paths into ArchiveEntry objects using SourceFileName and Path.GetFileName for EntryName, then delegating to existing ArchiveAsync overloads.
src/BootstrapBlazor/Services/IZipArchiveService.cs
src/BootstrapBlazor/Services/DefaultZipArchiveService.cs
Improve archiving behavior in DefaultZipArchiveService for file-based output and directory entries.
  • Use await using for the File.OpenWrite stream in ArchiveAsync(string archiveFile, IEnumerable entries, ArchiveOptions? options = null) to ensure proper async disposal.
  • Skip creating archive entries when the directory EntryName is null or empty to avoid invalid entries.
  • Normalize directory EntryName values by appending a trailing '/' when missing before creating entries in the archive.
src/BootstrapBlazor/Services/DefaultZipArchiveService.cs
Update the ZipArchives sample page to match the current async zip archive service API surface and naming.
  • Adjust the sample method signatures to include both string-based and ArchiveEntry-based ArchiveAsync overloads with consistent parameter names.
  • Rename ArchiveDirectory to ArchiveDirectoryAsync in the docs snippet to reflect async naming conventions.
  • Rename ExtractToDirectory to ExtractToDirectoryAsync in the docs snippet to reflect async naming conventions and behavior.
  • Fix a minor BOM-related issue in the Razor file header.
src/BootstrapBlazor.Server/Components/Samples/ZipArchives.razor

Assessment against linked issues

Issue Objective Addressed Explanation
#7379 Add an overload to IZipArchiveService: Task ArchiveAsync(IEnumerable files, ArchiveOptions? options = null) for compatibility with older versions.
#7379 Provide an implementation of Task ArchiveAsync(IEnumerable files, ArchiveOptions? options = null) in the default implementation (DefaultZipArchiveService).

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto bot added the enhancement New feature or request label Dec 20, 2025
@bb-auto bb-auto bot added this to the v10.1.0 milestone Dec 20, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • In the new string-based overloads, EntryName = Path.GetFileName(f) will be empty for directory paths ending in a separator, and with the new if (string.IsNullOrEmpty(entryName)) { continue; } logic those directories will be silently skipped; consider normalizing the path or providing an explicit EntryName for directories so they are archived as expected.
  • The projection from IEnumerable<string> to IEnumerable<ArchiveEntry> is duplicated in both new overloads; factoring this into a small helper method would reduce duplication and make it easier to keep the mapping logic consistent if it changes later.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the new string-based overloads, `EntryName = Path.GetFileName(f)` will be empty for directory paths ending in a separator, and with the new `if (string.IsNullOrEmpty(entryName)) { continue; }` logic those directories will be silently skipped; consider normalizing the path or providing an explicit `EntryName` for directories so they are archived as expected.
- The projection from `IEnumerable<string>` to `IEnumerable<ArchiveEntry>` is duplicated in both new overloads; factoring this into a small helper method would reduce duplication and make it easier to keep the mapping logic consistent if it changes later.

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor.Server/Components/Samples/ZipArchives.razor:26` </location>
<code_context>

 <p>@Localizer["ZipArchiveExtractText"]</p>
-<Pre class="mb-3">bool ExtractToDirectory(string archiveFile, string destinationDirectoryName, bool overwriteFiles = false, Encoding? encoding = null);</Pre>
+<Pre class="mb-3">bool ExtractToDirectoryAsync(string archiveFile, string destinationDirectoryName, bool overwriteFiles = false, Encoding? encoding = null);</Pre>
</code_context>

<issue_to_address>
**issue:** The `ExtractToDirectoryAsync` sample signature looks inconsistent with the async naming convention.

The sample now shows `ExtractToDirectoryAsync` but still returns `bool`. If the API is truly async, this should likely be `Task<bool>` (or `Task`); if it’s synchronous, consider dropping the `Async` suffix to avoid confusion for users of this sample.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Dec 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (395749c) to head (e61595f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7380   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          748       748           
  Lines        32766     32776   +10     
  Branches      4545      4546    +1     
=========================================
+ Hits         32766     32776   +10     
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds backward compatibility methods to the IZipArchiveService interface, allowing consumers to archive files using simpler string-based APIs instead of requiring ArchiveEntry objects. It also includes several code quality improvements and documentation updates.

  • Adds two new overload methods to IZipArchiveService that accept IEnumerable<string> instead of IEnumerable<ArchiveEntry>
  • Updates the default implementation to delegate the new methods to existing methods by converting strings to ArchiveEntry objects
  • Fixes logic issues in directory entry handling and improves async/await usage

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/BootstrapBlazor/Services/IZipArchiveService.cs Adds two new method overloads accepting string file paths for backward compatibility
src/BootstrapBlazor/Services/DefaultZipArchiveService.cs Implements new backward compatibility methods, fixes directory entry logic, and improves async stream disposal
src/BootstrapBlazor.Server/Components/Samples/ZipArchives.razor Updates documentation to reflect all available method signatures and corrects method names

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(IZipArchiveService): compatible with older versions

2 participants