github
3 of 3 new or added lines in 1 file covered. (100.0%)
3376 of 3438 relevant lines covered (98.2%)
50148.73 hits per line
| 1 |
# frozen_string_literal: true
|
|
| 2 |
|
|
| 3 |
module Grape |
44✔ |
| 4 |
module ServeStream |
44✔ |
| 5 |
CHUNK_SIZE = 16_384 |
44✔ |
| 6 |
|
|
| 7 |
# Class helps send file through API
|
|
| 8 |
class FileBody |
44✔ |
| 9 |
attr_reader :path
|
44✔ |
| 10 |
|
|
| 11 |
# @param path [String]
|
|
| 12 |
def initialize(path) |
44✔ |
| 13 |
@path = path
|
259✔ |
| 14 |
end
|
|
| 15 |
|
|
| 16 |
# Need for Rack::Sendfile middleware
|
|
| 17 |
#
|
|
| 18 |
# @return [String]
|
|
| 19 |
def to_path |
44✔ |
| 20 |
path |
37✔ |
| 21 |
end
|
|
| 22 |
|
|
| 23 |
def each |
44✔ |
| 24 |
File.open(path, 'rb') do |file| |
× |
| 25 |
while (chunk = file.read(CHUNK_SIZE)) |
× |
| 26 |
yield chunk
|
× |
| 27 |
end
|
|
| 28 |
end
|
|
| 29 |
end
|
|
| 30 |
|
|
| 31 |
def ==(other) |
44✔ |
| 32 |
path == other.path |
74✔ |
| 33 |
end
|
|
| 34 |
end
|
|
| 35 |
end
|
|
| 36 |
end
|