Skip to content

Commit

Permalink
good shit
Browse files Browse the repository at this point in the history
  • Loading branch information
santisq committed Jan 9, 2025
1 parent eef8b5d commit 9b1fdfb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
15 changes: 9 additions & 6 deletions src/PSCompression/Commands/GetZipEntryCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ ZipEntryBase CreateFromStream(ZipArchiveEntry entry, bool isDirectory) =>

using ZipArchive zip = new(Stream, ZipArchiveMode.Read, true);
WriteObject(
EnumerateEntries(zip, CreateFromStream),
GetEntries(zip, CreateFromStream),
enumerateCollection: true);
return;
}
Expand All @@ -102,10 +102,13 @@ ZipEntryBase CreateFromFile(ZipArchiveEntry entry, bool isDirectory) =>

try
{
using ZipArchive zip = ZipFile.OpenRead(path);
WriteObject(
EnumerateEntries(zip, CreateFromFile),
enumerateCollection: true);
IEnumerable<ZipEntryBase> entries;
using (ZipArchive zip = ZipFile.OpenRead(path))
{
entries = GetEntries(zip, CreateFromFile);
}

WriteObject(entries, enumerateCollection: true);
}
catch (Exception exception)
{
Expand All @@ -114,7 +117,7 @@ ZipEntryBase CreateFromFile(ZipArchiveEntry entry, bool isDirectory) =>
}
}

private IEnumerable<ZipEntryBase> EnumerateEntries(
private IEnumerable<ZipEntryBase> GetEntries(
ZipArchive zip,
Func<ZipArchiveEntry, bool, ZipEntryBase> createMethod)
{
Expand Down
12 changes: 9 additions & 3 deletions tests/ZipEntryCmdlets.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Describe 'ZipEntry Cmdlets' {
BeforeAll {
$zip = New-Item (Join-Path $TestDrive test.zip) -ItemType File -Force
$file = New-Item ([System.IO.Path]::Combine($TestDrive, 'someFile.txt')) -ItemType File -Value 'foo'
$zip, $file | Out-Null
$uri = 'https://www.powershellgallery.com/api/v2/package/PSCompression'
$zip, $file, $uri | Out-Null
}

Context 'New-ZipEntry' -Tag 'New-ZipEntry' {
Expand Down Expand Up @@ -113,8 +114,13 @@ Describe 'ZipEntry Cmdlets' {

Context 'Get-ZipEntry' -Tag 'Get-ZipEntry' {
It 'Can list entries in a zip archive' {
@($zip | Get-ZipEntry).Count -gt 0 |
Should -BeGreaterThan 0
$zip | Get-ZipEntry |
Should -BeOfType ([PSCompression.ZipEntryBase])
}

It 'Can list entries from a Stream' {
Invoke-WebRequest $uri | Get-ZipEntry |
Should -BeOfType ([PSCompression.ZipEntryBase])
}

It 'Should throw when not targetting a FileSystem Provider Path' {
Expand Down

0 comments on commit 9b1fdfb

Please sign in to comment.