aboutsummaryrefslogtreecommitdiffstats
path: root/lib/puke/concatenated_io.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puke/concatenated_io.rb')
-rw-r--r--lib/puke/concatenated_io.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/puke/concatenated_io.rb b/lib/puke/concatenated_io.rb
new file mode 100644
index 0000000..dfa2940
--- /dev/null
+++ b/lib/puke/concatenated_io.rb
@@ -0,0 +1,29 @@
+require_relative "core"
+
+class Puke::ConcatenatedIO
+ def initialize(ios)
+ @ios = ios
+ end
+
+ def readpartial(n, buf)
+ rotate_if_needed
+ f = @ios.first or raise EOFError
+ r = f.readpartial(n, buf)
+ r
+ end
+
+ def close
+ @ios.each(&:close)
+ # Ensure #readpartial won't be called anymore
+ @ios = nil
+ end
+
+ private
+
+ def rotate_if_needed
+ if f = @ios.first and f.eof?
+ f.close
+ @ios.shift
+ end
+ end
+end