doc: tag files containing internal implementation details
[ruby-mogilefs-client.git] / lib / mogilefs / util.rb
blob6b46c97069404ba31a5ffac8656dfe602b1aaf38
1 # -*- encoding: binary -*-
2 require 'mogilefs'
3 require 'socket'
5 module MogileFS::Util
7   # here are internal implementation details, do not use them in your code
8   # TODO: cleanup
9   if IO.respond_to?(:copy_stream)
10     def copy_stream(src, dst)
11       IO.copy_stream(src, dst)
12     end
13   else
14     def copy_stream(src, dst)
15       buf = ""
16       written = 0
17       begin
18         src.readpartial(0x4000, buf)
19         written += dst.write(buf)
20       rescue EOFError
21         break
22       end while true
23       written
24     end
25   end
27   class StoreContent < Proc
28     def initialize(total_size, &writer_proc)
29       @total_size = total_size
30       super(&writer_proc)
31     end
32     def length
33       @total_size
34     end
35   end
37 end
39 require 'timeout'
41 # Timeout error class.  Subclassing it from Timeout::Error is the only
42 # reason we require the 'timeout' module, otherwise that module is
43 # broken and worthless to us.
44 class MogileFS::Timeout < Timeout::Error; end