Conversation
Reviewer's GuideAdds asynchronous extraction support and more flexible archiving options to the zip archive service, updates method signatures and documentation, and introduces .NET 10 conditional async implementations while preserving backward compatibility. Sequence diagram for ExtractToDirectoryAsync call flowsequenceDiagram
actor Caller
participant ZipArchiveService as DefaultZipArchiveService
participant ZipFileApi as ZipFile
participant FileSystem
Caller->>ZipArchiveService: ExtractToDirectoryAsync(archiveFile, destinationDirectoryName, overwriteFiles, encoding)
activate ZipArchiveService
ZipArchiveService->>FileSystem: Directory.Exists(destinationDirectoryName)
alt destination does not exist
ZipArchiveService->>FileSystem: Directory.CreateDirectory(destinationDirectoryName)
end
alt NET10_0_OR_GREATER
ZipArchiveService->>ZipFileApi: ExtractToDirectoryAsync(archiveFile, destinationDirectoryName, encoding, overwriteFiles)
Note right of ZipFileApi: await ZipFileApi
else older_framework
ZipArchiveService->>ZipFileApi: ExtractToDirectory(archiveFile, destinationDirectoryName, encoding, overwriteFiles)\nwrapped in Task.Run
Note right of ZipFileApi: await ZipFileApi
end
ZipArchiveService-->>Caller: true
deactivate ZipArchiveService
Class diagram for updated zip archive service APIclassDiagram
class IZipArchiveService {
<<interface>>
Task ArchiveAsync(archiveFile, files, options)
Task ArchiveDirectory(archiveFile, directoryName, compressionLevel, includeBaseDirectory, encoding)
Task ArchiveDirectory(archiveFile, entries, compressionLevel, encoding)
bool ExtractToDirectory(archiveFile, destinationDirectoryName, overwriteFiles, encoding)
Task bool ExtractToDirectoryAsync(archiveFile, destinationDirectoryName, overwriteFiles, encoding)
Stream GetEntry(archiveFile, entryName, encoding)
}
class DefaultZipArchiveService {
Task~Stream~ ArchiveAsync(files, options)
Task ArchiveAsync(archiveFile, files, options)
Task ArchiveDirectory(archiveFile, directoryName, compressionLevel, includeBaseDirectory, encoding)
Task ArchiveDirectory(archiveFile, entries, compressionLevel, encoding)
bool ExtractToDirectory(archiveFile, destinationDirectoryName, overwriteFiles, encoding)
Task bool ExtractToDirectoryAsync(archiveFile, destinationDirectoryName, overwriteFiles, encoding)
Stream GetEntry(archiveFile, entryName, encoding)
static Task ArchiveFilesAsync(stream, files, options)
static void AddFolderToZip(archive, folderPath, relativePath, compressionLevel)
}
IZipArchiveService <|.. DefaultZipArchiveService
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 there - I've reviewed your changes - here's some feedback:
- In
ArchiveDirectory(string archiveFile, IEnumerable<string> entries, ...),AddFolderToZipbuilds entry names withPath.Combine, which can introduce OS-specific path separators into ZIP entries; consider normalizing to'/' in the archive paths to ensure consistent cross-platform behavior. - For the pre-NET10_0 branches in
ArchiveDirectoryandExtractToDirectoryAsync, the use ofTask.RunaroundZipFileAPIs can consume thread-pool threads for long-running I/O; if these methods are called at scale, you may want to consider a non-Task.Runapproach or a dedicated background scheduler to avoid potential thread starvation.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `ArchiveDirectory(string archiveFile, IEnumerable<string> entries, ...)`, `AddFolderToZip` builds entry names with `Path.Combine`, which can introduce OS-specific path separators into ZIP entries; consider normalizing to `'/`' in the archive paths to ensure consistent cross-platform behavior.
- For the pre-NET10_0 branches in `ArchiveDirectory` and `ExtractToDirectoryAsync`, the use of `Task.Run` around `ZipFile` APIs can consume thread-pool threads for long-running I/O; if these methods are called at scale, you may want to consider a non-`Task.Run` approach or a dedicated background scheduler to avoid potential thread starvation.
## Individual Comments
### Comment 1
<location> `src/BootstrapBlazor/Services/DefaultZipArchiveService.cs:116-118` </location>
<code_context>
+ // 添加当前文件夹中的所有文件
+ foreach (string filePath in Directory.GetFiles(folderPath))
+ {
+ string entryName = Path.Combine(relativePath, Path.GetFileName(filePath));
+ archive.CreateEntryFromFile(filePath, entryName, compressionLevel);
+ }
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Using `Path.Combine` for ZIP entry names may introduce platform-specific separators into the archive.
ZIP entries should use `/` as the directory separator, but `Path.Combine` uses the OS-specific separator (e.g., `\` on Windows), which can reduce cross-platform compatibility with other tools. Instead, construct the entry name with `'/'` (for example, `relativePath + "/" + Path.GetFileName(filePath)` or `string.Join('/', ...)`) so the archive remains portable.
```suggestion
// 添加当前文件夹中的所有文件
foreach (string filePath in Directory.GetFiles(folderPath))
{
var fileName = Path.GetFileName(filePath);
var entryName = string.IsNullOrEmpty(relativePath)
? fileName
: $"{relativePath}/{fileName}";
archive.CreateEntryFromFile(filePath, entryName, compressionLevel);
}
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7272 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 745 745
Lines 32586 32621 +35
Branches 4516 4522 +6
=========================================
+ Hits 32586 32621 +35
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 an asynchronous ExtractToDirectoryAsync method to the IZipArchiveService interface and its implementation, along with a new ArchiveDirectory overload that accepts a collection of file/directory entries. The PR also standardizes parameter naming by renaming archiveFileName to archiveFile across the interface and implementation, and updates the package version from beta to release.
- Adds
ExtractToDirectoryAsyncmethod with .NET 9+ optimization - Introduces
ArchiveDirectoryoverload for archiving multiple entries - Standardizes parameter naming from
archiveFileNametoarchiveFile
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| src/BootstrapBlazor/Services/IZipArchiveService.cs | Adds interface definition for ExtractToDirectoryAsync and new ArchiveDirectory overload; renames parameters for consistency |
| src/BootstrapBlazor/Services/DefaultZipArchiveService.cs | Implements new async extraction method with conditional compilation for .NET 9+; implements new archive overload with helper method for recursive folder processing |
| src/BootstrapBlazor/BootstrapBlazor.csproj | Updates package version from 10.1.2-beta01 to 10.1.2 release |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Link issues
fixes #7271
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Add asynchronous ZIP extraction support and extend archive directory options in the ZIP archive service.
New Features:
Enhancements: