Sha256: 2d25abbf02e9015c857834accedd51e8dbcff27311028093592b530f0ba9ba84

Contents?: true

Size: 790 Bytes

Versions: 135

Compression:

Stored size: 790 Bytes

Contents

# frozen_string_literal: true

require "zip"

module Decidim
  # This class performs a simple task: Zipping a single file. Originally
  # meant for mailers to attach files, but other usage can be found.
  class FileZipper
    # Public: Initializes the zipper with a filename and the data to
    # be zipped.
    #
    # filename - The file name of the file *inside* the zip.
    # data     - A string with the data to be zipped.
    def initialize(filename, data)
      @data = data
      @filename = filename
    end

    # Public: Zips the file.
    #
    # Returns a String with the zipped version of the file.
    def zip
      @zip ||= Zip::OutputStream.write_buffer do |zipfile|
        zipfile.put_next_entry(@filename)
        zipfile.write @data
      end.string
    end
  end
end

Version data entries

135 entries across 135 versions & 2 rubygems

Version Path
decidim-core-0.29.1 lib/decidim/file_zipper.rb
decidim-core-0.28.4 lib/decidim/file_zipper.rb
decidim-core-0.27.9 lib/decidim/file_zipper.rb
decidim-core-0.29.0 lib/decidim/file_zipper.rb
decidim-core-0.28.3 lib/decidim/file_zipper.rb
decidim-core-0.27.8 lib/decidim/file_zipper.rb
decidim-core-0.29.0.rc4 lib/decidim/file_zipper.rb
decidim-core-0.29.0.rc3 lib/decidim/file_zipper.rb
decidim-core-0.29.0.rc2 lib/decidim/file_zipper.rb
decidim-core-0.29.0.rc1 lib/decidim/file_zipper.rb
decidim-core-0.28.2 lib/decidim/file_zipper.rb
decidim-core-0.27.7 lib/decidim/file_zipper.rb
decidim-core-0.28.1 lib/decidim/file_zipper.rb
decidim-core-0.27.6 lib/decidim/file_zipper.rb
decidim-core-0.26.10 lib/decidim/file_zipper.rb
decidim-core-0.26.9 lib/decidim/file_zipper.rb
decidim-core-0.28.0 lib/decidim/file_zipper.rb
decidim-core-0.27.5 lib/decidim/file_zipper.rb
decidim-core-0.28.0.rc5 lib/decidim/file_zipper.rb
decidim-core-0.28.0.rc4 lib/decidim/file_zipper.rb