# frozen_string_literal: true module SafeZip # SafeZip::Extract provides a safe interface # to extract specific directories or files within a `zip` archive. # # @example Extract directories to destination # SafeZip::Extract.new(archive_file).extract(directories: ['app/', 'test/'], to: destination_path) # @example Extract files to destination # SafeZip::Extract.new(archive_file).extract(files: ['index.html', 'app/index.js'], to: destination_path) class Extract Error = Class.new(StandardError) PermissionDeniedError = Class.new(Error) SymlinkSourceDoesNotExistError = Class.new(Error) UnsupportedEntryError = Class.new(Error) EntrySizeError = Class.new(Error) AlreadyExistsError = Class.new(Error) NoMatchingError = Class.new(Error) ExtractError = Class.new(Error) attr_reader :archive_path def initialize(archive_file) @archive_path = archive_file end # extract given files or directories from the archive into the destination path # # @param [Hash] opts the options for extraction. # @option opts [Array 0 end end def extract_all_entries(zip_archive, params, entries) entries.count do |zip_entry| SafeZip::Entry.new(zip_archive, zip_entry, params) .extract end end end end