chupa-text 1.1.6 → 1.1.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 +4 -4
- data/doc/text/news.md +8 -0
- data/lib/chupa-text/data.rb +9 -4
- data/lib/chupa-text/decomposers/gzip.rb +11 -10
- data/lib/chupa-text/decomposers/tar.rb +13 -5
- data/lib/chupa-text/decomposers/zip.rb +16 -7
- data/lib/chupa-text/file-content.rb +10 -2
- data/lib/chupa-text/version.rb +1 -1
- data/lib/chupa-text/virtual-content.rb +10 -3
- data/lib/chupa-text/virtual-file-data.rb +5 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8e70028837d0c6abebb4d01432f3467e8c5dd42129b9dffa3dd16a939594894
|
4
|
+
data.tar.gz: 4a445af645995552c82e8339f1fd2d5f71dd8a47be669ee674ede6e635585c4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1052a2c7148c1bc184633b1ed365f422584bcdb4bc1952534e24f2ebf1445a0f286cdf4d47241a7aeefcfce80e4bdfb7c5bf6e9e74fba30a5a1f8d333fde62b3
|
7
|
+
data.tar.gz: c2b355f73f09004214037069ffbdeafddd4e786c2e2498a905c9b651947f7508d1fc268052404e37297d2e816b7e115fa35ef959e98f22369f1e355220138b91
|
data/doc/text/news.md
CHANGED
data/lib/chupa-text/data.rb
CHANGED
@@ -140,6 +140,10 @@ module ChupaText
|
|
140
140
|
yield(StringIO.new(body))
|
141
141
|
end
|
142
142
|
|
143
|
+
def peek_body(size)
|
144
|
+
body[0, size]
|
145
|
+
end
|
146
|
+
|
143
147
|
def [](name)
|
144
148
|
@attributes[name]
|
145
149
|
end
|
@@ -216,10 +220,11 @@ module ChupaText
|
|
216
220
|
|
217
221
|
def guess_mime_type_from_body
|
218
222
|
mime_type = nil
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
+
chunk = peek_body(1024)
|
224
|
+
change_encoding(chunk, "UTF-8") do |utf8_chunk|
|
225
|
+
return nil unless utf8_chunk.valid_encoding?
|
226
|
+
n_null_characters = utf8_chunk.count("\u0000")
|
227
|
+
return nil if n_null_characters > (utf8_chunk.bytesize * 0.01)
|
223
228
|
mime_type = "text/plain"
|
224
229
|
end
|
225
230
|
mime_type
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
|
1
|
+
# Copyright (C) 2013-2019 Kouhei Sutou <kou@clear-code.com>
|
2
2
|
#
|
3
3
|
# This library is free software; you can redistribute it and/or
|
4
4
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -14,7 +14,6 @@
|
|
14
14
|
# License along with this library; if not, write to the Free Software
|
15
15
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
16
|
|
17
|
-
require "stringio"
|
18
17
|
require "zlib"
|
19
18
|
|
20
19
|
module ChupaText
|
@@ -34,16 +33,18 @@ module ChupaText
|
|
34
33
|
end
|
35
34
|
|
36
35
|
def decompose(data)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
data.open do |input|
|
37
|
+
reader = Zlib::GzipReader.new(input)
|
38
|
+
uri = nil
|
39
|
+
case data.extension
|
40
|
+
when "gz"
|
41
41
|
uri = data.uri.to_s.gsub(/\.gz\z/i, "")
|
42
|
-
|
43
|
-
|
42
|
+
when "tgz"
|
43
|
+
uri = data.uri.to_s.gsub(/\.tgz\z/i, ".tar")
|
44
|
+
end
|
45
|
+
extracted = VirtualFileData.new(uri, reader, :source_data => data)
|
46
|
+
yield(extracted)
|
44
47
|
end
|
45
|
-
extracted = VirtualFileData.new(uri, reader, :source_data => data)
|
46
|
-
yield(extracted)
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
@@ -14,7 +14,6 @@
|
|
14
14
|
# License along with this library; if not, write to the Free Software
|
15
15
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
16
|
|
17
|
-
require "stringio"
|
18
17
|
require "rubygems/package"
|
19
18
|
|
20
19
|
require "chupa-text/path-converter"
|
@@ -41,10 +40,19 @@ module ChupaText
|
|
41
40
|
path_converter = PathConverter.new(entry.full_name,
|
42
41
|
uri_escape: true)
|
43
42
|
entry_uri.path = "#{base_path}/#{path_converter.convert}"
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
size = entry.header.size
|
44
|
+
if size < (32 * 1024)
|
45
|
+
entry_data = Data.new(source_data: data)
|
46
|
+
entry_data.uri = entry_uri
|
47
|
+
body = entry.read || ""
|
48
|
+
entry_data.body = body
|
49
|
+
entry_data.size = body.bytesize
|
50
|
+
else
|
51
|
+
entry_data = VirtualFileData.new(entry_uri,
|
52
|
+
entry,
|
53
|
+
:source_data => data)
|
54
|
+
end
|
55
|
+
yield(entry_data)
|
48
56
|
end
|
49
57
|
end
|
50
58
|
end
|
@@ -14,8 +14,6 @@
|
|
14
14
|
# License along with this library; if not, write to the Free Software
|
15
15
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
16
|
|
17
|
-
require "stringio"
|
18
|
-
|
19
17
|
require "archive/zip"
|
20
18
|
|
21
19
|
require "chupa-text/path-converter"
|
@@ -52,9 +50,18 @@ module ChupaText
|
|
52
50
|
encoding: base_path.encoding,
|
53
51
|
uri_escape: true)
|
54
52
|
entry_uri.path = "#{base_path}/#{path_converter.convert}"
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
size = entry.raw_data.window_size
|
54
|
+
if size < (8 * 1024)
|
55
|
+
entry_data = Data.new(source_data: data)
|
56
|
+
entry_data.uri = entry_uri
|
57
|
+
body = entry.file_data.read
|
58
|
+
entry_data.body = body
|
59
|
+
entry_data.size = body.bytesize
|
60
|
+
else
|
61
|
+
entry_data = VirtualFileData.new(entry_uri,
|
62
|
+
entry.file_data,
|
63
|
+
source_data: data)
|
64
|
+
end
|
58
65
|
yield(entry_data)
|
59
66
|
end
|
60
67
|
end
|
@@ -63,8 +70,10 @@ module ChupaText
|
|
63
70
|
private
|
64
71
|
def open_zip(data)
|
65
72
|
begin
|
66
|
-
|
67
|
-
|
73
|
+
data.open do |input|
|
74
|
+
Archive::Zip.open(input) do |zip|
|
75
|
+
yield(zip)
|
76
|
+
end
|
68
77
|
end
|
69
78
|
rescue Archive::Zip::Error => zip_error
|
70
79
|
error do
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
|
1
|
+
# Copyright (C) 2013-2019 Kouhei Sutou <kou@clear-code.com>
|
2
2
|
#
|
3
3
|
# This library is free software; you can redistribute it and/or
|
4
4
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -29,7 +29,15 @@ module ChupaText
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def body
|
32
|
-
|
32
|
+
open do |file|
|
33
|
+
file.read
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def peek_body(size)
|
38
|
+
open do |file|
|
39
|
+
file.read(size)
|
40
|
+
end
|
33
41
|
end
|
34
42
|
end
|
35
43
|
end
|
data/lib/chupa-text/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
|
1
|
+
# Copyright (C) 2013-2019 Kouhei Sutou <kou@clear-code.com>
|
2
2
|
#
|
3
3
|
# This library is free software; you can redistribute it and/or
|
4
4
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -34,7 +34,6 @@ module ChupaText
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
@original_path = original_path
|
37
|
-
@body = nil
|
38
37
|
setup_file do |file|
|
39
38
|
@size = IO.copy_stream(input, file)
|
40
39
|
end
|
@@ -45,7 +44,15 @@ module ChupaText
|
|
45
44
|
end
|
46
45
|
|
47
46
|
def body
|
48
|
-
|
47
|
+
open do |file|
|
48
|
+
file.read
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def peek_body(size)
|
53
|
+
open do |file|
|
54
|
+
file.read(size)
|
55
|
+
end
|
49
56
|
end
|
50
57
|
|
51
58
|
def path
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013-
|
1
|
+
# Copyright (C) 2013-2019 Kouhei Sutou <kou@clear-code.com>
|
2
2
|
#
|
3
3
|
# This library is free software; you can redistribute it and/or
|
4
4
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -27,6 +27,10 @@ module ChupaText
|
|
27
27
|
@content.body
|
28
28
|
end
|
29
29
|
|
30
|
+
def peek_body(size)
|
31
|
+
@content.peek_body(size)
|
32
|
+
end
|
33
|
+
|
30
34
|
def size
|
31
35
|
@content.size
|
32
36
|
end
|