class Tubeclip::Upload::RemoteFile
Public Class Methods
new(url, opts)
click to toggle source
# File lib/tubeclip/request/remote_file.rb, line 9 def initialize(url, opts) @pos = 0 @url = url @uri = URI(@url) @content_length = opts[:content_length] @fiber = Fiber.new do |first| Net::HTTP.start(@uri.host, @uri.port) do |http| request = Net::HTTP::Get.new @uri.request_uri http.request request do |response| response.read_body do |chunk| @pos += chunk.bytesize Fiber.yield chunk end end end end end
Public Instance Methods
filename()
click to toggle source
# File lib/tubeclip/request/remote_file.rb, line 46 def filename File.basename(@url) end
head()
click to toggle source
# File lib/tubeclip/request/remote_file.rb, line 39 def head @head_result || Net::HTTP.start(@uri.host, @uri.port) do |http| @head_result = http.request(Net::HTTP::Head.new(@uri.request_uri)) end @head_result end
length()
click to toggle source
# File lib/tubeclip/request/remote_file.rb, line 54 def length @content_length ||= head.content_length return @content_length end
path()
click to toggle source
# File lib/tubeclip/request/remote_file.rb, line 50 def path @url end
ping?()
click to toggle source
# File lib/tubeclip/request/remote_file.rb, line 31 def ping? end
pos()
click to toggle source
# File lib/tubeclip/request/remote_file.rb, line 35 def pos @pos end
read(buf_size = 524288)
click to toggle source
# File lib/tubeclip/request/remote_file.rb, line 59 def read(buf_size = 524288) buf = "" while (buf.bytesize < buf_size.to_i) && @fiber.alive? _chunk = @fiber.resume buf << _chunk if _chunk.is_a? String end buf end