Support for ZIP archives
This commit is contained in:
@@ -113,23 +113,26 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a packet file
|
||||
* Process a packet file
|
||||
*
|
||||
* @param File $file
|
||||
* @param mixed $f
|
||||
* @param string $name
|
||||
* @param int $size
|
||||
* @param System|null $system
|
||||
* @param bool $use_cache
|
||||
* @return Packet
|
||||
* @throws InvalidPacketException
|
||||
*/
|
||||
public static function open(File $file,System $system=NULL,bool $use_cache=TRUE): self
|
||||
{
|
||||
Log::debug(sprintf('%s:+ Opening Packet [%s]',self::LOGKEY,$file));
|
||||
|
||||
$f = fopen($file,'r');
|
||||
$fstat = fstat($f);
|
||||
public static function process(mixed $f,string $name,int $size,System $system=NULL,bool $use_cache=TRUE): self
|
||||
{
|
||||
Log::debug(sprintf('%s:+ Opening Packet [%s] with size [%d]',self::LOGKEY,$name,$size));
|
||||
|
||||
$read_ptr = 0;
|
||||
|
||||
// PKT Header
|
||||
$header = fread($f,self::HEADER_LEN);
|
||||
$read_ptr += strlen($header);
|
||||
|
||||
// Could not read header
|
||||
if (strlen($header) != self::HEADER_LEN)
|
||||
@@ -142,10 +145,11 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
|
||||
$o = new self;
|
||||
$o->use_cache = $use_cache;
|
||||
$o->name = (string)$file;
|
||||
$o->name = $name;
|
||||
$o->header = unpack(self::unpackheader(self::v2header),$header);
|
||||
|
||||
$x = fread($f,2);
|
||||
$read_ptr += strlen($x);
|
||||
|
||||
// End of Packet?
|
||||
if (strlen($x) == 2 and $x == "\00\00")
|
||||
@@ -171,6 +175,8 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
$last = '';
|
||||
|
||||
while ($buf_ptr || (! feof($f) && ($readbuf=fread($f,self::BLOCKSIZE)))) {
|
||||
$read_ptr += strlen($readbuf);
|
||||
|
||||
if (strlen($message) < self::PACKED_MSG_HEADER_LEN) {
|
||||
$addchars = self::PACKED_MSG_HEADER_LEN-strlen($message);
|
||||
$message .= substr($readbuf,$buf_ptr,$addchars);
|
||||
@@ -204,7 +210,7 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
// In case our packet break is at the end of the buffer
|
||||
$last = substr($readbuf,-2);
|
||||
|
||||
if ((str_contains($last,"\x00")) && ($fstat['size']-ftell($f) > 2)) {
|
||||
if ((str_contains($last,"\x00")) && ($size-$read_ptr > 2)) {
|
||||
$message .= substr($readbuf,$buf_ptr);
|
||||
$buf_ptr = 0;
|
||||
|
||||
@@ -216,7 +222,7 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
}
|
||||
|
||||
// See if we have found the end of the packet, if not read more.
|
||||
if ($end === FALSE && (ftell($f) < $fstat['size'])) {
|
||||
if ($end === FALSE && ($read_ptr < $size)) {
|
||||
$message .= substr($readbuf,$buf_ptr);
|
||||
$buf_ptr = 0;
|
||||
|
||||
|
Reference in New Issue
Block a user