Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22425657
PhutilStreamIterator.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
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
Sat, Nov 28, 04:24 (1 d, 4 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1216469
Default Alt Text
PhutilStreamIterator.php (1 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline