Optimised our sending and receiving of items

This commit is contained in:
2023-07-17 16:36:53 +10:00
parent a8f76aec31
commit c1ec4eff36
14 changed files with 634 additions and 572 deletions

View File

@@ -2,38 +2,84 @@
namespace App\Classes\File;
use App\Models\Address;
use App\Models\File;
use App\Classes\FTN\Tic as FTNTic;
use App\Models\{Address,File};
class Tic extends Item
final class Tic extends Send
{
private string $file;
/** @var int Our internal position counter */
private int $readpos;
private Address $ao;
private string $tic;
/**
* @throws \Exception
*/
public function __construct(Address $ao,File $fo,int $action)
public function __construct(File $file,Address $ao,int $type)
{
switch ($action) {
case self::I_SEND:
$tic = new FTNTic;
$this->file = $tic->generate($ao,$fo);
$this->file_name = sprintf('%s.tic',sprintf('%08x',$fo->id));
$this->file_size = strlen($this->file);
$this->file_mtime = $fo->created_at->timestamp;
parent::__construct();
break;
$this->f = $file;
$this->ao = $ao;
$this->ftype = ((($type&0xff)<<8)|self::IS_TIC);
$this->readpos = 0;
$this->tic = FTNTic::generate($ao,$file);
}
public function __get($key) {
switch ($key) {
case 'dbids':
return collect([$this->f->id]);
case 'name':
return sprintf('%08x',timew($this->f->created_at));
case 'nameas':
return sprintf('%s.tic',$this->name);
case 'mtime':
return $this->f->datetime->timestamp;
case 'size':
return strlen($this->tic);
case 'type':
return ($this->ftype&0xff00)>>8;
default:
throw new \Exception('Unknown action: '.$action);
return parent::__get($key);
}
$this->action = $action;
$this->type = self::IS_TIC;
}
public function read(int $start,int $length): string
public function close(bool $successful): void
{
return substr($this->file,$start,$length);
if ($successful)
$this->complete = TRUE;
}
public function feof(): bool
{
return ($this->readpos === $this->size);
}
public function open(string $compress=''): bool
{
return TRUE;
}
public function read(int $length): string
{
$result = substr($this->tic,$this->readpos,$length);
$this->readpos += strlen($result);
return $result;
}
public function seek(int $pos): bool
{
$this->readpos = ($pos < $this->size) ? $pos : $this->size;
return TRUE;
}
}