nur-sery/src/os/file/MemoryStream.php

24 lines
543 B
PHP

<?php
namespace nur\sery\os\file;
use nur\sery\os\IOException;
/**
* Class MemoryStream: un flux qui peut être lu ou écrit, et qui reste
* uniquement en mémoire.
*/
class MemoryStream extends Stream {
protected static function memory_fd() {
return fopen("php://memory", "w+b");
}
function __construct(bool $throwOnError=true) {
parent::__construct(self::memory_fd(), true, $throwOnError);
}
function getResource() {
if ($this->fd === null) $this->fd = self::memory_fd();
return parent::getResource();
}
}