xlsxtream 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d7ef18ac21a43cee29087458665fd3ff6511c62
4
- data.tar.gz: 03bf65a93162886fbfcdebefb89191ea29a09744
3
+ metadata.gz: 0dff3af0eeb78824d009e7428de38a1a9647a8f7
4
+ data.tar.gz: 52367aa07b8878102cb082742238c1e0050910a1
5
5
  SHA512:
6
- metadata.gz: '087c1ab2888d86144ce3872a5a74579b3d82eb07f672dd261b29c5513129a24eb81340b16fb0bb9f3e0843c39d7ae8d17e076bc2aff3b92ff569f617259e2351'
7
- data.tar.gz: dbc340a4f04e01e975886d5e94c939e2a6879bc754a632bd334895545bf982944b0c6053014ab0ddd8d383ac36ee677c118046cdeff21dd090df68dbbdb0d547
6
+ metadata.gz: 0fd9e15c00d665312806e857df5b6dc7a89f09a39dd5498c6a289a2c68d420ac05242491c33954ddce4cf4446acba85b9c0a7dc4202e710c9661dc81200a765f
7
+ data.tar.gz: c5e8e898cde5b8556f8395b05604519cebd681759ba85cd9d40d07d29b78f5cd8ee3960aa5db5b099783abf8230d6f24ec69c5ac7b650bb4874d436566a67c18
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.3.0 (2017-10-30)
4
+
5
+ - Drop rubyzip buffering workarounds, require rubyzip >= 1.2.0 (#17)
6
+ - Drop Ruby 1.9.1 compatibility (rubyzip 1.2 requires ruby >= 1.9.2)
7
+ - Refactor IO wrappers (#18)
8
+
3
9
  ## 1.2.0 (2017-10-30)
4
10
 
5
11
  - Add support for customizing default font (#17)
@@ -38,7 +38,7 @@ module Xlsxtream
38
38
  end
39
39
 
40
40
  def to_h
41
- @hash.keys.map {|path| [path, fetch(path)] }.to_h
41
+ ::Hash[@hash.keys.map {|path| [path, fetch(path)] }]
42
42
  end
43
43
  end
44
44
  end
@@ -1,12 +1,16 @@
1
1
  require "zip"
2
+ require "xlsxtream/errors"
2
3
 
3
4
  module Xlsxtream
4
5
  module IO
5
6
  class RubyZip
6
- def initialize(path_or_io)
7
- @stream = path_or_io.respond_to? :reopen
8
- path_or_io.binmode if path_or_io.respond_to? :binmode
9
- @zos = UnbufferedZipOutputStream.new(path_or_io, @stream)
7
+ def initialize(io)
8
+ unless io.respond_to? :pos and io.respond_to? :pos=
9
+ raise Error, 'IO is not seekable'
10
+ end
11
+ io.binmode if io.respond_to? :binmode
12
+ stream = true
13
+ @zos = Zip::OutputStream.new(io, stream)
10
14
  end
11
15
 
12
16
  def <<(data)
@@ -20,48 +24,6 @@ module Xlsxtream
20
24
  def close
21
25
  os = @zos.close_buffer
22
26
  os.flush if os.respond_to? :flush
23
- os.close if !@stream and os.respond_to? :close
24
- end
25
-
26
- # Extend get_compressor to hook our custom deflater.
27
- class UnbufferedZipOutputStream < ::Zip::OutputStream
28
- private
29
- def get_compressor(entry, level)
30
- case entry.compression_method
31
- when ::Zip::Entry::DEFLATED then
32
- StreamingDeflater.new(@output_stream, level, @encrypter)
33
- else
34
- super
35
- end
36
- end
37
- end
38
-
39
- # RubyZip's Deflater buffers to a StringIO until finish is called.
40
- # This StreamingDeflater writes out chunks during compression.
41
- class StreamingDeflater < ::Zip::Compressor
42
- def initialize(output_stream, level = Zip.default_compression, encrypter = NullEncrypter.new)
43
- super()
44
- @output_stream = output_stream
45
- @zlib_deflater = ::Zlib::Deflate.new(level, -::Zlib::MAX_WBITS)
46
- @size = 0
47
- @crc = ::Zlib.crc32
48
- unless encrypter.is_a? ::Zip::NullEncrypter
49
- raise ::Zip::Error, 'StreamingDeflater does not support encryption'
50
- end
51
- end
52
-
53
- def <<(data)
54
- val = data.to_s
55
- @crc = Zlib.crc32(val, @crc)
56
- @size += val.bytesize
57
- @output_stream << @zlib_deflater.deflate(data)
58
- end
59
-
60
- def finish
61
- @output_stream << @zlib_deflater.finish until @zlib_deflater.finished?
62
- end
63
-
64
- attr_reader :size, :crc
65
27
  end
66
28
  end
67
29
  end
@@ -1,3 +1,3 @@
1
1
  module Xlsxtream
2
- VERSION = '1.2.0'.freeze
2
+ VERSION = '1.3.0'.freeze
3
3
  end
@@ -1,12 +1,9 @@
1
1
  # encoding: utf-8
2
- require "stringio"
3
2
  require "xlsxtream/errors"
4
3
  require "xlsxtream/xml"
5
4
  require "xlsxtream/shared_string_table"
6
5
  require "xlsxtream/workbook"
7
6
  require "xlsxtream/io/rubyzip"
8
- require "xlsxtream/io/directory"
9
- require "xlsxtream/io/stream"
10
7
 
11
8
  module Xlsxtream
12
9
  class Workbook
@@ -22,8 +19,8 @@ module Xlsxtream
22
19
 
23
20
  class << self
24
21
 
25
- def open(data = nil, options = {})
26
- workbook = new(data, options)
22
+ def open(output = nil, options = {})
23
+ workbook = new(output, options)
27
24
  if block_given?
28
25
  begin
29
26
  yield workbook
@@ -37,10 +34,16 @@ module Xlsxtream
37
34
 
38
35
  end
39
36
 
40
- def initialize(data = nil, options = {})
37
+ def initialize(output = nil, options = {})
38
+ output ||= StringIO.new
41
39
  @options = options
42
40
  io_wrapper = options[:io_wrapper] || IO::RubyZip
43
- @io = io_wrapper.new(data || StringIO.new)
41
+ if output.is_a?(String) || !output.respond_to?(:<<)
42
+ @file = File.open(output, 'wb')
43
+ @io = io_wrapper.new(@file)
44
+ else
45
+ @io = io_wrapper.new(output)
46
+ end
44
47
  @sst = SharedStringTable.new
45
48
  @worksheets = Hash.new { |hash, name| hash[name] = hash.size + 1 }
46
49
  end
@@ -74,6 +77,7 @@ module Xlsxtream
74
77
  write_root_rels
75
78
  write_content_types
76
79
  @io.close
80
+ @file.close if @file
77
81
  nil
78
82
  end
79
83
 
data/xlsxtream.gemspec CHANGED
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.bindir = "exe"
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
- spec.required_ruby_version = '>= 1.9.1'
21
+ spec.required_ruby_version = '>= 1.9.2'
22
22
 
23
- spec.add_dependency "rubyzip", ">= 1.0.0"
23
+ spec.add_dependency "rubyzip", ">= 1.2.0"
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.7"
26
26
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xlsxtream
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Bünemann
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.0
19
+ version: 1.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.0
26
+ version: 1.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -122,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
122
  requirements:
123
123
  - - ">="
124
124
  - !ruby/object:Gem::Version
125
- version: 1.9.1
125
+ version: 1.9.2
126
126
  required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  requirements:
128
128
  - - ">="