Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
AnourValar committed Sep 8, 2022
1 parent 9b6bbe4 commit 09af590
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/Drivers/ZipDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ public function load(string $file, \AnourValar\Office\Format $format): self

$zipArchive = new \ZipArchive;
$zipArchive->open($file);
$count = $zipArchive->numFiles;
try {
$count = $zipArchive->numFiles;

for ($i = 0; $i < $count; $i++) {
$filename = $zipArchive->getNameIndex($i);
$content = $zipArchive->getFromName($filename);
for ($i = 0; $i < $count; $i++) {
$filename = $zipArchive->getNameIndex($i);
$content = $zipArchive->getFromName($filename);

$fileSystem[$filename] = $content;
$fileSystem[$filename] = $content;
}
} catch (\Throwable $e) {
$zipArchive->close();
throw $e;
}

$zipArchive->close();

$instance->fileSystem = $fileSystem;
Expand All @@ -49,21 +53,25 @@ public function save(string $file, \AnourValar\Office\Format $format): void
{
$this->getFormat($format); // check

ob_start();

$options = \App::make(\ZipStream\Option\Archive::class);
$zipStream = new \ZipStream\ZipStream(null, $options);
ob_start();

foreach ($this->fileSystem as $filename => $content) {
if ($content && mb_strtolower(pathinfo($filename, PATHINFO_EXTENSION)) == 'xml') {
$content = $this->handleReplace($content);
}
try {
foreach ($this->fileSystem as $filename => $content) {
if ($content && mb_strtolower(pathinfo($filename, PATHINFO_EXTENSION)) == 'xml') {
$content = $this->handleReplace($content);
}

$zipStream->addFile($filename, $content);
}
$zipStream->addFile($filename, $content);
}
} catch (\Throwable $e) {
$zipStream->finish();
ob_get_clean();
throw $e;
}

$zipStream->finish();

file_put_contents($file, ob_get_clean());
}

Expand Down

0 comments on commit 09af590

Please sign in to comment.