Module: Decidim::ZipStream::Writer

Included in:
DownloadYourDataExporter
Defined in:
decidim-core/app/services/decidim/zip_stream/writer.rb

Instance Method Summary collapse

Instance Method Details

#add_attachments_to_zip_stream(out, export_attachments) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'decidim-core/app/services/decidim/zip_stream/writer.rb', line 19

def add_attachments_to_zip_stream(out, export_attachments)
  export_attachments.each do |attachment_block|
    next if attachment_block.last.nil?

    folder_name = attachment_block.first.parameterize
    attachment_block.last.each do |attachment|
      next unless attachment.attached?

      blobs = attachment.is_a?(ActiveStorage::Attached::One) ? [attachment.blob] : attachment.blobs
      blobs.each do |blob|
        out.put_next_entry("#{folder_name}/#{blob.filename}")
        blob.open do |f|
          out << f.read
        end
      end
    end
  end
end

#add_user_data_to_zip_stream(out, user_data) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'decidim-core/app/services/decidim/zip_stream/writer.rb', line 6

def add_user_data_to_zip_stream(out, user_data)
  user_data.each do |element|
    filename_file = element.last.filename(element.first.parameterize)

    out.put_next_entry(filename_file)
    if element.last.read.presence
      out.write element.last.read
    else
      out.write "No data"
    end
  end
end