Class: IntervalResponse::Multi
Constant Summary
collapse
- ALPHABET =
('0'..'9').to_a + ('a'..'z').to_a + ('A'..'Z').to_a
ToRackResponseTriplet::CHUNK_SIZE
Instance Method Summary
collapse
#to_rack_response_triplet
Constructor Details
#initialize(interval_map, http_ranges) ⇒ Multi
Returns a new instance of Multi.
8
9
10
11
12
13
14
15
16
|
# File 'lib/interval_response/multi.rb', line 8
def initialize(interval_map, http_ranges)
@interval_map = interval_map
@http_ranges = http_ranges
@boundary = SecureRandom.bytes(24).unpack("C*").map { |b| ALPHABET[b % ALPHABET.length] }.join
end
|
Instance Method Details
#content_length ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/interval_response/multi.rb', line 34
def content_length
@envelope_size ||= compute_envelope_size
end
|
#each ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/interval_response/multi.rb', line 18
def each
@http_ranges.each_with_index do |http_range, range_i|
= (range_i, http_range)
= 0..(.bytesize - 1)
yield(, )
@interval_map.each_in_range(http_range) do |segment, range_in_segment|
yield(segment, range_in_segment)
end
end
end
|
44
45
46
47
48
49
50
51
|
# File 'lib/interval_response/multi.rb', line 44
def
{
'Accept-Ranges' => 'bytes',
'Content-Length' => content_length.to_s,
'Content-Type' => "multipart/byte-ranges; boundary=#{@boundary}",
'ETag' => @interval_map.etag,
}
end
|
#status_code ⇒ Object
30
31
32
|
# File 'lib/interval_response/multi.rb', line 30
def status_code
206
end
|