Sha256: 706061e7d80622796f8f0b1aa3662b5adc3969b41f0537b728b137ae057d4087

Contents?: true

Size: 947 Bytes

Versions: 3

Compression:

Stored size: 947 Bytes

Contents

require 'zip'

module Datasets
  class ZipExtractor
    def initialize(path)
      @path = path
    end

    def extract_first_file
      Zip::File.open(@path) do |zip_file|
        zip_file.each do |entry|
          next unless entry.file?

          entry.get_input_stream do |input|
            return yield(input)
          end
        end
      end
      nil
    end

    def extract_file(file_path)
      Zip::File.open(@path) do |zip_file|
        zip_file.each do |entry|
          next unless entry.file?
          next unless entry.name == file_path

          entry.get_input_stream do |input|
            return yield(input)
          end
        end
      end
      nil
    end

    def extract_files
      Zip::File.open(@path) do |zip_file|
        zip_file.each do |entry|
          next unless entry.file?

          entry.get_input_stream do |input|
            yield(input)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
red-datasets-0.1.8 lib/datasets/zip-extractor.rb
red-datasets-0.1.7 lib/datasets/zip-extractor.rb
red-datasets-0.1.6 lib/datasets/zip-extractor.rb