Skip to content

Add a Blob class as a bridge between string, bytes and streams#360

Merged
thekid merged 14 commits intoxp-framework:mainfrom
thekid:feature/blob-api
Mar 31, 2026
Merged

Add a Blob class as a bridge between string, bytes and streams#360
thekid merged 14 commits intoxp-framework:mainfrom
thekid:feature/blob-api

Conversation

@thekid
Copy link
Copy Markdown
Member

@thekid thekid commented Mar 29, 2026

This pull request adds an io.Blob class.

Examples

Creating a blob from various inputs:

use io\Blob;
use io\streams\{Streams, MemoryInputStream};
use util\Bytes;

$test= new Blob('Test');
$test= new Blob(new Bytes('Test'));
$test= new Blob(new MemoryInputStream('Test'));
$test= new Blob(['Te', 'st']);

$test->bytes();                    // util.Bytes("Test")
Streams::readAll($test->stream()); // "Test"
(string)$test;                     // "Test"

Iterating slices of a stream:

use io\Blob;
use io\streams\FileInputStream;

// Will echo the file's contents in slices of 8192 bytes
$blob= new Blob(new FileInputStream($argv[1]));
foreach ($blob->slices(size: 8192) as $slice) {
  echo $slice;
}

See also

@thekid thekid merged commit fa4957f into xp-framework:main Mar 31, 2026
17 checks passed
@thekid thekid deleted the feature/blob-api branch March 31, 2026 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant