Module: Omnizip::Extraction

Defined in:
lib/omnizip/extraction.rb,
lib/omnizip/extraction/filter_chain.rb,
lib/omnizip/extraction/glob_pattern.rb,
lib/omnizip/extraction/regex_pattern.rb,
lib/omnizip/extraction/pattern_matcher.rb,
lib/omnizip/extraction/predicate_pattern.rb,
lib/omnizip/extraction/selective_extractor.rb

Overview

Provides selective extraction capabilities for archives

Supports extracting files matching glob patterns, regex patterns, or custom predicates without extracting the entire archive.

Defined Under Namespace

Classes: FilterChain, GlobPattern, PatternMatcher, PredicatePattern, RegexPattern, SelectiveExtractor

Class Method Summary collapse

Class Method Details

.count_matching(archive, pattern) ⇒ Integer

Count files matching a pattern

Parameters:

  • archive (Object)

    Archive to count in

  • pattern (String, Regexp, Array)

    Pattern(s) to match

Returns:

  • (Integer)

    Number of matches



64
65
66
67
68
# File 'lib/omnizip/extraction.rb', line 64

def count_matching(archive, pattern)
  filter = build_filter(pattern)
  extractor = SelectiveExtractor.new(archive, filter)
  extractor.count_matches
end

.extract_matching(archive, pattern, dest, options = {}) ⇒ Array<String>

Extract files matching a pattern from an archive

Parameters:

  • archive (Object)

    Archive to extract from

  • pattern (String, Regexp, Array)

    Pattern(s) to match

  • dest (String)

    Destination directory

  • options (Hash) (defaults to: {})

    Extraction options

Options Hash (options):

  • :preserve_paths (Boolean)

    Keep directory structure

  • :flatten (Boolean)

    Extract all to destination root

  • :overwrite (Boolean)

    Overwrite existing files

Returns:

  • (Array<String>)

    Paths of extracted files



31
32
33
34
35
# File 'lib/omnizip/extraction.rb', line 31

def extract_matching(archive, pattern, dest, options = {})
  filter = build_filter(pattern)
  extractor = SelectiveExtractor.new(archive, filter)
  extractor.extract(dest, options)
end

.extract_to_memory_matching(archive, pattern) ⇒ Hash<String, String>

Extract files matching a pattern to memory

Parameters:

  • archive (Object)

    Archive to extract from

  • pattern (String, Regexp, Array)

    Pattern(s) to match

Returns:

  • (Hash<String, String>)

    Hash of filename => content



42
43
44
45
46
# File 'lib/omnizip/extraction.rb', line 42

def extract_to_memory_matching(archive, pattern)
  filter = build_filter(pattern)
  extractor = SelectiveExtractor.new(archive, filter)
  extractor.extract_to_memory
end

.extract_with_filter(archive, filter, dest, options = {}) ⇒ Array<String>

Extract with a filter chain

Parameters:

  • archive (Object)

    Archive to extract from

  • filter (FilterChain)

    Filter chain to apply

  • dest (String)

    Destination directory

  • options (Hash) (defaults to: {})

    Extraction options

Returns:

  • (Array<String>)

    Paths of extracted files



77
78
79
80
# File 'lib/omnizip/extraction.rb', line 77

def extract_with_filter(archive, filter, dest, options = {})
  extractor = SelectiveExtractor.new(archive, filter)
  extractor.extract(dest, options)
end

.list_matching(archive, pattern) ⇒ Array

List files matching a pattern without extracting

Parameters:

  • archive (Object)

    Archive to list from

  • pattern (String, Regexp, Array)

    Pattern(s) to match

Returns:

  • (Array)

    Matching entries



53
54
55
56
57
# File 'lib/omnizip/extraction.rb', line 53

def list_matching(archive, pattern)
  filter = build_filter(pattern)
  extractor = SelectiveExtractor.new(archive, filter)
  extractor.list_matches
end

.match_result(archive, pattern) ⇒ Models::MatchResult

Get match result with statistics

Parameters:

  • archive (Object)

    Archive to analyze

  • pattern (String, Regexp, Array)

    Pattern(s) to match

Returns:



87
88
89
90
91
# File 'lib/omnizip/extraction.rb', line 87

def match_result(archive, pattern)
  filter = build_filter(pattern)
  extractor = SelectiveExtractor.new(archive, filter)
  extractor.match_result
end