Class: FilesHunter::BeginPatternDecoder
- 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
Direct Known Subclasses
Decoders::ASF, Decoders::BMP, Decoders::CAB, Decoders::CFBF, Decoders::EBML, Decoders::EXE, Decoders::FLAC, Decoders::ICO, Decoders::JPEG, Decoders::M2V, Decoders::MP3, Decoders::MP4, Decoders::MPG_Video, Decoders::OGG, Decoders::RIFF, Decoders::TIFF
Defined Under Namespace
Classes: InvalidDataError, TruncatedDataError
Instance Method Summary collapse
-
#find_segments ⇒ Object
Find segments from a given data.
Methods inherited from Decoder
Instance Method Details
#find_segments ⇒ Object
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, = 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 ( != nil) @max_regexp_size = [:max_regexp_size] if ([:max_regexp_size] != nil) @offset_inc = [:offset_inc] if ([:offset_inc] != nil) @begin_pattern_offset_in_segment = [:begin_pattern_offset_in_segment] if ([: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 |