Ferreteria/v0.6/clade/IO/Aspect/Connx/Buffer/File/Reader/@fx/RemoveBytes

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | IO‎ | Aspect‎ | Connx‎ | Buffer‎ | File‎ | Reader
Revision as of 14:41, 11 December 2025 by Woozle (talk | contribs) (Created page with "{{page/fx}} ==Code== ''as of {{fmt/date|2025|12|11}}:'' {{fmt/php/block|1=# public function RemoveBytes() : string { $this->ErrorIfShut('read from'); // Is there room in the buffer for more? $nBuff = $this->AvailBuffByteCount(); // what's in the buffer #$this->AmHere("Bytes remaining: [$nBuff]"); $nRoom = self::MAX_BUFF_LEN - $nBuff; // room available #$this->AmHere("Bytes remaining: [$nBuff] / Space remaining: [...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Code

as of 2025-12-11:

#
    public function RemoveBytes() : string {
        $this->ErrorIfShut('read from');

        // Is there room in the buffer for more?
        $nBuff = $this->AvailBuffByteCount();    // what's in the buffer
        #$this->AmHere("Bytes remaining: [$nBuff]");
        $nRoom = self::MAX_BUFF_LEN - $nBuff;    // room available
        #$this->AmHere("Bytes remaining: [$nBuff] / Space remaining: [$nRoom]");
        if ($nRoom > 0) {
            $nFileAll = $this->AvailSrceByteCount();
            #echo $this->DataFile()->Ident()->ReflectThis()->Report();
            #$this->AmHere("File bytes: [$nFileAll] in ".$this->DataFile()->Ident()->SpecFull());
            $nFileNew = $nFileAll - $this->nInPtr;      // what hasn't been read from the file yet
            if ($nFileNew > 0) {
                // There's more in the file, so refill the buffer:
                $nToRead = min($nRoom,$nFileNew);
                #echo "ADDING $nToRead BYTES (nFileNew=$nFileNew, nRoom=$nRoom) from file".CRLF;
                $oRes = $this->DataFile()->InOut()->Read($nToRead);
                $osData = $oRes->QData();
                if ($osData->HasIt()) {
                    $sData = $osData->GetIt();
                    $nLen = strlen($sData);
                    $this->AddBytesForFetch($sData);
                }
            }
        }

        $sOut = parent::RemoveBytes();  // grab existing buffer-contents
        #$this->SetNote('bytes to send: '.strlen($sOut));

        $this->OnStatusChange();

        return $sOut;
    }