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.13.0 lib/decidim/file_zipper.rb
decidim-core-0.12.1 lib/decidim/file_zipper.rb
decidim-core-0.13.0.pre1 lib/decidim/file_zipper.rb
decidim-core-0.12.0 lib/decidim/file_zipper.rb
decidim-core-0.11.2 lib/decidim/file_zipper.rb
decidim-core-0.12.0.pre lib/decidim/file_zipper.rb
decidim-core-0.11.1 lib/decidim/file_zipper.rb
decidim-core-0.11.0.pre1 lib/decidim/file_zipper.rb
decidim-core-0.10.1 lib/decidim/file_zipper.rb
decidim-core-0.10.0 lib/decidim/file_zipper.rb
decidim-core-0.9.3 lib/decidim/file_zipper.rb
decidim-core-0.9.2 lib/decidim/file_zipper.rb
decidim-core-0.9.1 lib/decidim/file_zipper.rb
decidim-core-0.9.0 lib/decidim/file_zipper.rb
decidim-core-0.8.4 lib/decidim/file_zipper.rb
decidim-core-0.8.3 lib/decidim/file_zipper.rb
decidim-core-0.8.2 lib/decidim/file_zipper.rb
decidim-core-0.8.1 lib/decidim/file_zipper.rb
decidim-core-0.8.0 lib/decidim/file_zipper.rb
decidim-core-0.7.4 lib/decidim/file_zipper.rb