Class: IntervalResponse::Full

Inherits:
Object
  • Object
show all
Includes:
ToRackResponseTriplet
Defined in:
lib/interval_response/full.rb

Overview

Serves out a response that contains the entire resource

Constant Summary

Constants included from ToRackResponseTriplet

ToRackResponseTriplet::CHUNK_SIZE

Instance Method Summary collapse

Methods included from ToRackResponseTriplet

#to_rack_response_triplet

Constructor Details

#initialize(interval_map) ⇒ Full

Returns a new instance of Full.



5
6
7
# File 'lib/interval_response/full.rb', line 5

def initialize(interval_map, *)
  @interval_map = interval_map
end

Instance Method Details

#content_lengthObject



21
22
23
# File 'lib/interval_response/full.rb', line 21

def content_length
  @interval_map.size
end

#eachObject



9
10
11
12
13
14
15
# File 'lib/interval_response/full.rb', line 9

def each
  # serve the part of the interval map
  full_range = 0..(@interval_map.size - 1)
  @interval_map.each_in_range(full_range) do |segment, range_in_segment|
    yield(segment, range_in_segment)
  end
end

#headersObject



25
26
27
28
29
30
31
32
# File 'lib/interval_response/full.rb', line 25

def headers
  {
    'Accept-Ranges' => 'bytes',
    'Content-Length' => @interval_map.size.to_s,
    'Content-Type' => 'binary/octet-stream',
    'ETag' => @interval_map.etag,
  }
end

#status_codeObject



17
18
19
# File 'lib/interval_response/full.rb', line 17

def status_code
  200
end