]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
httputil: reinstate partial_body
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sun, 1 Apr 2007 15:04:53 +0000 (15:04 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sun, 1 Apr 2007 15:04:53 +0000 (15:04 +0000)
lib/rbot/core/utils/httputil.rb

index 4ce8dcc33d848e948a30307a417e634e37227e1a..78445abebcebdc39d99d5601612cc153a044ac1a 100644 (file)
@@ -20,6 +20,25 @@ rescue LoadError => e
   error "Secured HTTP connections will fail"
 end
 
+module ::Net 
+  class HTTPResponse 
+    # Read chunks from the body until we have at least _size_ bytes, yielding 
+    # the partial text at each chunk. Return the partial body. 
+    def partial_body(size=0, &block) 
+
+      partial = String.new 
+
+      self.read_body { |chunk| 
+        partial << chunk 
+        yield partial if block_given? 
+        break if size and size > 0 and partial.length >= size 
+      } 
+
+      return partial 
+    end 
+  end 
+end
+
 Net::HTTP.version_1_2
 
 module ::Irc