Class: Axlsx::ZipCommand
- Inherits:
-
Object
- Object
- Axlsx::ZipCommand
- Defined in:
- lib/axlsx/util/zip_command.rb
Overview
The ZipCommand class supports zipping the Excel file contents using
a binary zip program instead of RubyZip's Zip::OutputStream
.
The methods provided here mimic Zip::OutputStream
so that ZipCommand
can
be used as a drop-in replacement. Note that method signatures are not
identical to Zip::OutputStream
, they are only sufficiently close so that
ZipCommand
and Zip::OutputStream
can be interchangeably used within
caxlsx
.
Defined Under Namespace
Classes: ZipError
Instance Method Summary collapse
-
#initialize(zip_command) ⇒ ZipCommand
constructor
A new instance of ZipCommand.
-
#open(output) ⇒ Object
Create a temporary directory for writing files to.
-
#put_next_entry(entry) ⇒ Object
Closes the current entry and opens a new for writing.
-
#write(content) ⇒ Object
(also: #<<)
Write to a buffer that will be written to the current entry.
Constructor Details
#initialize(zip_command) ⇒ ZipCommand
Returns a new instance of ZipCommand.
19 20 21 22 23 |
# File 'lib/axlsx/util/zip_command.rb', line 19 def initialize(zip_command) @current_file = nil @files = [] @zip_command = zip_command end |
Instance Method Details
#open(output) ⇒ Object
Create a temporary directory for writing files to.
The directory and its contents are removed at the end of the block.
28 29 30 31 32 33 34 35 |
# File 'lib/axlsx/util/zip_command.rb', line 28 def open(output) Dir.mktmpdir do |dir| @dir = dir yield(self) write_file zip_parts(output) end end |
#put_next_entry(entry) ⇒ Object
Closes the current entry and opens a new for writing.
38 39 40 41 42 43 44 |
# File 'lib/axlsx/util/zip_command.rb', line 38 def put_next_entry(entry) write_file @current_file = "#{@dir}/#{entry.name}" @files << entry.name FileUtils.mkdir_p(File.dirname(@current_file)) @io = File.open(@current_file, "wb") end |
#write(content) ⇒ Object Also known as: <<
Write to a buffer that will be written to the current entry
47 48 49 |
# File 'lib/axlsx/util/zip_command.rb', line 47 def write(content) @io << content end |