chupa-text 1.1.6 → 1.1.7

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
  SHA256:
3
- metadata.gz: 8a248b3b82aeb4ce65bd7b498dc2aab9ad6e43e6d5ea70a304163362c3e723e7
4
- data.tar.gz: 82f3f02b63235924cab8608f1fde8d4ecbe4cb0e1aa92f12bf9ecff1debab21d
3
+ metadata.gz: a8e70028837d0c6abebb4d01432f3467e8c5dd42129b9dffa3dd16a939594894
4
+ data.tar.gz: 4a445af645995552c82e8339f1fd2d5f71dd8a47be669ee674ede6e635585c4f
5
5
  SHA512:
6
- metadata.gz: f2c3acee194db640b3b3e01a913cfc00727ed7b8e0e4b353f5fbb2d1723f689846164d44f2ffcf1874b2948ec3f3b578dacd49d27934693ad71f24b9901373a2
7
- data.tar.gz: 12bd3c5ed94f85bad888e56a62ef478a606e8ce5fe8f376f7c2418924ef91094b1a6c150c60fd80278a7541bb5e177b7d9cb4b7ec5b67a482b8ff74c67953ba2
6
+ metadata.gz: 1052a2c7148c1bc184633b1ed365f422584bcdb4bc1952534e24f2ebf1445a0f286cdf4d47241a7aeefcfce80e4bdfb7c5bf6e9e74fba30a5a1f8d333fde62b3
7
+ data.tar.gz: c2b355f73f09004214037069ffbdeafddd4e786c2e2498a905c9b651947f7508d1fc268052404e37297d2e816b7e115fa35ef959e98f22369f1e355220138b91
data/doc/text/news.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # News
2
2
 
3
+ ## 1.1.7: 2019-03-01
4
+
5
+ ### Improvements
6
+
7
+ * Reduced memory usage.
8
+
9
+ * Reduced IO.
10
+
3
11
  ## 1.1.6: 2019-03-01
4
12
 
5
13
  ### Improvements
@@ -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
- change_encoding(body, "UTF-8") do |utf8_body|
220
- return nil unless utf8_body.valid_encoding?
221
- n_null_characters = utf8_body.count("\u0000")
222
- return nil if n_null_characters > (utf8_body.bytesize * 0.01)
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
- reader = Zlib::GzipReader.new(StringIO.new(data.body))
38
- uri = nil
39
- case data.extension
40
- when "gz"
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
- when "tgz"
43
- uri = data.uri.to_s.gsub(/\.tgz\z/i, ".tar")
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
- extracted = VirtualFileData.new(entry_uri,
45
- entry,
46
- :source_data => data)
47
- yield(extracted)
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
- entry_data = VirtualFileData.new(entry_uri,
56
- entry.file_data,
57
- source_data: data)
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
- Archive::Zip.open(StringIO.new(data.body)) do |zip|
67
- yield(zip)
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
- @body ||= open {|file| file.read}
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
@@ -15,5 +15,5 @@
15
15
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
  module ChupaText
18
- VERSION = "1.1.6"
18
+ VERSION = "1.1.7"
19
19
  end
@@ -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
- @body ||= open {|file| file.read}
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-2017 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
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chupa-text
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou