xsv 0.3.6 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c6b42a947e6f518a9284de8262e1c1327267a6e1fdd55ea6d14fffba1f1b19d
4
- data.tar.gz: '04887e8c4e50d3bb5762c6738237442d3b6360f4b96304b5a802215d7f4240ca'
3
+ metadata.gz: f5a4e91e03098400d7c83734fe68128418de719c3c9c0dc95e2e31e5beca9f90
4
+ data.tar.gz: 78488c6161efcec8e503403b35181b7efe827fb8a67cf8f579d06b444dc50a8f
5
5
  SHA512:
6
- metadata.gz: e8ad674f6735a1711190469836f30911bb2ebce502d3e99bc268c1c439c7cf9b8f6841189c76950c1722a0861a769a00b6ee7f15e5ab1cb2763a3d6b05342057
7
- data.tar.gz: 07c01bc46762348b87f745fd1c7b3aa9d16c0051916b46473a0c0c76bf4d1551f5d2cabc724a612069f3ce83eb959cbe06f4114bef361e615fc37b9ceae51193
6
+ metadata.gz: e43aa9c8ace8fee462cfaa09a8af785c7522c1ce31810523f5e4d498e3239b8c8e096ce11f638cb31561fc37ed0f7ce9d65d992dbaff23876c1f3fa68d9b44fb
7
+ data.tar.gz: 812911282e79f7737a27410b71bbe92fc941af181ae7e38c774ced448dcf88643a194e294f9b71862b8cb2eba41b01e0ee755fd4800bcae8ea4a025eefa78a9d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Xsv Changelog
2
2
 
3
+ ## 0.3.7 - 2020-03-05
4
+
5
+ Reduce retained memory, making Xsv the definite performance king among the
6
+ Ruby Excel parsing gems.
7
+
8
+ ## 0.3.6 - 2020-03-05
9
+
10
+ Reduce memory usage
11
+
3
12
  ## 0.3.5 - 2020-03-02
4
13
 
5
14
  Fix a Gemfile small Gemfile issue that broke the 0.3.3 and 0.3.4 releases
data/lib/xsv/sheet.rb CHANGED
@@ -28,10 +28,12 @@ module Xsv
28
28
  # There is no need to create Sheets from application code.
29
29
  #
30
30
  # @param workbook [Workbook] The Workbook with shared data such as shared strings and styles
31
- # @param io [IO] A handle to an open worksheet XML file or a string with the XML contents
32
- def initialize(workbook, io)
31
+ # @param io [IO] A handle to an open worksheet XML file
32
+ # @param size [Number] size of the XML file
33
+ def initialize(workbook, io, size)
33
34
  @workbook = workbook
34
35
  @io = io
36
+ @size = size
35
37
  @headers = []
36
38
  @mode = :array
37
39
  @row_skip = 0
@@ -46,11 +48,19 @@ module Xsv
46
48
 
47
49
  # Iterate over rows, returning either hashes or arrays based on the current mode.
48
50
  def each_row(&block)
49
- @io.rewind if @io.respond_to?(:rewind)
51
+ @io.rewind
50
52
 
51
53
  handler = SheetRowsHandler.new(@mode, empty_row, @workbook, @row_skip, @last_row, &block)
52
54
 
53
- Ox.sax_parse(handler, @io)
55
+ # For smaller sheets, memory performance is a lot better if Ox is
56
+ # handed a string. For larger sheets this leads to awful performance.
57
+ # This is probably caused by either something in SheetRowsHandler or
58
+ # the interaction between Zip::InputStream and Ox
59
+ if @size > 100_000_000
60
+ Ox.sax_parse(handler, @io)
61
+ else
62
+ Ox.sax_parse(handler, @io.read)
63
+ end
54
64
 
55
65
  true
56
66
  end
@@ -17,8 +17,8 @@ module Xsv
17
17
  return rows, cols
18
18
  end
19
19
 
20
- sheet.rewind if sheet.respond_to?(:rewind)
21
- Ox.sax_parse(handler, sheet)
20
+ sheet.rewind
21
+ Ox.sax_parse(handler, sheet.read)
22
22
 
23
23
  return rows, cols
24
24
  end
data/lib/xsv/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Xsv
3
- VERSION = "0.3.6"
3
+ VERSION = "0.3.7"
4
4
  end
data/lib/xsv/workbook.rb CHANGED
@@ -80,15 +80,7 @@ module Xsv
80
80
  @zip.glob("xl/worksheets/sheet*.xml").sort do |a, b|
81
81
  a.name[/\d+/].to_i <=> b.name[/\d+/].to_i
82
82
  end.each do |entry|
83
- # For smaller sheets, memory performance is a lot better if Ox is
84
- # handed a string. For larger sheets this leads to awful performance.
85
- # This is probably caused by either something in SheetRowsHandler or
86
- # the interaction between Zip::InputStream and Ox
87
- if entry.size > 100_000_000
88
- @sheets << Xsv::Sheet.new(self, entry.get_input_stream)
89
- else
90
- @sheets << Xsv::Sheet.new(self, entry.get_input_stream.read)
91
- end
83
+ @sheets << Xsv::Sheet.new(self, entry.get_input_stream, entry.size)
92
84
  end
93
85
  end
94
86
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xsv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martijn Storck