Class: Omnizip::Pipe::StreamCompressor
- Inherits:
-
Object
- Object
- Omnizip::Pipe::StreamCompressor
- Defined in:
- lib/omnizip/pipe/stream_compressor.rb
Overview
Stream-based compression for pipe operations
Accepts any IO-like input source and writes compressed output to any IO-like sink, using chunk-based processing to avoid loading entire streams into memory.
Constant Summary collapse
- DEFAULT_CHUNK_SIZE =
Default chunk size for reading input (64KB)
64 * 1024
Instance Attribute Summary collapse
-
#bytes_written ⇒ Object
readonly
Returns the value of attribute bytes_written.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
-
#compress ⇒ Integer
Compress input stream to output stream.
-
#initialize(input, output, format, compression: nil, **options) ⇒ StreamCompressor
constructor
Initialize stream compressor.
Constructor Details
#initialize(input, output, format, compression: nil, **options) ⇒ StreamCompressor
Initialize stream compressor
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/omnizip/pipe/stream_compressor.rb', line 40 def initialize(input, output, format, compression: nil, **) @input = input @output = output @format = format @compression = compression @options = @chunk_size = [:chunk_size] || DEFAULT_CHUNK_SIZE @bytes_read = 0 @bytes_written = 0 @progress_callback = [:progress] end |
Instance Attribute Details
#bytes_written ⇒ Object (readonly)
Returns the value of attribute bytes_written.
27 28 29 |
# File 'lib/omnizip/pipe/stream_compressor.rb', line 27 def bytes_written @bytes_written end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
27 28 29 |
# File 'lib/omnizip/pipe/stream_compressor.rb', line 27 def format @format end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
27 28 29 |
# File 'lib/omnizip/pipe/stream_compressor.rb', line 27 def input @input end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
27 28 29 |
# File 'lib/omnizip/pipe/stream_compressor.rb', line 27 def @options end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
27 28 29 |
# File 'lib/omnizip/pipe/stream_compressor.rb', line 27 def output @output end |
Instance Method Details
#compress ⇒ Integer
Compress input stream to output stream
Reads input in chunks and writes compressed output, maintaining constant memory usage regardless of input size.
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/omnizip/pipe/stream_compressor.rb', line 59 def compress case @format when :zip compress_zip when :seven_zip, :"7z" compress_7z else raise ArgumentError, "Unsupported format: #{@format}" end @bytes_written end |