Class: Omnizip::Formats::Xz
- Inherits:
-
Object
- Object
- Omnizip::Formats::Xz
- Defined in:
- lib/omnizip/formats/xz.rb,
lib/omnizip/formats/xz/reader.rb,
lib/omnizip/formats/xz/writer.rb
Overview
XZ compression format Creates .xz files compatible with XZ Utils
Defined Under Namespace
Classes: Builder, Entry, Reader, Writer
Class Method Summary collapse
-
.create(input, output = nil, options = {}) ⇒ Object
Create a .xz file from input data.
-
.create_file(path, options = {}) {|builder| ... } ⇒ Object
Convenience method with block syntax.
-
.decompress(input, output = nil, _options = {}) ⇒ String?
(also: decode, extract)
Decompress XZ, LZIP (.lz), or LZMA_Alone (.lzma) data.
Class Method Details
.create(input, output = nil, options = {}) ⇒ Object
Create a .xz file from input data
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/omnizip/formats/xz.rb', line 19 def create(input, output = nil, = {}) encoder = ::Omnizip::Formats::XzImpl::StreamEncoder.new( check_type: [:check] || ::Omnizip::Formats::XzConst::CHECK_CRC64, dict_size: [:dict_size] || (64 * 1024 * 1024), ) compressed = encoder.encode(input) if output Omnizip::IO::Sink.for(output).write(compressed) else compressed end end |
.create_file(path, options = {}) {|builder| ... } ⇒ Object
Convenience method with block syntax
39 40 41 42 43 44 45 |
# File 'lib/omnizip/formats/xz.rb', line 39 def create_file(path, = {}) builder = Builder.new() yield builder if block_given? compressed = create(builder.data, nil, ) File.binwrite(path, compressed) end |
.decompress(input, output = nil, _options = {}) ⇒ String? Also known as: decode, extract
Decompress XZ, LZIP (.lz), or LZMA_Alone (.lzma) data
This method automatically detects the format based on magic bytes and routes to the appropriate decoder:
- XZ format (.xz): Container format with stream header/footer/index
- LZIP format (.lz): Standalone format with "LZIP" magic and CRC32 footer
- LZMA_Alone format (.lzma): Legacy standalone format with properties byte
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/omnizip/formats/xz.rb', line 66 def decompress(input, output = nil, = {}) data = Omnizip::IO::Source.for(input).read # Detect format and decode decompressed = decode_lzma_data(data) if output Omnizip::IO::Sink.for(output).write(decompressed) nil else decompressed end end |