index/src/IO/TempFileStream.php

24 lines
592 B
PHP

<?php
// TempFileStream.php
// Created: 2021-05-02
// Updated: 2022-02-27
namespace Index\IO;
class TempFileStream extends GenericStream {
public const MAX_MEMORY = 2 * 1024 * 1024;
public function __construct(?string $body = null, int $maxMemory = self::MAX_MEMORY) {
parent::__construct(fopen("php://temp/maxmemory:{$maxMemory}", 'r+b'));
if($body !== null) {
$this->write($body);
$this->flush();
}
}
public static function fromString(string $string): TempFileStream {
return new TempFileStream($string);
}
}