Skip to content

Conversation

@koenvo
Copy link
Contributor

@koenvo koenvo commented Nov 14, 2025

This PR adds write support. It also introduced a BufferedStream with spooling to a temp directory to prevent high memory pressure when reading for example tracking data.

This adds comprehensive write support to the open_as_file() function with
efficient memory management and streaming capabilities.

Key features:
- BufferedStream: SpooledTemporaryFile wrapper with chunked I/O (5MB memory threshold)
- Write modes: 'wb' (write), 'ab' (append) - binary only
- Adapter pattern: write_from_stream() method (opt-in for adapters)
- Compression support: .gz, .bz2, .xz files handled automatically
- Local files and S3 URIs supported via FSSpecAdapter
- Protocols for type safety: SupportsRead, SupportsWrite

Implementation details:
- read_from()/write_to() methods use shutil.copyfileobj for chunked copying
- Context manager pattern buffers writes and flushes on exit
- No breaking changes to existing read functionality
@UnravelSports UnravelSports added this to the 3.19.0 milestone Nov 18, 2025
@UnravelSports UnravelSports mentioned this pull request Dec 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants