lib/chupa-text/decomposers/tar.rb in chupa-text-1.1.5 vs lib/chupa-text/decomposers/tar.rb in chupa-text-1.1.6

- old
+ new

@@ -1,6 +1,6 @@ -# Copyright (C) 2013-2017 Kouhei Sutou <kou@clear-code.com> +# Copyright (C) 2013-2019 Kouhei Sutou <kou@clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. @@ -15,10 +15,12 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA require "stringio" require "rubygems/package" +require "chupa-text/path-converter" + module ChupaText module Decomposers class Tar < Decomposer registry.register("tar", self) @@ -26,21 +28,25 @@ data.extension == "tar" or data.mime_type == "application/x-tar" 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, "") - entry_uri.path = "#{base_path}/#{entry.full_name}" - 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 # TODO: Supporting output buffer in #read and #readpartial