Class: Pageflow::EntryExportImport::ZipArchive

Inherits:
Object
  • Object
show all
Defined in:
lib/pageflow/entry_export_import/zip_archive.rb

Overview

Read and write files from and to zip archives

Instance Method Summary collapse

Constructor Details

#initialize(file_name) ⇒ ZipArchive

Returns a new instance of ZipArchive.



7
8
9
10
11
12
# File 'lib/pageflow/entry_export_import/zip_archive.rb', line 7

def initialize(file_name)
  Zip.force_entry_names_encoding = 'UTF-8'
  Zip.write_zip64_support = true

  @file = Zip::File.open(file_name, Zip::File::CREATE)
end

Instance Method Details

#add(path, stream) ⇒ Object



22
23
24
# File 'lib/pageflow/entry_export_import/zip_archive.rb', line 22

def add(path, stream)
  @file.get_output_stream(path) { |f| IO.copy_stream(stream, f) }
end

#closeObject



34
35
36
# File 'lib/pageflow/entry_export_import/zip_archive.rb', line 34

def close
  @file.close
end

#extract_to_tempfile(path) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/pageflow/entry_export_import/zip_archive.rb', line 26

def extract_to_tempfile(path)
  Tempfile.open do |f|
    IO.copy_stream(@file.get_input_stream(path), f)
    f.rewind
    yield f
  end
end

#glob(pattern) ⇒ Object



18
19
20
# File 'lib/pageflow/entry_export_import/zip_archive.rb', line 18

def glob(pattern)
  @file.glob(pattern).map(&:name)
end

#include?(path) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/pageflow/entry_export_import/zip_archive.rb', line 14

def include?(path)
  @file.find_entry(path).present?
end