Implement comprehensive zip archive functionality with progress tracking

 ZipArchiveBuilder - Core compression engine:
  • Built on System.IO.Compression (.NET Standard 2.0 built-in)
  • Real-time progress tracking with events
  • Start/end time tracking with duration calculation
  • Size metrics (compressed/uncompressed) and compression ratios
  • FileSystemInfo support (FileInfo, DirectoryInfo)
  • Append support via ZipArchiveMode.Update
  • Compression efficiency calculations

 ZipBuilder - PowerShell integration layer:
  • ThreadSafeProgressCollector integration
  • Multi-layer progress tracking (Zip + File levels)
  • Verbose logging with comprehensive metrics
  • ZipCreationResult object for PowerShell output
  • Event-driven progress reporting

 New-MinIOZipArchive cmdlet - Well-structured PowerShell interface:
  • Files parameter set: FileInfo[] support for multiple files
  • Directory parameter set: DirectoryInfo with recursive options
  • File filtering: InclusionFilter/ExclusionFilter ScriptBlocks
  • Compression levels: Optimal, Fastest, NoCompression
  • Archive modes: Create, Update (for appending)
  • BasePath parameter for custom entry name control
  • Force parameter for overwriting existing archives
  • PassThru parameter for detailed result objects

 Advanced features:
  • Progress tracking: Real-time speed and ETA calculations
  • Metrics: Compression ratio, space saved, processing time
  • File filtering: ScriptBlock-based inclusion/exclusion
  • Path handling: Cross-platform compatibility
  • Error handling: Comprehensive validation and recovery
  • Memory efficiency: 80KB buffer for optimal throughput

 Integration benefits:
  • No external dependencies (uses built-in .NET compression)
  • Thread-safe operations compatible with PSMinIO architecture
  • Consistent with existing progress tracking patterns
  • Minimal footprint aligning with project preferences
  • Enterprise-grade functionality with comprehensive metrics

