2
require("streamwriter.php");
3
require("streamobject.php");
4
require("streamreader.php");
6
class IO extends VIRTUALStreamReaderWriter implements STREAMObjectInterface {
16
function __construct($output = NULL, $read_mode = false) {
17
$this->output = $output;
18
$this->read = $read_mode;
21
function Open(&$output = NULL, $flags = 0) {
22
if (!$output) $output = $this->output;
24
if (is_resource($output)) {
25
$this->action = $output;
27
if ($flags&STREAM::GIFT) $this->close = true;
28
else $this->close = false;
29
$this->stdout = false;
30
} elseif (is_string($output)) {
31
$this->action = fopen($output, $this->read?"rw":"w");
33
throw new ADEIException(translate("Access to the stream outlet (%s) is failed", $action));
36
$this->stdout = false;
37
} elseif ($output instanceof STREAMWriterInterface) {
38
if (($this->read)&&(!($output instanceof STREAMReaderWriterInterface))) {
39
throw new ADEIException(translate("STREAMReader interface is not supported by object"));
42
$this->action = $output;
44
if ($output instanceof STREAMSequenceInterface) {
45
$this->action->SequenceStart();
46
$this->action->Start();
54
throw new ADEIException(translate("Unsupported stream output"));
57
throw new ADEIException(translate("There are no read possibility for STDOUT objects"));
59
$this->action = fopen("php://output", "w");
65
function Close(STREAMWriterInterface $h = NULL) {
67
if ($h) $this->Stream($h);
68
else $res = $this->GetContent($h);
71
if (is_resource($this->action)) {
73
fclose($this->action);
79
$this->action->SequenceEnd();
88
function WriteFile($file) {
89
if ($this->stdout) readfile($file);
90
else parent::WriteFile($file, $flags);
93
function WriteData(&$data) {
94
if (is_resource($this->action))
95
fwrite($this->action, $data);
97
$this->action->WriteData($data, $flags);
100
function ReadData($limit = 0, $flags = 0) {
102
throw new ADEIException(translate("The read is not supported"));
104
$this->read = 2; // At least single read is performed
106
if (is_resource($this->action)) {
107
if (($flags&STREAM::BLOCK)||(stream_select($r=array($this->action), $w=NULL, $e=NULL, 0)>0)) {
108
if ($limit) return fread($this->action, $limit);
109
else return fread($this->action, STREAM::BUFFER_SIZE);
113
$this->action->ReadData($flags);
118
throw new ADEIException(translate("The read is not supported"));
120
if (is_resource($this->action))
121
return feof($this->action);
123
return $this->action->EOS($flags);
b'\\ No newline at end of file'