Class: FilesHunter::BeginPatternDecoder

Inherits:
Decoder
  • Object
show all
Defined in:
lib/fileshunter/BeginPatternDecoder.rb,
ext/fileshunter/Decoders/_FLAC.c

Overview

Decoders that are based on begin patterns (sucha as Magic Numbers) inherit from this class. They then have to implement the following methods:

  • get_begin_pattern: To give the begin pattern and eventual options

  • decode: To decode data starting a given offset that matches the begin pattern

  • check_begin_pattern: Provide a quick check of the begin pattern when found [optional]

They can then use the following DSL in the decode method:

  • found_relevant_data: Indicate that we are certain the beginning of data of the given extension has been found

  • invalid_data: Indicate the data read is invalid for our Decoder

  • truncated_data: Indicate the data should have continued if it were to be complete. This can happen even in the middle of a stream, if the data has been corrupted.

  • progress: Indicate the progression of the scan: everything before the progression is considered valid for the given extension (if found_relevant_data was called previously)

  • metadata: Set metadata properties

Defined Under Namespace

Classes: InvalidDataError, TruncatedDataError

Instance Method Summary collapse

Methods inherited from Decoder

#segments_found, #setup

Instance Method Details

#find_segmentsObject

Find segments from a given data



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fileshunter/BeginPatternDecoder.rb', line 36

def find_segments
  @begin_pattern, options = get_begin_pattern
  log_debug "Pattern to find: #{@begin_pattern.inspect}"
  @has_to_check_begin_pattern = self.respond_to?(:check_begin_pattern)
  # Parse options
  @max_regexp_size = 32
  @offset_inc = 1
  @begin_pattern_offset_in_segment = 0
  if (options != nil)
    @max_regexp_size = options[:max_regexp_size] if (options[:max_regexp_size] != nil)
    @offset_inc = options[:offset_inc] if (options[:offset_inc] != nil)
    @begin_pattern_offset_in_segment = options[:begin_pattern_offset_in_segment] if (options[:begin_pattern_offset_in_segment] != nil)
  end
  @metadata = {}
  @missing_previous_data = false
  foreach_begin_pattern do |begin_pattern_offset|
    next decode(begin_pattern_offset)
  end
end