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.20.1 lib/decidim/file_zipper.rb
decidim-core-0.20.0 lib/decidim/file_zipper.rb
decidim-core-0.19.1 lib/decidim/file_zipper.rb
decidim-core-0.18.1 lib/decidim/file_zipper.rb
decidim-core-0.19.0 lib/decidim/file_zipper.rb
decidim-core-0.17.2 lib/decidim/file_zipper.rb
decidim-core-0.18.0 lib/decidim/file_zipper.rb
decidim-core-0.17.1 lib/decidim/file_zipper.rb
decidim-core-0.16.1 lib/decidim/file_zipper.rb
decidim-core-0.17.0 lib/decidim/file_zipper.rb
decidim-core-0.16.0 lib/decidim/file_zipper.rb
decidim-core-0.15.2 lib/decidim/file_zipper.rb
decidim-core-0.15.1 lib/decidim/file_zipper.rb
decidim-core-0.15.0 lib/decidim/file_zipper.rb
decidim-core-0.14.4 lib/decidim/file_zipper.rb
decidim-core-0.14.3 lib/decidim/file_zipper.rb
decidim-core-0.14.2 lib/decidim/file_zipper.rb
decidim-core-0.14.1 lib/decidim/file_zipper.rb
decidim-core-0.13.1 lib/decidim/file_zipper.rb
decidim-core-0.12.2 lib/decidim/file_zipper.rb