Skip to content

Add a seekable input stream which spools to a temporary file#362

Merged
thekid merged 1 commit intoxp-framework:mainfrom
thekid:feature/spooled-input-stream
Apr 23, 2026
Merged

Add a seekable input stream which spools to a temporary file#362
thekid merged 1 commit intoxp-framework:mainfrom
thekid:feature/spooled-input-stream

Conversation

@thekid
Copy link
Copy Markdown
Member

@thekid thekid commented Apr 22, 2026

This pull request adds io.streams.SpooledInputStream which uses the new seekable buffers from #361

Example

use io\streams\{Buffer, SpooledInputStream};
use lang\Environment;

$socket= /* ... */;

// Buffers to a file in environment's temporary directory by default
$stream= new SpooledInputStream($socket->in());

// Use a Buffer instance for more control. Here, uses 1 MB of memory before writing to a file
$stream= new SpooledInputStream($socket->in(), new Buffer(Environment::tempDir(), 1024 * 1024));

// Skips over 100 bytes, then reads 100 bytes
$stream->seek(100); 
$stream->read(100);

// Seeks back, possible because of backing file buffer, then reads 100 bytes
$stream->seek(0);
$stream->read(100);

$stream->close();

@thekid thekid changed the title Add SpooledInputStream, a seekable input stream which spools to a temporary file Add a seekable input stream which spools to a temporary file Apr 22, 2026
@thekid thekid merged commit b2ad31d into xp-framework:main Apr 23, 2026
17 checks passed
@thekid thekid deleted the feature/spooled-input-stream branch April 23, 2026 17:03
@thekid
Copy link
Copy Markdown
Member Author

thekid commented Apr 23, 2026

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