stk2k / iostream
输入输出流库
0.2.1
2021-07-09 08:04 UTC
Requires
- php: >=7.2
- ext-json: *
- stk2k/file-system: ~0.1
- stk2k/xstring: ~0.1
Requires (Dev)
- mikey179/vfsstream: ^1.6.8
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^8.5.15
README
描述
输入输出流库
演示
StringInputStream
use stk2k\iostream\string\StringInputStream; // foreach $sis = new StringInputStream('Hello'); foreach ($sis as $c){ echo $c . '.'; // H.e.l.l.o. } // read $sis = new StringInputStream('Hello'); while($c = $sis->read(1)){ echo $c . '.'; // H.e.l.l.o. } // read line $sis = new StringInputStream("Foo\nBar\nBaz"); while($line = $sis->readLine()){ echo $line . '.'; // Foo.Bar.Baz. } // read lines $sis = new StringInputStream("Foo\nBar\nBaz"); $lines = $sis->readLines(); echo implode('.', $lines); // Foo.Bar.Baz
PushBackStringInputStream
use stk2k\iostream\string\PushBackStringInputStream; use stk2k\xstring\xStringBuffer; $sis = new PushBackStringInputStream(', World!'); $sis->unread(new xStringBuffer('olleH')); echo $sis->readLine(); // Hello, World!
FileInputStream
use stk2k\filesystem\File; use stk2k\iostream\file\FileInputStream; // foreach $file = new File('test/_files/b.txt'); $fis = new FileInputStream($file); foreach ($fis as $c){ echo $c . '.'; // H.e.l.l.o. } // read $file = new File('test/_files/b.txt'); $fis = new FileInputStream($file); while($c = $fis->read(1)){ echo $c . '.'; // H.e.l.l.o. } // read line $file = new File('test/_files/c.txt'); $fis = new FileInputStream($file); while($line = $fis->readLine()){ echo $line . '.'; // Foo.Bar.Baz. } // read lines $file = new File('test/_files/c.txt'); $fis = new FileInputStream($file); $lines = $fis->readLines(); echo implode('.', $lines); // Foo.Bar.Baz
要求
PHP 7.2 或更高版本
安装 stk2k/iostream
推荐通过 Composer 安装 stk2k/iostream。
composer require stk2k/iostream
许可
作者
免责声明
本软件无任何保证。
我们不对使用本软件造成的任何后果负责。
请自行承担责任。