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

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | IO‎ | Aspect‎ | Connx‎ | Buffer‎ | Sourced/File
Jump to navigation Jump to search
clade: IO\Aspect\Connx\Buffer\Sourced\File\Writer
Clade Family
File Writer (none)
Clade Aliases
Alias Clade
Base* [ca,i] IO\Aspect\Connx\Buffer\File
FModeEnum Sys\FileSys\Mode
Subpages

About

  • Purpose: a Buffer which saves incoming data to a file
    • Since this can take awhile, it also shows progress on the screen.
  • Usage: when output is large enough that we don't want to fill up RAM with it
    • Typically used for capturing data that we want to store in a file.
  • Assumes: Screen is capable of dynamic updates

History

  • 2024-11-24 started
  • 2024-12-03 renamed from Status -> FileWriter
  • 2024-12-07 ...except it was ToFile for awhile, but now it's File/Writer
    • and it's a podling of File (new).

Code

as of 2025-11-27:

interface iWriter extends BaseIface {}
class cWriter extends BaseClass implements iWriter {

    // ++ CONFIG ++ //

    protected function ModesArray() : array {
        return [
          FModeEnum::FILE_WRITER,FModeEnum::FLAG_ON,  // need to write
          FModeEnum::FILE_CREATE,FModeEnum::FLAG_ON,  // create if not found
          FModeEnum::FILE_FOUND,FModeEnum::FOUND_ZERO // if found, erase
          ];
    }

    // -- CONFIG -- //
    // ++ ACCESS ++ //

    // OVERRIDE: does not apply
    protected function AvailSrceByteCount() : int { return 0; }

    // OVERRIDE: just dump directly to file, for now
    public function AppendBytes(string $s) {
        #static $ntLast = 0.0;
        #static $nNewLast = NULL;

        $nNew = strlen($s);       // bytes in current input chunk
        $this->IncSpentBytes($nNew);

        $this->DataFile()->InOut()->Write($s);
        $this->OnStatusChange();

    }

    // -- ACCESS -- //
}

Removed

2025-03-19

Commented out from AppendBytes() on 3/15:

#
        // 2025-03-15 replaced by OnStatusChange()
        $ntNow = microtime(TRUE);
        if ($ntNow - $ntLast > 0.05) { // update display every 0.05 seconds
            $ntLast = $ntNow;
            $nNewLast = $nNew;
            $this->UpdateStatus();
            // reset the timeout clock
            $ok = set_time_limit(5); // NOTE: seems to always return FALSE
        }

2024-12-05

This is from UpdateStatus(), when I was still trying to have it show the size of each input packet but also not update for every input packet (which means you have a decision to make about what you want to show, when there may be multiple packets that have come in):

#
        if ($nNew > 0) {
            $nByWd = strlen((string)$nNew);
            if ($nByWd > $nMaxWd) $nMaxWd = $nByWd;
            $sInBytes = sprintf("%' {$nMaxWd}d bytes in,",$nNew);
            $ftInBytes = $sInBytes;
        } else {
            #$sInBytes = '';
            #$nLen = $nMaxWd + strlen(' bytes in,');
            #$sInBytes = str_repeat('-',$nLen);
            $ftInBytes = self::Screen()->FaintIt($sInBytes);
        }