Skip to main content

haagenti_core/
stream.rs

1//! Streaming compression and decompression utilities.
2
3/// Flush modes for streaming compression.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
5pub enum Flush {
6    /// No flush - buffer data for optimal compression.
7    #[default]
8    None,
9
10    /// Sync flush - emit all pending output, remain compressible.
11    /// Use for: periodic checkpoints, network packets.
12    Sync,
13
14    /// Full flush - emit all pending output, reset state.
15    /// Use for: seeking support, error recovery.
16    Full,
17
18    /// Block flush - complete current block only.
19    /// Use for: block-level parallelism.
20    Block,
21
22    /// Finish - complete stream with trailer.
23    /// Use for: end of stream.
24    Finish,
25}
26
27/// Configuration for stream buffers.
28#[derive(Debug, Clone)]
29pub struct StreamConfig {
30    /// Input buffer size (default: 64 KB).
31    pub input_buffer_size: usize,
32
33    /// Output buffer size (default: 64 KB).
34    pub output_buffer_size: usize,
35
36    /// Maximum memory usage (default: 8 MB).
37    pub max_memory: usize,
38
39    /// Enable checksum verification.
40    pub verify_checksum: bool,
41}
42
43impl Default for StreamConfig {
44    fn default() -> Self {
45        StreamConfig {
46            input_buffer_size: 65536,
47            output_buffer_size: 65536,
48            max_memory: 8 * 1024 * 1024,
49            verify_checksum: true,
50        }
51    }
52}
53
54/// Stream state for tracking progress.
55#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
56pub enum StreamState {
57    /// Stream not started.
58    #[default]
59    Initial,
60    /// Stream in progress.
61    Active,
62    /// Stream finished successfully.
63    Finished,
64    /// Stream encountered error.
65    Error,
66}
67
68impl StreamState {
69    /// Check if stream is in a terminal state.
70    pub fn is_terminal(self) -> bool {
71        matches!(self, StreamState::Finished | StreamState::Error)
72    }
73
74    /// Check if stream can accept more input.
75    pub fn can_write(self) -> bool {
76        matches!(self, StreamState::Initial | StreamState::Active)
77    }
78}