Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F12660586
PhutilStreamIterator.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
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
Fri, Nov 28, 15:40 (13 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1077156
Default Alt Text
PhutilStreamIterator.php (1 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline
Log In to Comment