PHP code example of kusabi / stream

1. Go to this page and download the library: Download kusabi/stream library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kusabi / stream example snippets


use Kusabi\Stream\Stream;

// Instantiate a Uri instance
$stream = new Stream(fopen('php://stdin', 'r'));

// Fetch the properties of the Stream
$stream->getContents(); // Get everything from the current pointer to the end of the stream
$stream->getSize(); // Get the size of the stream in bytes
$stream->isSeekable();
$stream->isReadable();
$stream->isWritable();
$stream->seek($offset, $whence = SEEK_SET); // Move the pointer around in the stream
$stream->tell(); // Where is the pointer in the stream
$stream->rewind(); // Set the pointer to the beginning of the stream
$stream->read($length); // Read the next $length character from the stream
$stream->write($string); // Write data into the stream. Returns the number of bytes written
$stream->getMetadata($key = null); // Get all the metadata, or a particular key
$stream->getStat($key = null); // Get all the fstat entries, or a particular key
$stream->isLocal(); // Determine if the stream url is local using `stream_is_local()`
$stream->getLine($length = null, $ending = "\n"); // Fetch a line up to a length or delimiter (which ever comes first)
$stream->pipe(Stream $stream); // Copy the contents of one stream into another
(string) $stream; // Rewind and get all the contents from the stream


use Kusabi\Stream\StreamFactory;

// Instantiate a Uri instance
$factory = new StreamFactory();
$stream = $factory->createStream('temp resource with data in it');
$stream = $factory->createStreamFromFile('file.txt');
$stream = $factory->createStreamFromResource(fopen('php://stdin', 'r'));