Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Stream Laravel Package

jstewmc/stream

jstewmc/stream is a small PHP library that provides a simple Stream abstraction for working with PHP stream resources. It helps with reading/writing, buffering, and common stream operations behind a cleaner, object-oriented API.

View on GitHub
Deep Wiki
Context7

Stream a very large text file or string character-by-character (multi-byte safe).

Frequently asked questions about Stream
How does jstewmc/stream handle multi-byte characters like emojis or UTF-8 text in Laravel?
The package is explicitly designed for multi-byte safety, ensuring characters like emojis or non-ASCII text are read correctly without corruption. It uses PHP’s stream resources under the hood, which natively support UTF-8, making it ideal for internationalized Laravel applications or log files with mixed encodings. For edge cases like BOM markers, you may need to pre-process files, but the core streaming logic remains robust.
Can I use jstewmc/stream with Laravel’s queue system (e.g., Horizon or Redis queues) for processing large files?
Yes, this package is perfect for Laravel queues. Since it streams files character-by-character, it avoids loading entire files into memory, reducing the risk of timeouts or memory limits in long-running jobs. Pair it with Laravel’s `retry()` or queue middleware to handle interruptions gracefully, especially for files larger than 1GB. Test with your queue worker’s memory settings to ensure stability.
Will jstewmc/stream work with Laravel’s Storage facade (e.g., S3, local files, or FTP)?
Absolutely. The package integrates seamlessly with Laravel’s Storage facade. For example, you can use `Storage::disk('s3')->readStream('large-file.log')` to stream files from cloud storage without downloading them entirely. It also supports local files and custom streams via `fopen()`, making it versatile for any Laravel filesystem configuration.
Does jstewmc/stream support writing streams, or is it read-only?
The package is primarily designed for reading streams, offering a clean API for character-by-character input. Writing streams are not a core feature, but you can extend it with custom logic if needed. For write operations, consider Laravel’s built-in file handling or libraries like `ReactPHP` for more advanced use cases. Always test write operations thoroughly, as they introduce additional complexity.
What Laravel versions does jstewmc/stream support, and are there any breaking changes to watch for?
The package is compatible with Laravel LTS versions 8.x through 10.x and requires PHP 7.4+. There are no Laravel-specific dependencies, so it avoids vendor lock-in. The API is stable, but always check the package’s changelog for minor updates, especially if you’re using features like seek operations, which may have limitations in future versions.
How do I test jstewmc/stream in a Laravel project, especially for large files or edge cases?
For unit testing, mock streams using PHP’s `Stringable` or `ResourceBundle` to simulate file inputs without hitting disk I/O. For integration tests, use Laravel’s Storage facade to test real files, including large ones (e.g., 100MB+). Load test with files approaching your application’s limits to validate memory usage, and use PHPUnit’s assertions to verify character-level accuracy, especially for multi-byte sequences.
What happens if a stream is interrupted mid-character (e.g., network failure or timeout)?
The package itself doesn’t include built-in recovery logic for interrupted streams, as this depends on your use case. For Laravel queues, leverage the `retry()` mechanism or dead-letter queues to handle failures. For API responses, implement chunked streaming with timeouts and fallback logic. Always pair this package with your application’s error-handling strategy, such as Laravel events or custom middleware.
Are there alternatives to jstewmc/stream for streaming files in Laravel, and when should I choose them?
Alternatives include Laravel’s `SplFileObject` or `ReactPHP` streams. Use `SplFileObject` if you need seek/reset functionality, though it lacks built-in multi-byte guarantees. `ReactPHP` is better for real-time or concurrent streaming (e.g., WebSockets). Choose jstewmc/stream when multi-byte safety and simplicity are priorities, especially for background jobs or CLI tools where memory efficiency is critical.
Can jstewmc/stream be used for chunked API responses in Laravel, like streaming large file downloads?
Yes, this package works well with Laravel’s `Response::stream()` for chunked API responses. By reading files character-by-character, you can send data incrementally to clients without buffering the entire file in memory. This is ideal for serving large logs, CSV exports, or other text-based downloads. Just ensure your server’s timeout settings accommodate the streaming duration.
How do I integrate jstewmc/stream into a Laravel CLI artisan command for processing massive datasets?
Start by requiring the package via Composer (`composer require jstewmc/stream`). In your artisan command, use the streamer to read files line-by-line or character-by-character, avoiding `file_get_contents()`. For example, wrap `Storage::disk('local')->readStream()` with the package’s API to process files efficiently. Monitor memory usage with `memory_get_usage()` to ensure your CLI script stays within limits, especially for files larger than 1GB.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor