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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
<?php namespace WillWashburn\Stream;
use WillWashburn\Stream\Exception\StreamBufferTooSmallException;
/** * Class Stream * * @package FasterImage */ class Stream implements StreamableInterface { /** * The string that we have downloaded so far */ protected $stream_string = '';
/** * The pointer in the string * * @var int */ protected $strpos = 0;
/** * Get characters from the string but don't move the pointer * * @param $characters * * @return string * @throws StreamBufferTooSmallException */ public function peek($characters) { if ( strlen($this->stream_string) < $this->strpos + $characters ) { throw new StreamBufferTooSmallException('Not enough of the stream available.'); }
return substr($this->stream_string, $this->strpos, $characters); }
/** * Get Characters from the string * * @param $characters * * @return string * @throws StreamBufferTooSmallException */ public function read($characters) { $result = $this->peek($characters);
$this->strpos += $characters;
return $result; }
/** * Resets the pointer to the 0 position * * @return mixed */ public function resetPointer() { $this->strpos = 0; }
/** * Append to the stream string * * @param $string */ public function write($string) { $this->stream_string .= $string; } }
|