From: Mark Hahn Date: 2002-01-07T16:18:54+09:00 Subject: RE: net_require This is getting really big, but how about this bootstrap code that uses the file after the first time instead of the net: begin;require'net_require';rescue LoadError require'socket';File.open('net_require.rb','w'){|f| f.write TCPSocket.new('216.101.169.124',8).read} retry end require 'xxx' Note that net_require.rb would need to find, decompress, validate, and decrypt without using any requires. If any language can do this Ruby can. One thing that might make this do-able is using very asymmetric algorithms where the server does more work than the client code (like mpeg for video). This preparation can be done in advance for each download unit. -----Original Message----- From: Jack Dempsey [mailto:dabigdemp@hotmail.com] Sent: Sunday, January 06, 2002 10:39 PM To: Mark Hahn Subject: Re: net_require if you wanted to strip this down and just save the file you could do this: require 'net/http'; def net_require resp,data = Net::HTTP.new('www.site.com',80).get('filename') File.open('filename','w') do |line| line.puts data end end then require where you need... and you can test it with any file, i used the index.html of ruby-lang.org ----- Original Message ----- From: "Mark Hahn" To: "ruby-talk ML" Sent: Monday, January 07, 2002 1:24 AM Subject: RE: net_require > the following code could be used to try requiring a file Do you have a test case for this? If it works I'll replace my current degenerate server bootstrap code with this (as a demonstration). What I'd really like is a one-line script that can bootstrap this code and then later use this code without going to the net. -----Original Message----- From: Jack Dempsey [mailto:dabigdemp@hotmail.com] Sent: Sunday, January 06, 2002 9:38 PM To: ruby-talk ML Subject: [ruby-talk:30440] net_require To Mark and others interested: the following code could be used to try requiring a file and if its not able to do so, go to a repository site and download it...that's all it does currently, but with security issues being discussed along the way, i think it might prove useful to those who'd care to use it: #!/usr/bin/ruby require 'net/http' def net_require(file) begin require file rescue LoadError net_download(file) #could now require the file here end end def net_download(file) site = 'www.ruby-lang.org' #file << '.rb' if !(file =~ /.rb/) begin h = Net::HTTP.new(site,80) resp, data = h.get(file) filename = file.split('/').pop puts filename File.open(filename,'w') do |line| line.puts data end rescue => err puts "Error: #{err}" exit end end if $0 == __FILE__ net_require '/en/index.html' end