<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>call (BlobStream)</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" /> </head> <body class="standalone-code"> <pre><span class="ruby-comment cmt"># File lib/deltacloud/helpers/blob_stream.rb, line 25</span> <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">env</span>, <span class="ruby-identifier">credentials</span>, <span class="ruby-identifier">params</span>) <span class="ruby-identifier">body</span> = <span class="ruby-constant">DeferrableBody</span>.<span class="ruby-identifier">new</span> <span class="ruby-comment cmt">#Get the headers out asap. Don't specify a content-type let</span> <span class="ruby-comment cmt">#the client guess and if they can't they SHOULD default to</span> <span class="ruby-comment cmt">#'application/octet-stream' anyway as per:</span> <span class="ruby-comment cmt">#http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.2.1</span> <span class="ruby-constant">EM</span>.<span class="ruby-identifier">next_tick</span> { <span class="ruby-identifier">env</span>[<span class="ruby-value str">'async.callback'</span>].<span class="ruby-identifier">call</span> [<span class="ruby-value">200</span>, { <span class="ruby-value str">'Content-Type'</span> =<span class="ruby-operator">></span> <span class="ruby-node">"#{params['content_type']}"</span>, <span class="ruby-value str">'Content-Disposition'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">params</span>[<span class="ruby-value str">"content_disposition"</span>], <span class="ruby-value str">'Content-Length'</span> =<span class="ruby-operator">></span> <span class="ruby-node">"#{params['content_length']}"</span>}, <span class="ruby-identifier">body</span>] } <span class="ruby-comment cmt">#call the driver from here. the driver method yields for every chunk</span> <span class="ruby-comment cmt">#of blob it receives. Then use body.call to write that chunk as received.</span> <span class="ruby-identifier">driver</span>.<span class="ruby-identifier">blob_data</span>(<span class="ruby-identifier">credentials</span>, <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:bucket</span>], <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:blob</span>], <span class="ruby-identifier">params</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">chunk</span><span class="ruby-operator">|</span> <span class="ruby-identifier">body</span>.<span class="ruby-identifier">call</span> [<span class="ruby-node">"#{chunk}"</span>]} <span class="ruby-comment cmt">#close blob_data block</span> <span class="ruby-identifier">body</span>.<span class="ruby-identifier">succeed</span> <span class="ruby-constant">AsyncResponse</span> <span class="ruby-comment cmt"># Tell Thin to not close connection & work other requests</span> <span class="ruby-keyword kw">end</span></pre> </body> </html>