From e7673f431813cde7aab2d032a4417d4ddeeb9342 Mon Sep 17 00:00:00 2001 From: Ryan Winograd Date: Thu, 13 Aug 2020 21:05:59 -0500 Subject: Add option to `#serialize` with system zip command Add a `:zip_command` option to `Axlsx::Package#serialize` that allows the user to specify an alternate command to use to perform the zip operation on the XLSX file contents. The default zip operation is provided by RubyZip. On large documents users may experience faster zip times using a zip binary. Resolves #55 --- test/tc_package.rb | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/tc_package.rb b/test/tc_package.rb index 23078862..18c08f5c 100644 --- a/test/tc_package.rb +++ b/test/tc_package.rb @@ -128,11 +128,34 @@ class TestPackage < Test::Unit::TestCase def test_serialization @package.serialize(@fname) - zf = Zip::File.open(@fname) - @package.send(:parts).each{ |part| zf.get_entry(part[:entry]) } + assert_zip_file_matches_package(@fname, @package) File.delete(@fname) end + def test_serialization_with_zip_command + @package.serialize(@fname, false, zip_command: "zip") + assert_zip_file_matches_package(@fname, @package) + File.delete(@fname) + end + + def test_serialization_with_zip_command_and_absolute_path + fname = "#{Dir.tmpdir}/#{@fname}" + @package.serialize(fname, false, zip_command: "zip") + assert_zip_file_matches_package(fname, @package) + File.delete(fname) + end + + def test_serialization_with_invalid_zip_command + assert_raises Axlsx::ZipCommand::ZipError do + @package.serialize(@fname, false, zip_command: "invalid_zip") + end + end + + def assert_zip_file_matches_package(fname, package) + zf = Zip::File.open(fname) + package.send(:parts).each{ |part| zf.get_entry(part[:entry]) } + end + # See comment for Package#zip_entry_for_part def test_serialization_creates_identical_files_at_any_time_if_created_at_is_set @package.core.created = Time.now -- cgit v1.2.3