From ccd90309b6798fab29fff77e156da8475218d06a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Ryciuk?= Date: Fri, 14 Oct 2016 22:18:20 +0200 Subject: [PATCH] Split streams into MemoryStream and FileStream --- src/IO/FileStream.php | 12 +++++++++++ src/IO/MemoryStream.php | 10 ++++++++++ src/{MemoryStream.php => IO/PhpStream.php} | 23 +++------------------- 3 files changed, 25 insertions(+), 20 deletions(-) create mode 100644 src/IO/FileStream.php create mode 100644 src/IO/MemoryStream.php rename src/{MemoryStream.php => IO/PhpStream.php} (84%) diff --git a/src/IO/FileStream.php b/src/IO/FileStream.php new file mode 100644 index 0000000..b1e0aa1 --- /dev/null +++ b/src/IO/FileStream.php @@ -0,0 +1,12 @@ +phpStream = fopen($path, $mode); + stream_set_read_buffer($this->phpStream, 1024*1024); + $this->seek(0); + } +} diff --git a/src/IO/MemoryStream.php b/src/IO/MemoryStream.php new file mode 100644 index 0000000..97150c5 --- /dev/null +++ b/src/IO/MemoryStream.php @@ -0,0 +1,10 @@ +phpStream = fopen('php://memory', 'wb+'); + } +} diff --git a/src/MemoryStream.php b/src/IO/PhpStream.php similarity index 84% rename from src/MemoryStream.php rename to src/IO/PhpStream.php index db65d88..7bbbe2d 100644 --- a/src/MemoryStream.php +++ b/src/IO/PhpStream.php @@ -1,30 +1,13 @@ phpStream = fopen("php://memory", "wb+"); - } - - public function loadFromFile($path) - { - $this->phpStream = fopen($path, 'rb'); - stream_set_read_buffer($this->phpStream, 1024*1024); - $this->seek(0); - } - /** * @param int $bytesCount How many bytes to read * @param array $buffer Reference to buffer array where read bytes will be written @@ -109,4 +92,4 @@ public function hasReachedEOF() { return feof($this->phpStream); } -} \ No newline at end of file +}