lib/omnibus/download_helpers.rb in omnibus-5.4.0 vs lib/omnibus/download_helpers.rb in omnibus-5.5.0
- old
+ new
@@ -12,21 +12,22 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-require 'open-uri'
-require 'ruby-progressbar'
+require "open-uri"
+require "ruby-progressbar"
module Omnibus
module DownloadHelpers
def self.included(base)
base.send(:include, InstanceMethods)
end
module InstanceMethods
private
+
#
# Downloads a from a given url to a given path using Ruby's
# +OpenURI+ implementation.
#
# @param [String] from_url
@@ -60,20 +61,20 @@
reported_total = 0
if enable_progress_bar
progress_bar = ProgressBar.create(
output: $stdout,
- format: '%e %B %p%% (%r KB/sec)',
- rate_scale: ->(rate) { rate / 1024 },
+ format: "%e %B %p%% (%r KB/sec)",
+ rate_scale: ->(rate) { rate / 1024 }
)
options[:content_length_proc] = ->(total) {
reported_total = total
progress_bar.total = total
}
options[:progress_proc] = ->(step) {
- downloaded_amount = [step, reported_total].min
+ downloaded_amount = reported_total ? [step, reported_total].min : step
progress_bar.progress = downloaded_amount
}
end
file = open(from_url, options)
@@ -127,10 +128,10 @@
# the bug that took many hours away from the lives of a once-happy
# developer.
#
# TL;DR - Do not let Ruby ungzip our file
#
- h['Accept-Encoding'] = 'identity'
+ h["Accept-Encoding"] = "identity"
end
end
end
end
end