How can I generate zip file without saving to the disk with Ruby?

后端 未结 5 1332
既然无缘
既然无缘 2020-12-05 06:41

I have generated many PDF files in memory and I want to compress them into one zip file before sending it as a email attachment. I have looked at Rubyzip and it does not all

5条回答
  •  醉梦人生
    2020-12-05 07:21

    Ruby comes with a very convenient StringIO library - this can be used for using a String as output IO object or faking reading a file backed by a String.

    The challenge here is that RubyZip does not support directly taking an IO object when creating a Zip::ZipOutputStream, but if you look at the implementation of the initialize, and depending on your willingness to experiment, you may be able to extend the class and allow it to take either an IO object or a file name in the constructor.

提交回复
热议问题