-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from giansalex/f002
New Zip routines
- Loading branch information
Showing
7 changed files
with
107 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Giansalex | ||
* Date: 16/07/2017 | ||
* Time: 12:23 | ||
*/ | ||
|
||
namespace Greenter\Zip; | ||
|
||
/** | ||
* Class ZipFactory | ||
* @package Greenter\Zip | ||
*/ | ||
final class ZipReader | ||
{ | ||
const UNZIP_FORMAT = 'Vsig/vver/vflag/vmeth/vmodt/vmodd/Vcrc/Vcsize/Vsize/vnamelen/vexlen'; | ||
|
||
/** | ||
* Retorna el contenido del primer xml dentro del zip. | ||
* | ||
* @param string $zipContent | ||
* @return string | ||
*/ | ||
public function decompressXmlFile($zipContent) | ||
{ | ||
$start = 0; | ||
$max = 10; | ||
while ($max > 0) { | ||
$dat = substr($zipContent, $start, 30); | ||
if (empty($dat)) { | ||
break; | ||
} | ||
|
||
$head = unpack(self::UNZIP_FORMAT, $dat); | ||
$filename = substr(substr($zipContent, $start),30, $head['namelen']); | ||
if (empty($filename)) { | ||
break; | ||
} | ||
$count = 30 + $head['namelen'] + $head['exlen']; | ||
|
||
if (strtolower($this->getFileExtension($filename)) == 'xml') { | ||
return gzinflate(substr($zipContent, $start + $count, $head['csize'])); | ||
} | ||
|
||
$start += $count + $head['csize']; | ||
$max--; | ||
} | ||
|
||
return ''; | ||
} | ||
|
||
function getFileExtension($filename) | ||
{ | ||
$lastDotPos = strrpos($filename, '.'); | ||
if (!$lastDotPos) return ''; | ||
|
||
return substr($filename, $lastDotPos + 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters