Weave 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 Decorators Laravel Package

zbateson/stream-decorators

Lightweight PHP stream decorators for composing and filtering streams. Wrap any resource to add behaviors like buffering, limiting, logging, or on-the-fly transforms while keeping a standard stream interface. Useful for email parsing, I/O pipelines, and testing.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit: Moderate for Laravel applications requiring low-level stream manipulation (e.g., custom file processing, MIME encoding/decoding, or legacy system integrations). Poor fit for high-level HTTP handling (e.g., API responses/requests), where Laravel’s built-in abstractions (e.g., Symfony\Component\HttpFoundation\StreamedResponse) or Guzzle’s StreamInterface implementations suffice. Ideal for:

  • Email/MIME processing (e.g., charset conversion, Base64/Quoted-Printable encoding).
  • Data pipelines (e.g., rate-limited file uploads, log filtering, or encrypted stream wrappers).
  • Legacy system bridges (e.g., interfacing with non-PSR-7-compliant services).

Integration feasibility: Low due to:

  1. Laravel’s PSR-7 stack: Laravel’s HTTP layer (e.g., Illuminate\Http\StreamedResponse) already uses Guzzle’s StreamInterface, which overlaps with this package’s functionality. Direct integration risks redundancy.
  2. Unknown repository validity: The provided GitHub URL (zbateson/stream-decorators) is unverified (last release date is invalid/future-dated). Assess via:
  3. PHP 8.1+ requirement: Compatible with Laravel 9/10, but test for edge cases (e.g., CharsetStream with multi-byte encodings).

Technical risk: High due to:

  • Unverified maintenance: No visible activity post-2026 suggests abandonment or forks (e.g., spatie/stream-decorators).
  • Security: No audit trail for CVEs (e.g., preg_replace in PregReplaceFilterStream could expose ReDoS risks if misused).
  • Compatibility: Assumes PSR-7 v2+; Laravel’s default GuzzleHttp\Psr7 (v2.6) should align, but test DecoratedCachingStream (depends on zbateson/mb-wrapper).
  • Performance: Decorators add overhead (e.g., Base64Stream buffers data). Benchmark for high-throughput use cases.

Key questions:

  1. Repository validity: Is the GitHub URL correct? If not, locate the active fork (e.g., via Packagist).
  2. Maintenance status: Are there open issues/PRs? Last commit date?
  3. Laravel-specific use cases: Does the team have documented needs for:
    • Custom MIME encoding (e.g., for email attachments)?
    • Stream-based rate limiting or throttling?
    • Legacy system integrations requiring raw stream decorators?
  4. Alternatives: Evaluate Laravel-native solutions first:
    • Symfony\Component\Mime\Part\DataPart (for MIME).
    • Guzzle’s LimitStream, FilterStream (for HTTP).
    • Symfony\Component\StreamedResponse (for streaming responses).
  5. Testing: How will decorated streams be tested? Mock StreamInterface or use php://memory?
  6. Error handling: Decorators like CharsetStream may fail silently on invalid encodings. Define fallback strategies.

Integration Approach

Stack fit: Limited to niche scenarios where Laravel’s abstractions are insufficient:

  • Email/MIME processing: Replace custom charset conversion logic with CharsetStream.
  • File uploads/downloads: Use LimitStream or RateLimitStream (if extended) for throttling.
  • Legacy integrations: Wrap non-PSR-7 streams (e.g., fopen resources) for compatibility.
  • CLI tools: Decorate php://stdin/stdout for real-time processing (e.g., log filtering).

Poor fit for:

  • HTTP request/response bodies (use Guzzle/Symfony instead).
  • Database streams (Laravel’s query builder handles this).
  • Real-time event streams (Laravel Echo/Pusher abstractions exist).

Migration path:

  1. Audit stream usage:
    • Identify all custom stream-handling code (e.g., fopen + manual fread/fwrite).
    • Check for MIME encoding/decoding (e.g., Base64, Quoted-Printable).
  2. Pilot integration:
    • Start with a single decorator (e.g., Base64Stream for file attachments).
    • Example:
      use ZBateson\StreamDecorators\Base64Stream;
      use Illuminate\Support\Facades\Storage;
      
      $file = Storage::disk('s3')->readStream('large-file.bin');
      $encoded = new Base64Stream($file);
      return response()->stream(fn() => $encoded);
      
  3. Refactor incrementally:
    • Replace custom logic with decorators (e.g., swap mb_convert_encoding + base64_encode for CharsetStream + Base64Stream).
    • Use dependency injection to inject decorated streams into services.

Compatibility:

  • PHP 8.1+: Laravel 9/10 compatible, but test with PHP 8.2+ for CharsetStream edge cases.
  • PSR-7: Requires guzzlehttp/psr7 v2+. Laravel’s default (^2.6) should suffice.
  • Dependencies: zbateson/mb-wrapper (for CharsetStream) must be compatible with Laravel’s ext-mbstring.
  • Stream resources: Decorators work with resource or StreamInterface. Avoid StreamWrapper with CharsetStream (per README).

Sequencing:

  1. Validate repository: Confirm GitHub/Packagist URL and maintenance status.
  2. Test core decorators: Benchmark Base64Stream, CharsetStream, and LimitStream in isolation.
  3. Integrate with Laravel services:
    • Email: Replace SwiftMailer/MimeMessage attachments with decorated streams.
    • Filesystem: Wrap Storage streams (e.g., readStream()).
  4. Add to composer.json:
    "require": {
        "zbateson/stream-decorators": "^3.0"
    }
    
  5. Document patterns: Create internal guidelines for decorator usage (e.g., "Use LimitStream for uploads >10MB").

Operational Impact

Maintenance:

  • Pros:
    • Reduced boilerplate: Eliminates custom stream-handling code.
    • Composable: Decorators can be stacked (e.g., CharsetStream + Base64Stream).
    • Testable: Isolate stream logic for unit tests (mock StreamInterface).
  • Cons:
    • Dependency risk: If the package is abandoned, maintain forks or rewrite critical decorators.
    • Debugging complexity: Nested decorators may obscure stream state (e.g., tell() position).
    • Performance tuning: Monitor memory usage (e.g., DecoratedCachingStream buffers data).

Support:

  • Limited community: 47 stars suggest niche adoption. Escalate issues to:
    • GitHub issues (if repository is valid).
    • Laravel Slack/Discord for alternatives.
  • Documentation: README is technical but lacks Laravel-specific examples. Supplement with:
    • Use-case guides (e.g., "Decorating Email Attachments").
    • Error-handling patterns (e.g., "Handling CharsetStream failures").

Scaling:

  • Performance:
    • Buffering decorators (e.g., DecoratedCachingStream) increase memory usage. Avoid for large streams (>100MB).
    • Rate-limiting: Use LimitStream or extend SeekingLimitStream for throughput control.
  • Concurrency: Decorators are thread-safe (PSR-7 streams are immutable). No additional scaling considerations.
  • Horizontal scaling: Stateless decorators work in distributed systems (e.g., queue workers).

Failure modes:

Decorator Failure Scenario Mitigation Strategy
CharsetStream Invalid source/target encoding Validate encodings; fall back to UTF-8.
Base64Stream Corrupted Base64 data Wrap in try-catch; log errors.
LimitStream Seek operations on non-seekable streams Document limitations; avoid seeking.
PregReplaceFilterStream ReDoS via malicious input Sanitize input; limit regex complexity.
DecoratedCachingStream Memory exhaustion Set size limits; avoid for large streams.

Ramp-up:

  • Onboarding:
    • Developers: Train on PSR-7 streams and decorator patterns (1–2 hours).
    • QA: Test edge cases (e.g., empty streams, invalid encodings).
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.
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc
animalyoung/laravel-influxdb
onix-solutions/sms-telera
lonely-lights/prosetta
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin