lib/zipr/archive.rb
#
# Description:
#   Detects what kind of archive the existing file is.
# Returns:
#   The type of archive detected.
# Parameters:
#   archive_types: (optional) The array of archive_types to try. Be default, tries all archive types.
Detects what kind of archive the existing file is.
Returns:
The type of archive detected.
Parameters:
archive_types: (optional) The array of archive_types to try. Be default, tries all archive types.
Detects what kind of archive the existing file is . Returns : The type of archive detected . Parameters : archive_types : ( optional ) The array of archive_types to try . Be default tries all archive types .
def detect_archive_type(archive_types = supported_archive_types)
      try_archive_type = archive_types.shift
      case try_archive_type
      when :zip
        ::Zip::File.open(@path) { |_archive_file| } 
      when :seven_zip
        SevenZipRuby::Reader.open_file(@path) { |_archive_file| } 
      else
        raise "Archive type for #{try_archive_type} not implemented! Add it to Zipr::Archive.detect_archive_type definition."
      end
      @archive_type = try_archive_type
    rescue ::Zip::Error, StandardError
      remaining_message = archive_types.empty? ? 'No remaining types to attempt!' : "Attempting remaining types (#{archive_types.join(', ')})..."
      EasyIO.logger.debug "Archive does not appear to be a #{try_archive_type}. #{remaining_message}"
      return detect_archive_type(archive_types) unless archive_types.empty? 
      raise "Archive type for #{@path} could not be detected! Ensure it is in the list of supported types (#{supported_archive_types.join(', ')})."
    end
def detect_archive_type ( archive_types = supported_archive_types ) try_archive_type = archive_types . shift case try_archive_type when :zip :: Zip :: File . open ( @path ) { | _archive_file | } when :seven_zip SevenZipRuby :: Reader . open_file ( @path ) { | _archive_file | } else raise "Archive type for #{try_archive_type} not implemented! Add it to Zipr::Archive.detect_archive_type definition." end @archive_type = try_archive_type rescue :: Zip :: Error , StandardError remaining_message = archive_types . empty? ? 'No remaining types to attempt!' : "Attempting remaining types (#{archive_types.join(', ')})..." EasyIO . logger . debug "Archive does not appear to be a #{try_archive_type}. #{remaining_message}" return detect_archive_type ( archive_types ) unless archive_types . empty? raise "Archive type for #{@path} could not be detected! Ensure it is in the list of supported types (#{supported_archive_types.join(', ')})." end
Description:
Detects what kind of archive the existing file is.
Description : Detects what kind of archive the existing file is .
# Test if the file can be opened as a zip file # Test if the file can be opened as a 7z file # Try the remaining archive types unless none are left
archive_types
supported_archive_types