Ferreteria/v0.6/clade/IO/Aspect/Connx/Buffer/File
Jump to navigation
Jump to search
| ||||||||||||||||||||
About
- Purpose: a Buffer which moves data between a stream and a file
- This is the direction-agnostic base class, probably abstract.
History
Code
interface iFile extends BaseIface {}
abstract class caFile extends BaseClass {
// ++ CONFIG ++ //
abstract protected function ModesArray() : array;
// -- CONFIG -- //
// ++ SETUP ++ //
public function __construct(private FileIface $oData) {}
protected function DataFile() : FileIface { return $this->oData; }
// -- SETUP -- //
// ++ LIFECYCLE ++ //
protected function ActualOpen() : ActionIface {
$oData = $this->DataFile();
$oMode = new FModeClass($this->ModesArray());
$oDataIO = $oData->InOut();
$oDataIO->Mode($oMode);
#echo $oData->ReflectThis()->Report();
$oAct = $oDataIO->Open();
if (!$oAct->GetOkay()) {
self::GotToHere('File error detected here.');
echo self::Screen()->ErrorIt('File error').': '.$oAct->GetStatusText().CRLF;
}
$this->RewindAll(); // reset the contents
$this->StartClock(); // reset the time counter
return $oAct;
}
protected function ActualShut() : ActionIface {
$oDataIO = $this->DataFile()->InOut();
$oAct = $oDataIO->Shut();
$this->UpdateStatus();
echo CRLF;
return $oAct;
}
private $onWhenStart;
protected function StartClock() { $this->onWhenStart = new DateTime; }
protected function DurationString() : string {
$onNow = new DateTime;
$onDiff = $this->onWhenStart->diff($onNow);
return $onDiff->format('%h:%I:%S');
}
// -- LIFECYCLE -- //
// ++ UI ++ //
private $onFmt = NULL; protected function Formatter() : NumberFormatter {
return $this->onFmt ?? ($this->onFmt = new NumberFormatter('en_US',NumberFormatter::DECIMAL));
}
protected function UpdateStatus() {
static $nMaxWd = 0;
static $sInBytes = '0';
$nTot = $this->SpentByteCount();
$sTot = $this->Formatter()->format($nTot);
$nFil = $this->DataFile()->Size();
$ftRem = ''; // default
if (is_int($nFil) && ($nFil > 0)) {
$nRem = $nFil - $nTot;
if ($nRem > 0) {
$sRem = $this->Formatter()->format($nRem);
$ftRem = "rem: $sRem