-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZipTricks 5.x -> ZipKit 6.x (new gem name, same API)
- Loading branch information
Andrew Hodgkinson
committed
Jan 7, 2025
1 parent
2cae416
commit 9d09578
Showing
4 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters