Skip to content

stk2k/iostream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Input and output stream library

Latest Version on Packagist Software License Build Status Coverage Status Code Climate Total Downloads

Description

Input and output stream library

Demo

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

Requirement

PHP 7.2 or later

Installing stk2k/iostream

The recommended way to install stk2k/iostream is through Composer.

composer require stk2k/iostream

License

MIT

Author

stk2k

Disclaimer

This software is no warranty.

We are not responsible for any results caused by the use of this software.

Please use the responsibility of the your self.

About

Input and output stream library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages