Class: Xlsxrb::Ooxml::ZipGenerator
- Inherits:
-
Object
- Object
- Xlsxrb::Ooxml::ZipGenerator
- Defined in:
- lib/xlsxrb/ooxml/zip_generator.rb
Overview
Generates a simple ZIP file using only the standard library.
Instance Method Summary collapse
-
#add_entry(filepath, content) ⇒ Object
Adds an entry to the ZIP archive.
-
#generate ⇒ Object
Generates the ZIP file.
-
#initialize(filepath) ⇒ ZipGenerator
constructor
A new instance of ZipGenerator.
Constructor Details
#initialize(filepath) ⇒ ZipGenerator
Returns a new instance of ZipGenerator.
9 10 11 12 13 |
# File 'lib/xlsxrb/ooxml/zip_generator.rb', line 9 def initialize(filepath) @filepath = filepath @entries = [] @file = nil end |
Instance Method Details
#add_entry(filepath, content) ⇒ Object
Adds an entry to the ZIP archive.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/xlsxrb/ooxml/zip_generator.rb', line 16 def add_entry(filepath, content) compressed_data = compress(content) @entries << { path: filepath, content: content, compressed_data: compressed_data, crc32: crc32(content), uncompressed_size: content.bytesize, compressed_size: compressed_data.bytesize, mtime: Time.now } end |
#generate ⇒ Object
Generates the ZIP file.
30 31 32 33 34 35 36 |
# File 'lib/xlsxrb/ooxml/zip_generator.rb', line 30 def generate File.open(@filepath, "wb") do |f| @file = f write_entries write_central_directory end end |