Ferreteria/v0.6/clade/IO/Aspect/Connx/Buffer/File

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | IO‎ | Aspect‎ | Connx‎ | Buffer
Revision as of 02:57, 28 November 2025 by Woozle (talk | contribs) (Created page with "{{page/clade/v2 |fam= {{!}} align=right {{!}} <code>{{l/ver/clade|IO\Aspect\Connx|Buffer}}</code> {{!}} align=center {{!}} ⇒ <code>{{l/ver/clade|IO\Aspect\Connx\Buffer|File}}</code> ⇒ {{!}} align=left {{!}} <poem> <code>/Reader/</code> <code>/Writer/</code> </poem> |alia= {{!-!}} '''ActionIface''' {{!!}} <code>{{l/ver/clade/full|Sys\Events|ItWent}}</code> {{!-!}} '''Base'''* [ca,i] {{!!}} <code>{{l/ver/clade/full|IO\Aspect\Connx|Buffer}}</code> {{!...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
clade: IO\Aspect\Connx\Buffer\File
Clade Family
Buffer File
Clade Aliases
Alias Clade
ActionIface Sys\Events\ItWent
Base* [ca,i] IO\Aspect\Connx\Buffer
FModeClass Sys\FileSys\Mode
FileIface Sys\FileSys\Node\Fi
Subpages

About

  • Purpose: a Buffer which moves data between a stream and a file
    • This is the direction-agnostic base class, probably abstract.

History

Code

as of 2025-11-27:

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