Skip to content

Commit

Permalink
feat: load TempDirectory from archive stream
Browse files Browse the repository at this point in the history
  • Loading branch information
theus77 committed Jul 1, 2024
1 parent 8471550 commit 432629c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions EMS/helpers/src/File/TempDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace EMS\Helpers\File;

use Psr\Http\Message\StreamInterface;
use Symfony\Component\Filesystem\Filesystem;

class TempDirectory
Expand Down Expand Up @@ -47,4 +48,19 @@ public function exists(): bool
{
return \is_dir($this->path);
}

public function loadFromArchive(StreamInterface $stream): void
{
$tempFile = TempFile::create()->loadFromStream($stream);
$zip = new \ZipArchive();
if (true !== $open = $zip->open($tempFile->path)) {
throw new \RuntimeException(\sprintf('Failed opening zip %s (ZipArchive %s)', $tempFile->path, $open));
}

if (!$zip->extractTo($this->path)) {
throw new \RuntimeException(\sprintf('Extracting of zip file failed (%s)', $this->path));
}
$zip->close();
$tempFile->clean();
}
}

0 comments on commit 432629c

Please sign in to comment.