Rails: on-the-fly streaming of output in zip format? -
i need serve data database in zip file, streaming on fly such that:
- i not write temporary file disk
- i not compose whole file in ram
i know can streaming generation of zip files filesystemk using zipoutputstream
here. know can streaming output rails controller setting response_body
proc
here. need (i think) way of plugging 2 things together. can make rails serve response zipoutputstream
? can zipoutputstream
give me incremental chunks of data can feed response_body
proc
? or there way?
i had similar issue. didn't need stream directly, had first case of not wanting write temp file. can modify zipoutputstream accept io object instead of filename.
module zip class iooutputstream < zipoutputstream def initialize io super '-' @outputstream = io end def stream @outputstream end end end
from there, should matter of using new zip::iooutputstream in proc. in controller, you'd like:
self.response_body = proc |response, output| zip::iooutputstream.open(output) |zip| my_files.each |file| zip.put_next_entry file zip << io.read file end end end
Comments
Post a Comment