Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

Commit

Permalink
Split streams into MemoryStream and FileStream
Browse files Browse the repository at this point in the history
  • Loading branch information
stil committed Oct 14, 2016
1 parent a17e5a0 commit ccd9030
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
12 changes: 12 additions & 0 deletions src/IO/FileStream.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
namespace GIFEndec\IO;

class FileStream extends PhpStream
{
public function __construct($path, $mode = 'rb')
{
$this->phpStream = fopen($path, $mode);
stream_set_read_buffer($this->phpStream, 1024*1024);
$this->seek(0);
}
}
10 changes: 10 additions & 0 deletions src/IO/MemoryStream.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace GIFEndec\IO;

class MemoryStream extends PhpStream
{
public function __construct()
{
$this->phpStream = fopen('php://memory', 'wb+');
}
}
23 changes: 3 additions & 20 deletions src/MemoryStream.php → src/IO/PhpStream.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,13 @@
<?php
namespace GIFEndec;
namespace GIFEndec\IO;

class MemoryStream
abstract class PhpStream
{
/**
* @var string Bytes array
*/
protected $bytes;

/**
* @var resource
*/
protected $phpStream;

public function __construct()
{
$this->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
Expand Down Expand Up @@ -109,4 +92,4 @@ public function hasReachedEOF()
{
return feof($this->phpStream);
}
}
}

0 comments on commit ccd9030

Please sign in to comment.