1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
| | # -*- encoding: binary -*-
# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> et. al.
# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
require_relative 'wbuf_common'
class Yahns::StreamFile # :nodoc:
include Yahns::WbufCommon
def initialize(body, persist, offset, count)
if body.respond_to?(:to_io)
@tmpio = body.to_io
else
path = body.to_path
if path =~ %r{\A/dev/fd/(\d+)\z}
@tmpio = IO.for_fd($1.to_i)
@tmpio.autoclose = false
else
@tmpio = File.open(path)
end
end
@sf_offset = offset
@sf_count = count || @tmpio.stat.size
@wbuf_persist = persist # whether or not we keep the connection alive
@body = body
end
# called by last wbuf_flush
def wbuf_close(client)
if File === @tmpio && @tmpio != @body
@tmpio.close
end
wbuf_close_common(client)
end
end
|