xlsxtream 0.3.0 → 0.3.1
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +3 -0
- data/lib/xlsxtream/io/hash.rb +46 -0
- data/lib/xlsxtream/version.rb +1 -1
- data/lib/xlsxtream/xml.rb +8 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3059ae91a1d37f8af53f001f209956b099020ffe
|
4
|
+
data.tar.gz: 14cdbda940cfd0f71cb426c1c646b4434dddff7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5894ce04ab5f8720e2da65e09de45a5d20b8c4df0f260e94cf2db1ec025b05832e69e8dce6edf1d6a9a938ea089408063dacf026f9185992a24c8e69a73847a5
|
7
|
+
data.tar.gz: 762faa3c9c0b2c29aacf150ed1610ae6af0badd373f770d33f348ac3bbd9dceaa98cbf98ff6ee35b6422fc554cbce4eb7729deb3887a392989c38b73be6bc10f
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Xlsxtream
|
2
2
|
|
3
|
+
[](https://rubygems.org/gems/xlsxtream)
|
4
|
+
[](https://travis-ci.org/felixbuenemann/xlsxtream)
|
5
|
+
|
3
6
|
Xlsxtream is a streaming writer for XLSX spreadsheets. It supports multiple worksheets and optional string
|
4
7
|
deduplication via a shared string table (SST). Its purpose is to replace CSV for large exports, because using
|
5
8
|
CSV in Excel is very buggy and error prone. It's very efficient and can quickly write millions of rows with
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Xlsxtream
|
2
|
+
module IO
|
3
|
+
class Hash
|
4
|
+
def initialize(stream)
|
5
|
+
@stream = stream
|
6
|
+
@hash = {}
|
7
|
+
@path = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def <<(data)
|
11
|
+
@stream << data
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_file(path)
|
15
|
+
close
|
16
|
+
@path = path
|
17
|
+
@hash[@path] = [@stream.tell]
|
18
|
+
end
|
19
|
+
|
20
|
+
def close
|
21
|
+
@hash[@path] << @stream.tell if @path
|
22
|
+
end
|
23
|
+
|
24
|
+
def fetch(path)
|
25
|
+
old = @stream.tell
|
26
|
+
from, to = @hash.fetch(path)
|
27
|
+
size = to - from
|
28
|
+
@stream.seek(from)
|
29
|
+
data = @stream.read(size)
|
30
|
+
@stream.seek(old)
|
31
|
+
data
|
32
|
+
end
|
33
|
+
|
34
|
+
def [](path)
|
35
|
+
fetch(path)
|
36
|
+
rescue KeyError
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_h
|
41
|
+
@hash.keys.map {|path| [path, fetch(path)] }.to_h
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
data/lib/xlsxtream/version.rb
CHANGED
data/lib/xlsxtream/xml.rb
CHANGED
@@ -14,6 +14,13 @@ module Xlsxtream
|
|
14
14
|
UNSAFE_ATTR_CHARS = /[&"<>]/.freeze
|
15
15
|
UNSAFE_VALUE_CHARS = /[&<>]/.freeze
|
16
16
|
|
17
|
+
# http://www.w3.org/TR/REC-xml/#NT-Char:
|
18
|
+
# Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
|
19
|
+
INVALID_XML10_CHARS = /[^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u10000-\u10FFFF]/.freeze
|
20
|
+
|
21
|
+
# ST_Xstring escaping
|
22
|
+
ESCAPE_CHAR = lambda { |c| '_x%04X_'.freeze % c.ord }.freeze
|
23
|
+
|
17
24
|
class << self
|
18
25
|
|
19
26
|
def header
|
@@ -29,7 +36,7 @@ module Xlsxtream
|
|
29
36
|
end
|
30
37
|
|
31
38
|
def escape_value(string)
|
32
|
-
string.gsub(UNSAFE_VALUE_CHARS, XML_ESCAPES)
|
39
|
+
string.gsub(UNSAFE_VALUE_CHARS, XML_ESCAPES).gsub(INVALID_XML10_CHARS, &ESCAPE_CHAR)
|
33
40
|
end
|
34
41
|
|
35
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xlsxtream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felix Bünemann
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- bin/setup
|
100
100
|
- lib/xlsxtream.rb
|
101
101
|
- lib/xlsxtream/io/directory.rb
|
102
|
+
- lib/xlsxtream/io/hash.rb
|
102
103
|
- lib/xlsxtream/io/rubyzip.rb
|
103
104
|
- lib/xlsxtream/io/stream.rb
|
104
105
|
- lib/xlsxtream/row.rb
|