Last active
July 30, 2022 14:26
-
-
Save servel333/6642770 to your computer and use it in GitHub Desktop.
Basic Ruby implementation of wget to fetch a file from the internet.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def wget(url,file) | |
require 'net/http' | |
require 'uri' | |
if (!file) | |
file = File.basename(url) | |
end | |
url = URI.parse(url) | |
Net::HTTP.start(url.host) do |http| | |
resp = http.get(url.path) | |
open(file, "wb") do |file| | |
file.write(resp.body) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment