Ferreteria/v0.6/clade/IO/Aspect/Connx/Buffer/File/Reader/@fx/RemoveBytes
Jump to navigation
Jump to search
|
fx:
RemoveBytes() |
Code
#
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;
}