Sha256: 5c93bfb1fae4fb0d224e5956ac824279548eeec49e80d9de380549d9534412a9

Contents?: true

Size: 1.01 KB

Versions: 10

Compression:

Stored size: 1.01 KB

Contents

require "arr-pm"

# fix for Ruby 3.0
unless RPM::File::Header::HEADER_MAGIC == "\x8e\xad\xe8\x01\x00\x00\x00\x00".force_encoding("BINARY")
  RPM::File::Header.send(:remove_const, "HEADER_MAGIC")
  RPM::File::Header.const_set("HEADER_MAGIC", "\x8e\xad\xe8\x01\x00\x00\x00\x00".force_encoding("BINARY"))
end

module Excavate
  module Extractors
    class RpmExtractor < Extractor
      def extract(target)
        File.open(@archive, "rb") do |file|
          rpm = RPM::File.new(file)
          content = rpm.payload.read
          path = target_path(@archive, rpm.tags, target)

          File.write(path, content, mode: "wb")
        end
      end

      private

      def target_path(archive, tags, dir)
        archive_format = tags[:payloadformat]
        compression_format = tags[:payloadcompressor] == "gzip" ? "gz" : tags[:payloadcompressor]
        basename = File.basename(archive, ".*")
        filename = basename + "." + archive_format + "." + compression_format
        File.join(dir, filename)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
excavate-0.3.1 lib/excavate/extractors/rpm_extractor.rb
excavate-0.3.0 lib/excavate/extractors/rpm_extractor.rb
excavate-0.2.5 lib/excavate/extractors/rpm_extractor.rb
excavate-0.2.4 lib/excavate/extractors/rpm_extractor.rb
excavate-0.2.3 lib/excavate/extractors/rpm_extractor.rb
excavate-0.2.2 lib/excavate/extractors/rpm_extractor.rb
excavate-0.2.1 lib/excavate/extractors/rpm_extractor.rb
excavate-0.2.0 lib/excavate/extractors/rpm_extractor.rb
excavate-0.1.1 lib/excavate/extractors/rpm_extractor.rb
excavate-0.1.0 lib/excavate/extractors/rpm_extractor.rb