Architecture: Built on System.IO.Compression with custom progress tracking,
providing superior zip functionality with PowerShell-native integration.
This commit is contained in:
PSMinIO Developer
2025-07-11 21:00:14 -04:00
parent 6f693d7236
commit f420effc84
12 changed files with 1499 additions and 1 deletions
+29
View File
@@ -0,0 +1,29 @@
# Check what parameters are available for New-MinIOObject
Import-Module ".\Module\PSMinIO\PSMinIO.psd1" -Force
Write-Host "=== New-MinIOObject Parameter Information ===" -ForegroundColor Cyan
# Get command info
$cmdInfo = Get-Command New-MinIOObject
Write-Host "`nParameter Sets:" -ForegroundColor Yellow
foreach ($paramSet in $cmdInfo.ParameterSets) {
Write-Host " $($paramSet.Name):" -ForegroundColor Green
foreach ($param in $paramSet.Parameters) {
if ($param.Name -notin @('Verbose', 'Debug', 'ErrorAction', 'WarningAction', 'InformationAction', 'ErrorVariable', 'WarningVariable', 'InformationVariable', 'OutVariable', 'OutBuffer', 'PipelineVariable', 'WhatIf', 'Confirm')) {
$mandatory = if ($param.IsMandatory) { " (Mandatory)" } else { "" }
$aliases = if ($param.Aliases.Count -gt 0) { " [Aliases: $($param.Aliases -join ', ')]" } else { "" }
Write-Host " - $($param.Name)$mandatory$aliases" -ForegroundColor White
}
}
Write-Host ""
}
Write-Host "All Parameters:" -ForegroundColor Yellow
foreach ($param in $cmdInfo.Parameters.Values) {
if ($param.Name -notin @('Verbose', 'Debug', 'ErrorAction', 'WarningAction', 'InformationAction', 'ErrorVariable', 'WarningVariable', 'InformationVariable', 'OutVariable', 'OutBuffer', 'PipelineVariable', 'WhatIf', 'Confirm')) {
$aliases = if ($param.Aliases.Count -gt 0) { " [Aliases: $($param.Aliases -join ', ')]" } else { "" }
$paramSets = $param.ParameterSets.Keys -join ', '
Write-Host " $($param.Name)$aliases - Sets: $paramSets" -ForegroundColor White
}
}
+156
View File
@@ -0,0 +1,156 @@
# Test script for uploading 50 test files to demonstrate enhanced upload functionality
# This tests FileInfo[] support, multi-layer progress tracking, and BucketDirectory features
param(
[string]$TestBucketName = "psminiotest-50files-$(Get-Date -Format 'yyyyMMdd-HHmmss')",
[string]$TestDirectory = "TestFiles50",
[switch]$Cleanup,
[switch]$Verbose
)
# Set verbose preference if requested
if ($Verbose) {
$VerbosePreference = 'Continue'
}
Write-Host "=== PSMinIO 50-File Upload Test ===" -ForegroundColor Cyan
Write-Host "Testing enhanced upload functionality with multi-layer progress tracking" -ForegroundColor Green
try {
# Import the module
Write-Host "`n1. Loading PSMinIO module..." -ForegroundColor Yellow
Import-Module ".\Module\PSMinIO\PSMinIO.psd1" -Force
# Connect to MinIO
Write-Host "2. Connecting to MinIO..." -ForegroundColor Yellow
Connect-MinIO -Endpoint "https://api.s3.gracesolution.info" -AccessKey "T34Wg85SAwezUa3sk3m4" -SecretKey "PxEmnbQoQJTJsDocSEV6mSSscDpJMiJCayPv93xe"
Write-Host "✅ Connected successfully!" -ForegroundColor Green
# Create test directory and files
Write-Host "`n3. Creating test files..." -ForegroundColor Yellow
if (Test-Path $TestDirectory) {
Remove-Item $TestDirectory -Recurse -Force
}
New-Item -ItemType Directory -Path $TestDirectory -Force | Out-Null
# Create 50 test files with varying sizes and content
$testFiles = @()
for ($i = 1; $i -le 50; $i++) {
$fileName = "testfile-{0:D3}.txt" -f $i
$filePath = Join-Path $TestDirectory $fileName
# Create files with different sizes (1KB to 100KB)
$fileSize = Get-Random -Minimum 1024 -Maximum 102400
$content = "Test file $i`n" + ("X" * ($fileSize - 20))
Set-Content -Path $filePath -Value $content -NoNewline
$testFiles += Get-Item $filePath
}
Write-Host "✅ Created 50 test files (total size: $((($testFiles | Measure-Object Length -Sum).Sum / 1MB).ToString('F2')) MB)" -ForegroundColor Green
# Create test bucket
Write-Host "`n4. Creating test bucket: $TestBucketName" -ForegroundColor Yellow
New-MinIOBucket -BucketName $TestBucketName
Write-Host "✅ Bucket created successfully!" -ForegroundColor Green
# Test 1: Upload all files using FileInfo[] parameter
Write-Host "`n5. Test 1: Uploading 50 files using FileInfo[] parameter..." -ForegroundColor Yellow
Write-Host " This will demonstrate multi-layer progress tracking:" -ForegroundColor Cyan
Write-Host " • Layer 1: Collection progress (overall files)" -ForegroundColor Cyan
Write-Host " • Layer 2: File progress (current file)" -ForegroundColor Cyan
Write-Host " • Layer 3: Transfer progress (bytes)" -ForegroundColor Cyan
$uploadStart = Get-Date
$uploadResults = New-MinIOObject -BucketName $TestBucketName -Files $testFiles -BucketDirectory "batch-upload" -PassThru -Verbose
$uploadDuration = (Get-Date) - $uploadStart
Write-Host "✅ Upload completed in $($uploadDuration.TotalSeconds.ToString('F2')) seconds!" -ForegroundColor Green
Write-Host " Average speed: $(($uploadResults | Measure-Object TotalSize -Sum).Sum / $uploadDuration.TotalSeconds / 1MB | ForEach-Object { $_.ToString('F2') }) MB/s" -ForegroundColor Green
Write-Host " Files uploaded: $($uploadResults.Count)" -ForegroundColor Green
# Test 2: Upload using Directory parameter with BucketDirectory
Write-Host "`n6. Test 2: Uploading directory with BucketDirectory parameter..." -ForegroundColor Yellow
$dirUploadStart = Get-Date
$dirUploadResults = New-MinIOObject -BucketName $TestBucketName -Directory (Get-Item $TestDirectory) -BucketDirectory "directory-upload/nested/structure" -PassThru -Verbose
$dirUploadDuration = (Get-Date) - $dirUploadStart
Write-Host "✅ Directory upload completed in $($dirUploadDuration.TotalSeconds.ToString('F2')) seconds!" -ForegroundColor Green
Write-Host " Files uploaded: $($dirUploadResults.Count)" -ForegroundColor Green
# Test 3: Verify uploads by listing objects
Write-Host "`n7. Verifying uploads..." -ForegroundColor Yellow
$allObjects = Get-MinIOObject -BucketName $TestBucketName
$batchObjects = $allObjects | Where-Object { $_.Name -like "batch-upload/*" }
$dirObjects = $allObjects | Where-Object { $_.Name -like "directory-upload/*" }
Write-Host "✅ Verification complete:" -ForegroundColor Green
Write-Host " Total objects in bucket: $($allObjects.Count)" -ForegroundColor Green
Write-Host " Batch upload objects: $($batchObjects.Count)" -ForegroundColor Green
Write-Host " Directory upload objects: $($dirObjects.Count)" -ForegroundColor Green
# Test 4: Test with filters (create subdirectories first)
Write-Host "`n8. Test 3: Testing directory upload with filters..." -ForegroundColor Yellow
# Create subdirectories with different file types
$subDir1 = Join-Path $TestDirectory "SubDir1"
$subDir2 = Join-Path $TestDirectory "SubDir2"
New-Item -ItemType Directory -Path $subDir1 -Force | Out-Null
New-Item -ItemType Directory -Path $subDir2 -Force | Out-Null
# Create some .log and .json files
for ($i = 1; $i -le 5; $i++) {
Set-Content -Path (Join-Path $subDir1 "logfile$i.log") -Value "Log entry $i"
Set-Content -Path (Join-Path $subDir2 "config$i.json") -Value "{`"test`": $i}"
}
# Upload only .log files using inclusion filter
$filterStart = Get-Date
$filterResults = New-MinIOObject -BucketName $TestBucketName -Directory (Get-Item $TestDirectory) -Recursive -InclusionFilter { $_.Extension -eq ".log" } -BucketDirectory "filtered-upload" -PassThru -Verbose
$filterDuration = (Get-Date) - $filterStart
Write-Host "✅ Filtered upload completed in $($filterDuration.TotalSeconds.ToString('F2')) seconds!" -ForegroundColor Green
Write-Host " Log files uploaded: $($filterResults.Count)" -ForegroundColor Green
# Summary
Write-Host "`n=== TEST SUMMARY ===" -ForegroundColor Cyan
Write-Host "✅ All tests completed successfully!" -ForegroundColor Green
Write-Host "Features tested:" -ForegroundColor Yellow
Write-Host " • FileInfo[] parameter with 50 files" -ForegroundColor White
Write-Host " • Multi-layer progress tracking (3 layers)" -ForegroundColor White
Write-Host " • BucketDirectory parameter for nested structures" -ForegroundColor White
Write-Host " • Directory parameter with recursive upload" -ForegroundColor White
Write-Host " • InclusionFilter for selective file upload" -ForegroundColor White
Write-Host " • PassThru parameter for upload results" -ForegroundColor White
Write-Host " • Thread-safe progress reporting" -ForegroundColor White
Write-Host "`nPerformance metrics:" -ForegroundColor Yellow
Write-Host " • Batch upload: $($uploadDuration.TotalSeconds.ToString('F2'))s for $($uploadResults.Count) files" -ForegroundColor White
Write-Host " • Directory upload: $($dirUploadDuration.TotalSeconds.ToString('F2'))s for $($dirUploadResults.Count) files" -ForegroundColor White
Write-Host " • Filtered upload: $($filterDuration.TotalSeconds.ToString('F2'))s for $($filterResults.Count) files" -ForegroundColor White
# Cleanup option
if ($Cleanup) {
Write-Host "`n9. Cleaning up..." -ForegroundColor Yellow
Remove-MinIOBucket -BucketName $TestBucketName -Force
Remove-Item $TestDirectory -Recurse -Force
Write-Host "✅ Cleanup completed!" -ForegroundColor Green
} else {
Write-Host "`nTest bucket '$TestBucketName' and files preserved for inspection." -ForegroundColor Cyan
Write-Host "Use -Cleanup parameter to automatically clean up test resources." -ForegroundColor Cyan
}
} catch {
Write-Host "❌ Test failed: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "Stack trace: $($_.ScriptStackTrace)" -ForegroundColor Red
} finally {
# Clean up test files if they exist
if (Test-Path $TestDirectory) {
Write-Host "`nCleaning up local test files..." -ForegroundColor Yellow
Remove-Item $TestDirectory -Recurse -Force -ErrorAction SilentlyContinue
}
}
Write-Host "`n=== Test Complete ===" -ForegroundColor Cyan
+117
View File
@@ -0,0 +1,117 @@
# Test script for current upload functionality (single file version)
param(
[string]$TestBucketName = "psminiotest-current-$(Get-Date -Format 'yyyyMMdd-HHmmss')",
[switch]$Cleanup,
[switch]$Verbose
)
if ($Verbose) {
$VerbosePreference = 'Continue'
}
Write-Host "=== PSMinIO Current Upload Test ===" -ForegroundColor Cyan
Write-Host "Testing current upload functionality" -ForegroundColor Green
try {
# Import the module
Write-Host "`n1. Loading PSMinIO module..." -ForegroundColor Yellow
Import-Module ".\Module\PSMinIO\PSMinIO.psd1" -Force
# Connect to MinIO
Write-Host "2. Connecting to MinIO..." -ForegroundColor Yellow
Connect-MinIO -Endpoint "https://api.s3.gracesolution.info" -AccessKey "T34Wg85SAwezUa3sk3m4" -SecretKey "PxEmnbQoQJTJsDocSEV6mSSscDpJMiJCayPv93xe"
Write-Host "✅ Connected successfully!" -ForegroundColor Green
# Create test files
Write-Host "`n3. Creating test files..." -ForegroundColor Yellow
$testDir = "TestFilesCurrent"
if (Test-Path $testDir) {
Remove-Item $testDir -Recurse -Force
}
New-Item -ItemType Directory -Path $testDir -Force | Out-Null
# Create 10 test files
$testFiles = @()
for ($i = 1; $i -le 10; $i++) {
$fileName = "testfile-{0:D3}.txt" -f $i
$filePath = Join-Path $testDir $fileName
$content = "Test file $i - $(Get-Date)`n" + ("Content line $i`n" * 10)
Set-Content -Path $filePath -Value $content
$testFiles += Get-Item $filePath
}
Write-Host "✅ Created 10 test files" -ForegroundColor Green
# Create test bucket
Write-Host "`n4. Creating test bucket: $TestBucketName" -ForegroundColor Yellow
New-MinIOBucket -BucketName $TestBucketName
Write-Host "✅ Bucket created successfully!" -ForegroundColor Green
# Test uploading files one by one (current functionality)
Write-Host "`n5. Uploading files individually..." -ForegroundColor Yellow
$uploadResults = @()
$uploadStart = Get-Date
foreach ($file in $testFiles) {
Write-Host " Uploading: $($file.Name)" -ForegroundColor Cyan
$result = New-MinIOObject -BucketName $TestBucketName -File $file -BucketDirectory "individual-uploads" -PassThru -Verbose
$uploadResults += $result
}
$uploadDuration = (Get-Date) - $uploadStart
Write-Host "✅ Upload completed in $($uploadDuration.TotalSeconds.ToString('F2')) seconds!" -ForegroundColor Green
Write-Host " Files uploaded: $($uploadResults.Count)" -ForegroundColor Green
# Verify uploads
Write-Host "`n6. Verifying uploads..." -ForegroundColor Yellow
$objects = Get-MinIOObject -BucketName $TestBucketName
Write-Host "✅ Found $($objects.Count) objects in bucket" -ForegroundColor Green
# Test with different bucket directories
Write-Host "`n7. Testing nested bucket directories..." -ForegroundColor Yellow
$nestedResults = @()
foreach ($file in $testFiles[0..2]) { # Upload first 3 files to nested structure
$result = New-MinIOObject -BucketName $TestBucketName -File $file -BucketDirectory "level1/level2/level3" -PassThru -Verbose
$nestedResults += $result
}
Write-Host "✅ Nested directory upload completed: $($nestedResults.Count) files" -ForegroundColor Green
# Final verification
Write-Host "`n8. Final verification..." -ForegroundColor Yellow
$allObjects = Get-MinIOObject -BucketName $TestBucketName
$individualObjects = $allObjects | Where-Object { $_.Name -like "individual-uploads/*" }
$nestedObjects = $allObjects | Where-Object { $_.Name -like "level1/level2/level3/*" }
Write-Host "✅ Final verification complete:" -ForegroundColor Green
Write-Host " Total objects: $($allObjects.Count)" -ForegroundColor Green
Write-Host " Individual uploads: $($individualObjects.Count)" -ForegroundColor Green
Write-Host " Nested uploads: $($nestedObjects.Count)" -ForegroundColor Green
# Summary
Write-Host "`n=== TEST SUMMARY ===" -ForegroundColor Cyan
Write-Host "✅ Current functionality test completed!" -ForegroundColor Green
Write-Host "Features tested:" -ForegroundColor Yellow
Write-Host " • Single file upload with File parameter" -ForegroundColor White
Write-Host " • BucketDirectory parameter for nested structures" -ForegroundColor White
Write-Host " • PassThru parameter for upload results" -ForegroundColor White
Write-Host " • Multiple individual uploads" -ForegroundColor White
Write-Host " • Nested directory structure creation" -ForegroundColor White
Write-Host "`nNote: Enhanced features (FileInfo[], Directory, Multi-layer progress) require updated DLL" -ForegroundColor Yellow
if ($Cleanup) {
Write-Host "`n9. Cleaning up..." -ForegroundColor Yellow
Remove-MinIOBucket -BucketName $TestBucketName -Force
Write-Host "✅ Cleanup completed!" -ForegroundColor Green
}
} catch {
Write-Host "❌ Test failed: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "Stack trace: $($_.ScriptStackTrace)" -ForegroundColor Red
} finally {
if (Test-Path $testDir) {
Remove-Item $testDir -Recurse -Force -ErrorAction SilentlyContinue
}
}
Write-Host "`n=== Test Complete ===" -ForegroundColor Cyan
+174
View File
@@ -0,0 +1,174 @@
# Test script for the new New-MinIOZipArchive cmdlet
# Demonstrates comprehensive zip functionality with progress tracking
param(
[string]$TestDirectory = "TestZipFiles",
[switch]$Cleanup,
[switch]$Verbose
)
if ($Verbose) {
$VerbosePreference = 'Continue'
}
Write-Host "=== PSMinIO Zip Archive Test ===" -ForegroundColor Cyan
Write-Host "Testing New-MinIOZipArchive cmdlet with comprehensive functionality" -ForegroundColor Green
try {
# Import the module
Write-Host "`n1. Loading PSMinIO module..." -ForegroundColor Yellow
Import-Module ".\Module\PSMinIO\PSMinIO.psd1" -Force
# Create test directory and files
Write-Host "2. Creating test files..." -ForegroundColor Yellow
if (Test-Path $TestDirectory) {
Remove-Item $TestDirectory -Recurse -Force
}
New-Item -ItemType Directory -Path $TestDirectory -Force | Out-Null
# Create main directory files
for ($i = 1; $i -le 10; $i++) {
$fileName = "document-{0:D2}.txt" -f $i
$filePath = Join-Path $TestDirectory $fileName
$content = "Document $i`n" + ("Sample content line $i`n" * (Get-Random -Minimum 5 -Maximum 20))
Set-Content -Path $filePath -Value $content
}
# Create subdirectories with different file types
$subDir1 = Join-Path $TestDirectory "Reports"
$subDir2 = Join-Path $TestDirectory "Data"
$subDir3 = Join-Path $TestDirectory "Logs"
New-Item -ItemType Directory -Path $subDir1, $subDir2, $subDir3 -Force | Out-Null
# Add files to subdirectories
for ($i = 1; $i -le 5; $i++) {
Set-Content -Path (Join-Path $subDir1 "report$i.txt") -Value "Report $i content"
Set-Content -Path (Join-Path $subDir2 "data$i.csv") -Value "ID,Name,Value`n$i,Item$i,$(Get-Random -Minimum 100 -Maximum 1000)"
Set-Content -Path (Join-Path $subDir3 "app$i.log") -Value "$(Get-Date) - Log entry $i"
}
$allFiles = Get-ChildItem $TestDirectory -Recurse -File
Write-Host "✅ Created test structure: $($allFiles.Count) files in multiple directories" -ForegroundColor Green
# Test 1: Create zip from FileInfo array
Write-Host "`n3. Test 1: Creating zip from FileInfo array..." -ForegroundColor Yellow
$mainFiles = Get-ChildItem $TestDirectory -File
$zipPath1 = "test-files-array.zip"
Write-Host " Creating zip with $($mainFiles.Count) files using Files parameter set" -ForegroundColor Cyan
$result1 = New-MinIOZipArchive -DestinationPath $zipPath1 -Path $mainFiles -CompressionLevel Optimal -PassThru -Verbose
Write-Host "✅ Files array zip created:" -ForegroundColor Green
Write-Host " Files: $($result1.FileCount)" -ForegroundColor White
Write-Host " Original size: $([math]::Round($result1.TotalUncompressedSize / 1KB, 2)) KB" -ForegroundColor White
Write-Host " Compressed size: $([math]::Round($result1.TotalCompressedSize / 1KB, 2)) KB" -ForegroundColor White
Write-Host " Compression: $($result1.CompressionEfficiency.ToString('F1'))%" -ForegroundColor White
Write-Host " Duration: $($result1.Duration.TotalSeconds.ToString('F2'))s" -ForegroundColor White
# Test 2: Create zip from directory (non-recursive)
Write-Host "`n4. Test 2: Creating zip from directory (non-recursive)..." -ForegroundColor Yellow
$zipPath2 = "test-directory-flat.zip"
Write-Host " Creating zip from directory (top-level files only)" -ForegroundColor Cyan
$result2 = New-MinIOZipArchive -DestinationPath $zipPath2 -Directory (Get-Item $TestDirectory) -CompressionLevel Fastest -PassThru -Verbose
Write-Host "✅ Directory flat zip created:" -ForegroundColor Green
Write-Host " Files: $($result2.FileCount)" -ForegroundColor White
Write-Host " Compression: $($result2.CompressionEfficiency.ToString('F1'))%" -ForegroundColor White
# Test 3: Create zip from directory (recursive)
Write-Host "`n5. Test 3: Creating zip from directory (recursive)..." -ForegroundColor Yellow
$zipPath3 = "test-directory-recursive.zip"
Write-Host " Creating zip from directory (recursive, all subdirectories)" -ForegroundColor Cyan
$result3 = New-MinIOZipArchive -DestinationPath $zipPath3 -Directory (Get-Item $TestDirectory) -Recursive -IncludeBaseDirectory -CompressionLevel Optimal -PassThru -Verbose
Write-Host "✅ Directory recursive zip created:" -ForegroundColor Green
Write-Host " Files: $($result3.FileCount)" -ForegroundColor White
Write-Host " Compression: $($result3.CompressionEfficiency.ToString('F1'))%" -ForegroundColor White
# Test 4: Create zip with file filtering
Write-Host "`n6. Test 4: Creating zip with file filtering..." -ForegroundColor Yellow
$zipPath4 = "test-filtered-logs.zip"
Write-Host " Creating zip with only .log files using InclusionFilter" -ForegroundColor Cyan
$result4 = New-MinIOZipArchive -DestinationPath $zipPath4 -Directory (Get-Item $TestDirectory) -Recursive -InclusionFilter { $_.Extension -eq ".log" } -CompressionLevel Optimal -PassThru -Verbose
Write-Host "✅ Filtered zip created:" -ForegroundColor Green
Write-Host " Log files: $($result4.FileCount)" -ForegroundColor White
Write-Host " Compression: $($result4.CompressionEfficiency.ToString('F1'))%" -ForegroundColor White
# Test 5: Append to existing zip (Update mode)
Write-Host "`n7. Test 5: Appending to existing zip..." -ForegroundColor Yellow
$csvFiles = Get-ChildItem $TestDirectory -Recurse -Filter "*.csv"
Write-Host " Appending $($csvFiles.Count) CSV files to existing zip" -ForegroundColor Cyan
$result5 = New-MinIOZipArchive -DestinationPath $zipPath4 -Path $csvFiles -Mode Update -CompressionLevel Optimal -PassThru -Verbose
Write-Host "✅ Files appended to zip:" -ForegroundColor Green
Write-Host " Total files now: $($result5.FileCount)" -ForegroundColor White
# Test 6: Create zip with custom base path
Write-Host "`n8. Test 6: Creating zip with custom base path..." -ForegroundColor Yellow
$zipPath6 = "test-custom-basepath.zip"
Write-Host " Creating zip with custom base path (flattened structure)" -ForegroundColor Cyan
$result6 = New-MinIOZipArchive -DestinationPath $zipPath6 -Directory (Get-Item $TestDirectory) -Recursive -BasePath $TestDirectory -CompressionLevel Optimal -PassThru -Verbose
Write-Host "✅ Custom base path zip created:" -ForegroundColor Green
Write-Host " Files: $($result6.FileCount)" -ForegroundColor White
# Verify all zip files
Write-Host "`n9. Verifying created zip files..." -ForegroundColor Yellow
$zipFiles = Get-ChildItem "*.zip"
foreach ($zipFile in $zipFiles) {
try {
$archive = [System.IO.Compression.ZipFile]::OpenRead($zipFile.FullName)
$entryCount = $archive.Entries.Count
$archive.Dispose()
Write-Host "$($zipFile.Name): $entryCount entries" -ForegroundColor Green
}
catch {
Write-Host "$($zipFile.Name): Verification failed - $($_.Exception.Message)" -ForegroundColor Red
}
}
# Summary
Write-Host "`n=== TEST SUMMARY ===" -ForegroundColor Cyan
Write-Host "✅ All zip archive tests completed successfully!" -ForegroundColor Green
Write-Host "Features tested:" -ForegroundColor Yellow
Write-Host " • FileInfo[] parameter with Files parameter set" -ForegroundColor White
Write-Host " • Directory parameter with recursive and non-recursive modes" -ForegroundColor White
Write-Host " • File filtering with InclusionFilter ScriptBlock" -ForegroundColor White
Write-Host " • Append mode (Update) for adding files to existing zips" -ForegroundColor White
Write-Host " • Custom base path for entry name control" -ForegroundColor White
Write-Host " • Multiple compression levels (Optimal, Fastest)" -ForegroundColor White
Write-Host " • Comprehensive progress tracking and metrics" -ForegroundColor White
Write-Host " • PassThru parameter for detailed results" -ForegroundColor White
Write-Host "`nZip files created:" -ForegroundColor Yellow
foreach ($zipFile in $zipFiles) {
$sizeKB = [math]::Round($zipFile.Length / 1KB, 2)
Write-Host "$($zipFile.Name) ($sizeKB KB)" -ForegroundColor White
}
if ($Cleanup) {
Write-Host "`n10. Cleaning up..." -ForegroundColor Yellow
Remove-Item "*.zip" -Force -ErrorAction SilentlyContinue
Write-Host "✅ Cleanup completed!" -ForegroundColor Green
} else {
Write-Host "`nZip files preserved for inspection. Use -Cleanup to remove them." -ForegroundColor Cyan
}
} catch {
Write-Host "❌ Test failed: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "Stack trace: $($_.ScriptStackTrace)" -ForegroundColor Red
} finally {
# Clean up test directory
if (Test-Path $TestDirectory) {
Remove-Item $TestDirectory -Recurse -Force -ErrorAction SilentlyContinue
}
}
Write-Host "`n=== Test Complete ===" -ForegroundColor Cyan
+51
View File
@@ -0,0 +1,51 @@
# Force update the PSMinIO DLL with the enhanced version
Write-Host "=== Updating PSMinIO DLL ===" -ForegroundColor Cyan
try {
# Stop all PowerShell processes to release the DLL
Write-Host "1. Stopping PowerShell processes..." -ForegroundColor Yellow
Get-Process | Where-Object {$_.ProcessName -like "*powershell*" -or $_.ProcessName -like "*pwsh*"} | ForEach-Object {
Write-Host " Stopping process: $($_.ProcessName) (PID: $($_.Id))" -ForegroundColor Gray
try {
$_ | Stop-Process -Force -ErrorAction SilentlyContinue
} catch {
Write-Host " Could not stop process $($_.Id): $($_.Exception.Message)" -ForegroundColor Yellow
}
}
# Wait a moment for processes to fully stop
Start-Sleep -Seconds 3
# Copy the new DLL
Write-Host "2. Copying enhanced DLL..." -ForegroundColor Yellow
$sourceDLL = "bin\Release\netstandard2.0\PSMinIO.dll"
$targetDLL = "Module\PSMinIO\bin\PSMinIO.dll"
if (Test-Path $sourceDLL) {
Copy-Item $sourceDLL $targetDLL -Force
Write-Host "✅ DLL updated successfully!" -ForegroundColor Green
# Verify the copy
$sourceSize = (Get-Item $sourceDLL).Length
$targetSize = (Get-Item $targetDLL).Length
Write-Host " Source size: $($sourceSize) bytes" -ForegroundColor Gray
Write-Host " Target size: $($targetSize) bytes" -ForegroundColor Gray
if ($sourceSize -eq $targetSize) {
Write-Host "✅ File sizes match - copy successful!" -ForegroundColor Green
} else {
Write-Host "⚠️ File sizes don't match - copy may have failed!" -ForegroundColor Yellow
}
} else {
Write-Host "❌ Source DLL not found: $sourceDLL" -ForegroundColor Red
Write-Host " Run 'dotnet build PSMinIO.csproj --configuration Release' first" -ForegroundColor Yellow
}
} catch {
Write-Host "❌ Update failed: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host "`n=== Update Complete ===" -ForegroundColor Cyan
Write-Host "You can now test the enhanced functionality with:" -ForegroundColor Yellow
Write-Host " .\scripts\Test-50-Files-Upload.ps1 -Verbose" -ForegroundColor White