Module: SpatialFeatures::Download
- Defined in:
- lib/spatial_features/download.rb
Class Method Summary collapse
- .find_in_zip(file, find:, **unzip_options) ⇒ Object
- .normalize_file(file) ⇒ Object
- .open(file, unzip: nil, **unzip_options) ⇒ Object
-
.read(file, unzip: nil, **unzip_options) ⇒ Object
file can be a url, path, or file, any of which can return be a zipped archive.
Class Method Details
.find_in_zip(file, find:, **unzip_options) ⇒ Object
29 30 31 |
# File 'lib/spatial_features/download.rb', line 29 def self.find_in_zip(file, find:, **) return File.open(Unzip.paths(file, :find => find, **)) end |
.normalize_file(file) ⇒ Object
21 22 23 24 25 26 27 |
# 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) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/spatial_features/download.rb', line 12 def self.open(file, unzip: nil, **) 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, **) end return file end |
.read(file, unzip: nil, **unzip_options) ⇒ Object
file can be a url, path, or file, any of which can return be a zipped archive
6 7 8 9 10 |
# File 'lib/spatial_features/download.rb', line 6 def self.read(file, unzip: nil, **) file = open(file, unzip: unzip, **) path = ::File.path(file) return ::File.read(path) end |