stream caas file in chunks
All checks were successful
Gitea Actions Demo / lint (push) Successful in 25s
Gitea Actions Demo / test (push) Successful in 13s
Gitea Actions Demo / release-image (push) Successful in 1m51s

This commit is contained in:
Ryan Cavicchioni 2025-03-10 23:31:14 -05:00
parent b247971b7e
commit 9869e98346
Signed by: ryanc
SSH Key Fingerprint: SHA256:KbXiwUnZnHFwFtt3Bytd+F3FN9pPHn1Z1cxMIE1TPbg

16
app.rb
View File

@ -20,6 +20,7 @@ $LOAD_PATH.unshift File.dirname(__FILE__) + "/lib"
require "config"
CHUNK_SIZE = 1024**2
SESSION_SECRET_HEX_LENGTH = 64
JWT_SECRET_HEX_LENGTH = 64
@ -506,7 +507,7 @@ get "/kitty" do
# fail-safe url
url = "https://i.imgur.com/epzPw7L.jpeg"
end
path = Tempfile.open binmode: true do |f|
tmp_file = Tempfile.open binmode: true do |f|
# f.chmod 0o644
response = HTTParty.get(url, stream_body: true) do |fragment|
if [301, 302].include? fragment.code
@ -519,8 +520,15 @@ get "/kitty" do
end
content_type response.headers["content-type"]
f.path
f
end
tmp_file.open do |f|
stream do |out|
out << f.read
until f.eof?
out << f.read(CHUNK_SIZE)
end
end
end
send_file path
File.delete path
end