Kouhei Sutou 2019-03-01 16:10:53 +0900 (Fri, 01 Mar 2019) Revision: 746ecd8492692c29d2e1ad9ceac702f71b3e642c https://github.com/ranguba/chupa-text/commit/746ecd8492692c29d2e1ad9ceac702f71b3e642c Message: tar: reduce memory usage Modified files: lib/chupa-text/decomposers/tar.rb Modified: lib/chupa-text/decomposers/tar.rb (+15 -13) =================================================================== --- lib/chupa-text/decomposers/tar.rb 2019-03-01 13:57:03 +0900 (27e4e9f) +++ lib/chupa-text/decomposers/tar.rb 2019-03-01 16:10:53 +0900 (8fe7ba1) @@ -30,20 +30,22 @@ module ChupaText end def decompose(data) - Gem::Package::TarReader.new(StringIO.new(data.body)) do |reader| - reader.each do |entry| - next unless entry.file? + data.open do |input| + Gem::Package::TarReader.new(input) do |reader| + reader.each do |entry| + next unless entry.file? - entry.extend(CopyStreamable) - entry_uri = data.uri.dup - base_path = entry_uri.path.gsub(/\.tar\z/i, "") - 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) + entry.extend(CopyStreamable) + entry_uri = data.uri.dup + base_path = entry_uri.path.gsub(/\.tar\z/i, "") + 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) + end end end end -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190301/c2105b7c/attachment-0001.html>