[Groonga-commit] ranguba/chupa-text at 300212f [master] tar, zip: reduce IO

Back to archive index
Kouhei Sutou null+****@clear*****
Fri Mar 1 18:10:14 JST 2019


Kouhei Sutou	2019-03-01 18:10:14 +0900 (Fri, 01 Mar 2019)

  Revision: 300212ffb2d9a24208c5fab6eba301da5cf3955d
  https://github.com/ranguba/chupa-text/commit/300212ffb2d9a24208c5fab6eba301da5cf3955d

  Message:
    tar, zip: reduce IO

  Modified files:
    lib/chupa-text/decomposers/tar.rb
    lib/chupa-text/decomposers/zip.rb

  Modified: lib/chupa-text/decomposers/tar.rb (+11 -5)
===================================================================
--- lib/chupa-text/decomposers/tar.rb    2019-03-01 18:10:04 +0900 (8fe7ba1)
+++ lib/chupa-text/decomposers/tar.rb    2019-03-01 18:10:14 +0900 (4c1428e)
@@ -14,7 +14,6 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
-require "stringio"
 require "rubygems/package"
 
 require "chupa-text/path-converter"
@@ -41,10 +40,17 @@ module ChupaText
               path_converter = PathConverter.new(entry.full_name,
                                                  uri_escape: true)
               entry_uri.path = "#{base_path}/#{path_converter.convert}"
-              extracted = VirtualFileData.new(entry_uri,
-                                              entry,
-                                              :source_data => data)
-              yield(extracted)
+              if entry.size < (32 * 1024)
+                entry_data = Data.new(source_data: data)
+                entry_data.uri = entry_uri
+                entry_data.body = entry.read || ""
+                entry_data.size = entry.size
+              else
+                entry_data = VirtualFileData.new(entry_uri,
+                                                 entry,
+                                                 :source_data => data)
+              end
+              yield(entry_data)
             end
           end
         end

  Modified: lib/chupa-text/decomposers/zip.rb (+12 -3)
===================================================================
--- lib/chupa-text/decomposers/zip.rb    2019-03-01 18:10:04 +0900 (01647a4)
+++ lib/chupa-text/decomposers/zip.rb    2019-03-01 18:10:14 +0900 (1bad88f)
@@ -50,9 +50,18 @@ module ChupaText
                                                encoding: base_path.encoding,
                                                uri_escape: true)
             entry_uri.path = "#{base_path}/#{path_converter.convert}"
-            entry_data = VirtualFileData.new(entry_uri,
-                                             entry.file_data,
-                                             source_data: data)
+            size = entry.raw_data.window_size
+            if size < (8 * 1024)
+              entry_data = Data.new(source_data: data)
+              entry_data.uri = entry_uri
+              body = entry.file_data.read
+              entry_data.body = body
+              entry_data.size = body.bytesize
+            else
+              entry_data = VirtualFileData.new(entry_uri,
+                                               entry.file_data,
+                                               source_data: data)
+            end
             yield(entry_data)
           end
         end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190301/14a7db2a/attachment-0001.html>


More information about the Groonga-commit mailing list
Back to archive index