Skip to content

Instantly share code, notes, and snippets.

@janko
janko / 01-safe-download.rb
Last active February 18, 2025 08:40
A safe way in Ruby to download a file to disk using open-uri (with/without comments)
require "open-uri"
require "net/http"
Error = Class.new(StandardError)
DOWNLOAD_ERRORS = [
SocketError,
OpenURI::HTTPError,
RuntimeError,
URI::InvalidURIError,