feat(IZipArchiveService): compatible with older versions#7380
feat(IZipArchiveService): compatible with older versions#7380
Conversation
Reviewer's GuideAdds 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 overloadsequenceDiagram
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
Class diagram for the updated zip archive service APIclassDiagram
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
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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 newif (string.IsNullOrEmpty(entryName)) { continue; }logic those directories will be silently skipped; consider normalizing the path or providing an explicitEntryNamefor directories so they are archived as expected. - The projection from
IEnumerable<string>toIEnumerable<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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
src/BootstrapBlazor.Server/Components/Samples/ZipArchives.razor
Outdated
Show resolved
Hide resolved
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
IZipArchiveServicethat acceptIEnumerable<string>instead ofIEnumerable<ArchiveEntry> - Updates the default implementation to delegate the new methods to existing methods by converting strings to
ArchiveEntryobjects - 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.
Link issues
fixes #7379
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
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:
Bug Fixes:
Enhancements:
Documentation: