module SpatialFeatures::Download

Public Class Methods

entries(file) click to toggle source
# File lib/spatial_features/download.rb, line 29
def self.entries(file)
  file = Kernel.open(file)
  file = normalize_file(file) if file.is_a?(StringIO)
  Unzip.entries(file)
end
find_in_zip(file, find:, **unzip_options) click to toggle source
# File lib/spatial_features/download.rb, line 35
def self.find_in_zip(file, find:, **unzip_options)
  return File.open(Unzip.paths(file, :find => find, **unzip_options))
end
normalize_file(file) click to toggle source
# File lib/spatial_features/download.rb, line 21
def self.normalize_file(file)
  Tempfile.new.tap do |temp|
    temp.binmode
    temp.write(file.read)
    temp.rewind
  end
end
open(file, unzip: nil, **unzip_options) click to toggle source
# File lib/spatial_features/download.rb, line 12
def self.open(file, unzip: nil, **unzip_options)
  file = Kernel.open(file)
  file = normalize_file(file) if file.is_a?(StringIO)
  if unzip && Unzip.is_zip?(file)
    file = find_in_zip(file, find: unzip, **unzip_options)
  end
  return file
end
read(file, unzip: nil, **unzip_options) click to toggle source

file can be a url, path, or file, any of which can return be a zipped archive

# File lib/spatial_features/download.rb, line 6
def self.read(file, unzip: nil, **unzip_options)
  file = open(file, unzip: unzip, **unzip_options)
  path = ::File.path(file)
  return ::File.read(path)
end