IO
[m6w6/atick] / lib / atick / IO.php
diff --git a/lib/atick/IO.php b/lib/atick/IO.php
new file mode 100644 (file)
index 0000000..3a37e72
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+
+namespace atick\IO;
+
+function copy($from, $to, $len = 4096) {
+       $data = fread($from, $len);
+
+       if (!strlen($data)) {
+               if (feof($from)) {
+                       /* forward EOF */
+                       fclose($to);
+               }
+               return;
+       }
+
+       return fwrite($to, $data);
+}
+
+namespace atick;
+
+interface IO
+{
+       /**
+        * Retrieve the output stream
+        * @return resource
+        */
+       function getOutput();
+
+       /**
+        * Retrieve the input stream
+        * @return resource
+        */
+       function getInput();
+
+       /**
+        * Pass input from FD to input and return output stream
+        * @param resource $fd
+        * @return resource
+        */
+       function __invoke($fd);
+}