twistor/stream-util
Lightweight PHP helper for working with streams. Copy/clone streams, inspect size and metadata, check readability/writability/seekability/appendability, and safely rewind/seek. Includes mode and URI utilities for fopen-compatible streams.
Storage facade, Filesystem contracts, and StreamedResponse). It could reduce boilerplate in custom stream-based logic (e.g., chunked uploads, log processing, or media streaming).Symfony\Component\StreamedResponse and Illuminate\Support\StreamableClosure, but this package offers lower-level utilities (e.g., metadata inspection, mode validation, cloning) that could fill gaps in edge cases (e.g., validating stream capabilities before operations).a+ for append-only logs).StreamedResponse scenarios.Illuminate\Http\Request and UploadedFile).composer.json), reducing version conflicts.StreamUtil::isSeekable() with Laravel’s Storage streams).getSize() returns int|false). Laravel’s type-hinting can enforce usage.fopen() fails in copy()?). Risk mitigated by wrapping calls in Laravel’s try-catch or using StreamUtil defensively.copy()) are not optimized for Laravel’s use cases (e.g., no async support). Benchmark against native PHP functions (stream_copy_to_stream) if performance-critical.stream_get_meta_data(), fstat(), or fseek()? Justify with specific pain points (e.g., "We need a reusable isAppendable() check across 5 services").StreamedResponse logic? (Unlikely—this is lower-level.)Illuminate\Filesystem\FilesystemAdapter? (Probably not directly.)fopen() or use temporary files.)StreamedResponse—could this package conflict or overlap?StreamUtil::copy() to clone a stream for a StreamedResponse).StreamUtil::getSize() for log rotation logic).if (is_writable($stream))) with StreamUtil::isWritable($stream).composer.json in a feature branch.fseek()).app(\Twistor\StreamUtil)) to hide the package and add Laravel context (e.g., logging).php://memory, php://temp (for StreamedResponse).Storage facade).fopen('php://input')).php://stdin or HTTP request bodies.StreamUtil::copy() handles Resource objects that are already closed.getSize(), isSeekable()) to replace manual checks.FormRequest.copy() for cloning streams in StreamedResponse scenarios.modeIsAppendable() to enforce stream modes in logging or audit trails.getUsableUri() for dynamic file generation (e.g., Storage::disk()->url() alternatives).twistor/stream-util.StreamUtil methods.| Laravel Use Case | StreamUtil Method |
|---|---|
| Validate upload stream | isSeekable(), isWritable() |
| Clone a stream for response | copy() |
| Check log file mode | modeIsAppendable() |
StreamUtil to vendor/package/stream-utils and update tests.StreamUtil::getMetaDataKey($stream, 'seekable').Xdebug to inspect stream states.StreamDebugger trait to log stream operations in development.StreamUtil calls in try-catch blocks to handle Resource errors gracefully.try {
$size = StreamUtil::getSize($stream);
} catch (RuntimeException $e) {
Log::error("Stream validation failed: {$e->getMessage()}");
throw new \RuntimeException("Invalid stream provided.");
}
php://temp but not compress.zlib://").Illuminate\Filesystem\FilesystemAdapter streams").StreamUtil in high-throughput scenarios (e.g., processing 1000+ streams concurrently). Use native PHP functions (stream_copy_to_stream) instead.copy() loads streams into memory—avoid for large files (>100MB). Use chunked reading/writing instead.How can I help you explore Laravel packages today?