Chunk videoplayback response to avoid throttling

This commit is contained in:
Omar Roth 2019-06-26 14:43:33 -05:00
parent b31d1c06f5
commit 818cd2454d
No known key found for this signature in database
GPG key ID: B8254FB7EC3D37F2
3 changed files with 66 additions and 30 deletions

View file

@ -656,7 +656,7 @@ def proxy_file(response, env)
end
# https://stackoverflow.com/a/44802810 <3
def copy_in_chunks(input, output, chunk_size = 4096)
def copy_in_chunks(input, output, chunk_size = 8192)
size = 1
while size > 0
size = IO.copy(input, output, chunk_size)

View file

@ -358,3 +358,21 @@ def subscribe_pubsub(topic, key, config)
return client.post("/subscribe", form: body)
end
def parse_range(range)
if !range
return 0, nil
end
ranges = range.lchop("bytes=").split(',')
ranges.each do |range|
start_range, end_range = range.split('-')
start_range = start_range.to_i? || 0
end_range = end_range.to_i?.try &.+ 1
return start_range, end_range
end
return 0, nil
end