Skip to content

Commit

Permalink
ZipTricks 5.x -> ZipKit 6.x (new gem name, same API)
Browse files Browse the repository at this point in the history
  • Loading branch information
pond committed Jul 10, 2024
1 parent 003242e commit 3188766
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 12 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.6.0 (2024-07-10)

- Move to [ZipKit gem](http://rubygems.org/gems/zip_kit); equivalent of https://github.com/felixbuenemann/xlsxtream/pull/57/files

## 2.5.0 (2021-06-28)

- New `:add_header_row` method in Worksheet, which outputs as a row as bold text, intended for header rows
Expand Down Expand Up @@ -27,11 +31,11 @@
## 2.0.1 (2018-03-11)

- Rescue gracefully from invalid dates with auto-format (#22)
- Remove unused ZipTricksFibers IO wrapper (#24)
- Remove unused ZipKitFibers IO wrapper (#24)

## 2.0.0 (2017-10-31)

- Replace RubyZip with ZipTricks as default compressor (#16)
- Replace RubyZip with ZipKit as default compressor (#16)
- Drop support for Ruby < 2.1.0 (required for zip\_tricks gem)
- Deprecate :io\_wrapper option, you can now pass wrapper instances (#20)

Expand Down
45 changes: 45 additions & 0 deletions lib/xlsxtream/io/zip_kit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true
require "zip_kit"

module Xlsxtream
module IO
class ZipKit
BUFFER_SIZE = 64 * 1024

def initialize(body)
@streamer = ::ZipKit::Streamer.new(body)
@wf = nil
@buffer = String.new
end

def <<(data)
@buffer << data
flush_buffer if @buffer.size >= BUFFER_SIZE
self
end

def add_file(path)
flush_file
@wf = @streamer.write_deflated_file(path)
end

def close
flush_file
@streamer.close
end

private

def flush_buffer
@wf << @buffer
@buffer.clear
end

def flush_file
return unless @wf
flush_buffer if @buffer.size > 0
@wf.close
end
end
end
end
6 changes: 3 additions & 3 deletions lib/xlsxtream/io/zip_tricks.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# frozen_string_literal: true
require "zip_tricks"
require "zip_kit"

module Xlsxtream
module IO
class ZipTricks
class ZipKit
BUFFER_SIZE = 64 * 1024

def initialize(body)
@streamer = ::ZipTricks::Streamer.new(body)
@streamer = ::ZipKit::Streamer.new(body)
@wf = nil
@buffer = String.new
end
Expand Down
6 changes: 3 additions & 3 deletions lib/xlsxtream/workbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "xlsxtream/xml"
require "xlsxtream/shared_string_table"
require "xlsxtream/worksheet"
require "xlsxtream/io/zip_tricks"
require "xlsxtream/io/zip_kit"

module Xlsxtream
class Workbook
Expand Down Expand Up @@ -46,13 +46,13 @@ def initialize(output, options = {})
end
if output.is_a?(String) || !output.respond_to?(:<<)
@file = File.open(output, 'wb')
@io = IO::ZipTricks.new(@file)
@io = IO::ZipKit.new(@file)
elsif output.respond_to? :add_file
@file = nil
@io = output
else
@file = nil
@io = IO::ZipTricks.new(output)
@io = IO::ZipKit.new(output)
end
@sst = SharedStringTable.new
@worksheets = []
Expand Down
6 changes: 3 additions & 3 deletions test/xlsxtream/io/zip_tricks_test.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# frozen_string_literal: true
require 'test_helper'
require 'xlsxtream/io/zip_tricks'
require 'xlsxtream/io/zip_kit'
require 'zip'

module Xlsxtream
class ZipTricksTest < Minitest::Test
class ZipKitTest < Minitest::Test

def test_writes_of_multiple_files
zip_buf = Tempfile.new('ztio-test')

io = Xlsxtream::IO::ZipTricks.new(zip_buf)
io = Xlsxtream::IO::ZipKit.new(zip_buf)
io.add_file("book1.xml")
io << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook />'
io.add_file("book2.xml")
Expand Down
2 changes: 1 addition & 1 deletion xlsxtream.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]
spec.required_ruby_version = ">= 2.1.0"

spec.add_dependency "zip_tricks", ">= 4.5", "< 6"
spec.add_dependency "zip_kit", ">= 6.0", "< 7"

spec.add_development_dependency "bundler", ">= 1.7", "< 3"
spec.add_development_dependency "rake"
Expand Down

0 comments on commit 3188766

Please sign in to comment.