Some BINKP optimisation, implemented crypt, implemented receiving compressed transfers
This commit is contained in:
@@ -15,9 +15,6 @@ use App\Models\Address;
|
||||
* Object representing the files we are sending
|
||||
*
|
||||
* @property-read resource fd
|
||||
* @property-read int file_mtime
|
||||
* @property-read int file_size
|
||||
* @property-read string file_name
|
||||
* @property-read int mail_size
|
||||
* @property-read int total_count
|
||||
* @property-read int total_sent
|
||||
@@ -31,9 +28,7 @@ final class Send extends Item
|
||||
private ?Item $sending;
|
||||
private Collection $packets;
|
||||
|
||||
private mixed $f; // File descriptor
|
||||
private int $start; // Time we started sending
|
||||
private int $file_pos; // Current read pointer
|
||||
private string $comp_data;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -41,8 +36,6 @@ final class Send extends Item
|
||||
$this->list = collect();
|
||||
$this->packets = collect();
|
||||
$this->sending = NULL;
|
||||
$this->file_pos = 0;
|
||||
$this->f = NULL;
|
||||
}
|
||||
|
||||
public function __get($key)
|
||||
@@ -51,15 +44,15 @@ final class Send extends Item
|
||||
case 'fd':
|
||||
return is_resource($this->f) ?: $this->f;
|
||||
|
||||
case 'file_count':
|
||||
case 'files_count':
|
||||
return $this->list
|
||||
->filter(function($item) { return $item->isType(self::IS_FILE|self::IS_TIC); })
|
||||
->count();
|
||||
|
||||
case 'file_size':
|
||||
case 'files_size':
|
||||
return $this->list
|
||||
->filter(function($item) { return $item->isType(self::IS_FILE|self::IS_TIC); })
|
||||
->sum(function($item) { return $item->file_size; });
|
||||
->sum(function($item) { return $item->size; });
|
||||
|
||||
case 'filepos':
|
||||
return $this->file_pos;
|
||||
@@ -73,8 +66,8 @@ final class Send extends Item
|
||||
case 'mail_size':
|
||||
return $this->list
|
||||
->filter(function($item) { return $item->isType(self::IS_ARC|self::IS_PKT); })
|
||||
->sum(function($item) { return $item->file_size; })
|
||||
+ $this->packets->sum(function($item) { return $item->file_size; });
|
||||
->sum(function($item) { return $item->size; })
|
||||
+ $this->packets->sum(function($item) { return $item->size; });
|
||||
|
||||
case 'sendas':
|
||||
return $this->sending ? $this->sending->{$key} : NULL;
|
||||
@@ -95,10 +88,10 @@ final class Send extends Item
|
||||
case 'total_sent_bytes':
|
||||
return $this->list
|
||||
->filter(function($item) { return ($item->action & self::I_SEND) && $item->sent === TRUE; })
|
||||
->sum(function($item) { return $item->file_size; })
|
||||
->sum(function($item) { return $item->size; })
|
||||
+ $this->packets
|
||||
->filter(function($item) { return ($item->action & self::I_SEND) && $item->sent === TRUE; })
|
||||
->sum(function($item) { return $item->file_size; });
|
||||
->sum(function($item) { return $item->size; });
|
||||
|
||||
case 'total_count':
|
||||
return $this->list
|
||||
@@ -110,8 +103,8 @@ final class Send extends Item
|
||||
|
||||
case 'total_size':
|
||||
return $this->list
|
||||
->sum(function($item) { return $item->file_size; })
|
||||
+ $this->packets->sum(function($item) { return $item->file_size; });
|
||||
->sum(function($item) { return $item->size; })
|
||||
+ $this->packets->sum(function($item) { return $item->size; });
|
||||
|
||||
default:
|
||||
throw new Exception('Unknown key: '.$key);
|
||||
@@ -146,6 +139,21 @@ final class Send extends Item
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
private function compress(string $comp_mode): void
|
||||
{
|
||||
switch ($comp_mode) {
|
||||
case 'BZ2':
|
||||
$this->comp_data = bzcompress($buf);
|
||||
break;
|
||||
|
||||
case 'GZ':
|
||||
$this->comp_data = gzcompress($buf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Close the file descriptor of the file we are sending
|
||||
*
|
||||
@@ -160,7 +168,7 @@ final class Send extends Item
|
||||
if ($successful) {
|
||||
$this->sending->sent = TRUE;
|
||||
$end = time()-$this->start;
|
||||
Log::debug(sprintf('%s: - Closing [%s], sent in [%d]',self::LOGKEY,$this->sending->file_name,$end));
|
||||
Log::debug(sprintf('%s: - Closing [%s], sent in [%d]',self::LOGKEY,$this->sending->name,$end));
|
||||
}
|
||||
|
||||
// @todo This should be done better isType == file?
|
||||
@@ -208,9 +216,9 @@ final class Send extends Item
|
||||
Log::debug(sprintf('%s:- [%d] Files(s) added for sending to [%s]',self::LOGKEY,$x->count(),$ao->ftn));
|
||||
|
||||
// Add Files
|
||||
foreach ($x as $xx) {
|
||||
$this->list->push(new Item($xx,self::I_SEND));
|
||||
$this->list->push(new Tic($ao,$xx,self::I_SEND));
|
||||
foreach ($x as $fo) {
|
||||
$this->list->push(new Item($fo,self::I_SEND));
|
||||
$this->list->push(new Tic($ao,$fo,self::I_SEND));
|
||||
}
|
||||
|
||||
$file = TRUE;
|
||||
@@ -222,10 +230,11 @@ final class Send extends Item
|
||||
/**
|
||||
* Open a file for sending
|
||||
*
|
||||
* @param string $compress
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public function open(): bool
|
||||
public function open(string $compress=''): bool
|
||||
{
|
||||
Log::debug(sprintf('%s:+ open',self::LOGKEY));
|
||||
|
||||
@@ -238,6 +247,11 @@ final class Send extends Item
|
||||
$this->start = time();
|
||||
$this->f = TRUE;
|
||||
|
||||
/*
|
||||
if ($compress)
|
||||
$this->comp_data = $this->compdata($compress);
|
||||
*/
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -258,18 +272,19 @@ final class Send extends Item
|
||||
}
|
||||
|
||||
// If sending file is a File::class, then our file is s3
|
||||
if (! $this->sending->file_name && $this->sending->filemodel) {
|
||||
if (! $this->sending->name && $this->sending->filemodel) {
|
||||
$this->f = Storage::readStream($this->sending->filemodel->full_storage_path);
|
||||
return TRUE;
|
||||
|
||||
} else {
|
||||
$this->f = fopen($this->sending->file_name,'rb');
|
||||
$this->f = fopen($this->sending->name,'rb');
|
||||
|
||||
if (! $this->f) {
|
||||
Log::error(sprintf('%s:! Unable to open file [%s] for reading',self::LOGKEY,$this->sending->file_name));
|
||||
Log::error(sprintf('%s:! Unable to open file [%s] for reading',self::LOGKEY,$this->sending->name));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Log::info(sprintf('%s:= open - File [%s] opened with size [%d]',self::LOGKEY,$this->sending->file_name,$this->sending->file_size));
|
||||
Log::info(sprintf('%s:= open - File [%s] opened with size [%d]',self::LOGKEY,$this->sending->name,$this->sending->size));
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
@@ -343,7 +358,7 @@ final class Send extends Item
|
||||
Log::debug(sprintf('%s: - Read [%d] bytes, file pos now [%d]',self::LOGKEY,strlen($data),$this->file_pos));
|
||||
|
||||
if ($data === FALSE)
|
||||
throw new UnreadableFileEncountered('Error reading file: '.$this->sending->file_name);
|
||||
throw new UnreadableFileEncountered('Error reading file: '.$this->sending->name);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
Reference in New Issue
Block a user