Class: ServeByteRange::ByteRangeBody
- Inherits:
-
Object
- Object
- ServeByteRange::ByteRangeBody
show all
- Defined in:
- lib/serve_byte_range.rb
Instance Method Summary
collapse
Constructor Details
#initialize(http_range:, resource_size:, resource_content_type: "binary/octet-stream", &serving_block) ⇒ ByteRangeBody
Returns a new instance of ByteRangeBody.
28
29
30
31
32
33
|
# File 'lib/serve_byte_range.rb', line 28
def initialize(http_range:, resource_size:, resource_content_type: "binary/octet-stream", &serving_block)
@http_range = http_range
@resource_size = resource_size
@resource_content_type = resource_content_type
@serving_block = serving_block
end
|
Instance Method Details
#content_length ⇒ Object
45
46
47
|
# File 'lib/serve_byte_range.rb', line 45
def content_length
@http_range.size
end
|
#content_type ⇒ Object
49
50
51
|
# File 'lib/serve_byte_range.rb', line 49
def content_type
@resource_content_type
end
|
#each(&blk) ⇒ Object
39
40
41
42
43
|
# File 'lib/serve_byte_range.rb', line 39
def each(&blk)
writable_for_range_bytes = BlockWritableWithLimit.new(@http_range.size, &blk)
@serving_block.call(@http_range, writable_for_range_bytes)
writable_for_range_bytes.verify!
end
|
53
54
55
56
57
58
59
60
|
# File 'lib/serve_byte_range.rb', line 53
def
{
"Accept-Ranges" => "bytes",
"Content-Length" => content_length.to_s,
"Content-Type" => content_type,
"Content-Range" => "bytes %d-%d/%d" % [@http_range.begin, @http_range.end, @resource_size]
}
end
|
#status ⇒ Object
35
36
37
|
# File 'lib/serve_byte_range.rb', line 35
def status
206
end
|