Sha256: c3d2274fa47c7d59df82128228b42ebf9699f728feef59abf06c52d631bd8ee4

Contents?: true

Size: 899 Bytes

Versions: 17

Compression:

Stored size: 899 Bytes

Contents

require 'open-uri'

module SpatialFeatures
  module Download
    # file can be a url, path, or file, any of which can return be a zipped archive
    def self.read(file, unzip: nil, **unzip_options)
      file = open(file, unzip: unzip, **unzip_options)
      path = ::File.path(file)
      return ::File.read(path)
    end

    def self.open(file, unzip: nil, **unzip_options)
      file = Kernel.open(file)
      file = normalize_file(file) if file.is_a?(StringIO)
      if Unzip.is_zip?(file)
        file = find_in_zip(file, find: unzip, **unzip_options)
      end
      return file
    end

    def self.normalize_file(file)
      Tempfile.new.tap do |temp|
        temp.binmode
        temp.write(file.read)
        temp.rewind
      end
    end

    def self.find_in_zip(file, find:, **unzip_options)
      return File.open(Unzip.paths(file, :find => find, **unzip_options))
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
spatial_features-2.14.1 lib/spatial_features/download.rb
spatial_features-2.14.0 lib/spatial_features/download.rb
spatial_features-2.13.0 lib/spatial_features/download.rb
spatial_features-2.12.3 lib/spatial_features/download.rb
spatial_features-2.12.2 lib/spatial_features/download.rb
spatial_features-2.12.1 lib/spatial_features/download.rb
spatial_features-2.12.0 lib/spatial_features/download.rb
spatial_features-2.11.1 lib/spatial_features/download.rb
spatial_features-2.11.0 lib/spatial_features/download.rb
spatial_features-2.10.9 lib/spatial_features/download.rb
spatial_features-2.10.8 lib/spatial_features/download.rb
spatial_features-2.10.7 lib/spatial_features/download.rb
spatial_features-2.10.6 lib/spatial_features/download.rb
spatial_features-2.10.5 lib/spatial_features/download.rb
spatial_features-2.10.4 lib/spatial_features/download.rb
spatial_features-2.10.3 lib/spatial_features/download.rb
spatial_features-2.10.2 lib/spatial_features/download.rb