- bytesleft = @opts[:size].andand.to_i || 2**16
- IO.popen([env, 'arv-get', "#{@opts[:uuid]}/#{@opts[:file]}"],
- 'rb') do |io|
- while bytesleft > 0 && buf = io.read(bytesleft)
- # shrink the bytesleft count, if we were given a
- # maximum byte count to read
- if @opts.include? :size
- bytesleft = bytesleft - buf.length
- end
- yield buf
- end
- if buf and @opts.include? :size and bytesleft == 0 then
- unless buf[-1] == "\n"
- yield "\n"
- end
- # This line should match the regex in
- # app/assets/javascripts/log_viewer.js:addToLogViewer()
- yield Time.now.strftime("%F_%T zzzzz-zzzzz-zzzzzzzzzzzzzzz 0 File truncated (exceeded #{@opts[:size]} bytes). To retrieve the full file: arv-get #{@opts[:uuid]}/#{@opts[:file]}\n")
+ bytesleft = @opts[:maxbytes].andand.to_i || 2**16
+ io = IO.popen([env, 'arv-get', "#{@opts[:uuid]}/#{@opts[:file]}"], 'rb')
+ while bytesleft > 0 && (buf = io.read([bytesleft, 2**16].min)) != nil
+ # shrink the bytesleft count, if we were given a maximum byte
+ # count to read
+ if @opts.include? :maxbytes
+ bytesleft = bytesleft - buf.length