Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F3281711
PhutilStreamIterator.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
1 KB
Referenced Files
None
Subscribers
None
PhutilStreamIterator.php
View Options
<?php
final
class
PhutilStreamIterator
extends
Phobject
implements
Iterator
{
private
$stream
;
private
$started
=
false
;
private
$naturalKey
;
private
$data
;
public
function
__construct
(
$stream
)
{
$this
->
stream
=
$stream
;
}
/* -( Iterator Implementation )-------------------------------------------- */
public
function
rewind
(
)
{
if
(
$this
->
started
)
{
// When you first foreach() an iterator the rewind() method gets called
// so we have to work the first time.
throw
new
Exception
(
pht
(
'Stream iterators can not be rewound!'
)
)
;
}
$this
->
started
=
true
;
$this
->
naturalKey
=
-
1
;
$this
->
next
(
)
;
}
public
function
valid
(
)
{
return
(
$this
->
data
!==
null
)
;
}
public
function
current
(
)
{
return
$this
->
data
;
}
public
function
key
(
)
{
return
$this
->
naturalKey
;
}
public
function
next
(
)
{
$stream
=
$this
->
stream
;
if
(
!
$stream
)
{
return
;
}
if
(
feof
(
$stream
)
)
{
fclose
(
$stream
)
;
$this
->
stream
=
null
;
$this
->
data
=
null
;
return
;
}
$bytes
=
fread
(
$stream
,
64
*
1024
)
;
if
(
$bytes
===
false
)
{
throw
new
Exception
(
pht
(
'Failed to fread() from request input stream.'
)
)
;
}
$this
->
data
=
$bytes
;
$this
->
naturalKey
++
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Mar 24, 00:48 (13 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1113365
Default Alt Text
PhutilStreamIterator.php (1 KB)
Attached To
Mode
rARC Arcanist
Attached
Detach File
Event Timeline
Log In to Comment