22 lines
		
	
	
		
			515 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			22 lines
		
	
	
		
			515 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
namespace nur\sery\file\base;
 | 
						|
 | 
						|
/**
 | 
						|
 * 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();
 | 
						|
  }
 | 
						|
}
 |