1 # -*- encoding: binary -*-
3 # The MogileFS::MogileFS#new_file method is enhanced in v3.1.0+
4 # to support the :largefile parameter. While we have always
5 # supported large files via the "store_file" method, streaming
6 # large amounts of content of an unknown length required the use
9 # It is possible to stream large content of known length any WebDAV server.
10 # One example of this is for mirroring a large file from an existing HTTP
11 # server to \MogileFS without letting it hit the local filesystem.
13 # uri = URI('http://example.com/large_file')
14 # Net::HTTP.start(uri.host, uri.port) do |http|
15 # req = Net::HTTP::Get.new(uri.request_uri)
17 # http.request(req) do |response|
18 # if len = response.content_length
19 # io = mg.new_file('key', :largefile => true, :content_length => len)
21 # warn "trying to upload with Transfer-Encoding: chunked"
22 # warn "this is not supported by all WebDAV servers"
23 # io = mg.new_file('key', :largefile => :stream)
25 # response.read_body { |buf| io.write(buf) }
30 # If your WebDAV servers have chunked PUT support (e.g. Perlbal), you can
31 # stream a file of unknown length using "Transfer-Encoding: chunked".
33 # nf = mg.new_file("key", :largefile => :stream)
38 # If your WebDAV server has partial PUT support (e.g Apache), you can
39 # you can use multiple PUT requests with "Content-Range" support.
40 # This method is slower than Transfer-Encoding: chunked.
42 # nf = mg.new_file("key", :largefile => :content_range)
47 # Finally, if your WebDAV servers does not support either partial nor
48 # nor chunked PUTs, you must buffer a large file of unknown length
51 # nf = mg.new_file("key", :largefile => :tempfile)
56 module MogileFS::NewFile
58 # avoiding autoload for new code since it's going away in Ruby...
59 def self.new(dests, opts) # :nodoc:
60 largefile = opts[:largefile]
61 largefile = :stream if largefile && opts[:content_length]
62 require "mogilefs/new_file/#{largefile}" if Symbol === largefile
73 raise ArgumentError, "largefile: #{largefile.inspect} not understood"
78 require 'mogilefs/new_file/common'