src/fs/entity/FileEntity.php
public function prepend(string $contents, int $maxMemory = 8096): bool
    {
        $test = \sndsgd\Fs::EXISTS | \sndsgd\Fs::READABLE | \sndsgd\Fs::WRITABLE;
        if ($this->test($test) === false) {
            $this->error = "failed to prepend file; {$this->error}";
            return false;
        }

        $len = strlen($contents);
        $size = filesize($this->path);
        $endsize = $len + $size;

        # if the overall filesize is greater than `maxMemory`, write efficiently
        if ($endsize > $maxMemory) {
            return $this->prependFileInPlace($contents, $len, $endsize);
        }

        # use file_get/put_contents to handle the operation
        if (($tmp = $this->readFile(0)) === false) {
            return false;
        }

        if ($this->writeFile($contents.$tmp, 0) === false) {
            return false;
        }

        return true;
    }
public function prepend(string $contents, int $maxMemory = 8096): bool
    {
        $test = \sndsgd\Fs::EXISTS | \sndsgd\Fs::READABLE | \sndsgd\Fs::WRITABLE;
        if ($this->test($test) === false) {
            $this->error = "failed to prepend file; {$this->error}";
            return false;
        }

        $len = strlen($contents);
        $size = filesize($this->path);
        $endsize = $len + $size;

        # if the overall filesize is greater than `maxMemory`, write efficiently
        if ($endsize > $maxMemory) {
            return $this->prependFileInPlace($contents, $len, $endsize);
        }

        # use file_get/put_contents to handle the operation
        if (($tmp = $this->readFile(0)) === false) {
            return false;
        }

        if ($this->writeFile($contents.$tmp, 0) === false) {
            return false;
        }

        return true;
    }
Prepend contents to a file

@param string $contents The content to prepend to the file
@param int $maxMemory The max number of bytes to consume
@return bool