Private/Test-ConnectorZipFile.ps1
|
function Test-ConnectorZipFile { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string] $Path ) try { $archive = [System.IO.Compression.ZipFile]::OpenRead($Path) try { foreach ($entry in $archive.Entries) { if ([string]::IsNullOrEmpty($entry.Name)) { continue } $entryStream = $entry.Open() try { $entryStream.CopyTo([System.IO.Stream]::Null) } finally { $entryStream.Dispose() } } } finally { $archive.Dispose() } } catch { throw "ZIP file validation failed for '$Path'. The file may be corrupt or unsupported. $($_.Exception.Message)" } } |