willwashburn/stream
最新稳定版本:v1.0.0
Composer 安装命令:
composer require willwashburn/stream
包简介
model a sequence of data elements made available over time
关键字:
README 文档
README
model a sequence of data elements made available over time
Usage
Write and read (or peek) from a string of characters.
$stream = new \WillWashburn\Stream\Stream(); $stream->write('foo'); $stream->read(3); //foo $stream->write('bar'); $stream->write('bang'); $stream->read(4); // barb $stream->peek(3); // ang $stream->read(3); // ang
I mostly use this when buffering responses from curl requests.
$stream = new WillWashburn\Stream\Stream; curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $str) use (& $stream, $url) { $stream->write($str); try { // do something with the stream $characters = $stream->read(100); // tell curl to stop the transfer when we find what we're looking for if(strpos($characters,'string im looking for') !==false) { return -1; } } catch (StreamBufferTooSmallException $e) { // The buffer ended, so keep getting more return strlen($str); } // We return -1 to abort the transfer when we have enough buffered return -1; });
Installation
Use composer
composer require willwashburn/stream
Alternatively, add "willwashburn/stream": "~1.0.0" to your composer.json
Change Log
- v1.0.0 - Basic stream model
统计信息
- 总下载量: 973.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-03-15