-
Notifications
You must be signed in to change notification settings - Fork 3
/
DataReader.php
41 lines (34 loc) · 945 Bytes
/
DataReader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace Trojal\PhpRo;
define('PHPRO_DATA_FILE', 1);
define('PHPRO_DATA_STRING', 2);
class DataReader
{
public function __construct($dataSource, $type = PHPRO_DATA_FILE)
{
switch ($type) {
case PHPRO_DATA_FILE:
$this->dataSource = fopen($dataSource, 'r');
break;
case PHPRO_DATA_STRING:
$this->dataSource = fopen('data://text/plain;base64,' . base64_encode($dataSource), 'r');
break;
default:
throw new \Exception('Unrecognized data type.');
break;
}
}
public function read($length)
{
return fread($this->dataSource, $length);
}
public function tell()
{
return ftell($this->dataSource);
}
public function seek($offset, $whence = SEEK_SET)
{
fseek($this->dataSource, $offset, $whence);
return $this;
}
}