Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92625690
PhutilStreamIterator.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Nov 22, 04:18
Size
1 KB
Mime Type
text/x-php
Expires
Sun, Nov 24, 04:18 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22472345
Attached To
rPHU libphutil
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
++;
}
}
Event Timeline
Log In to Comment