Module: FileType::Extractable

Defined in:
lib/file_type.rb

Instance Method Summary collapse

Instance Method Details

#extractObject



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/file_type.rb', line 130

def extract
  base, ext = @base.extsplit
  @tmp = TempPath.new(base.path.basename, ext)
  cmd = mk_cmd(@tmp)
  data = cmd.run(self.class.runner)
  data.waitpid if data.status.nil?
  if data.status != 0
    @tmp.rmtree if @tmp.exist?
    STDERR.puts data.error.read if data.error and data.error.exist?
    raise ExtractError, "Cannot extract a file:
    |  path: #{to_s}
    |  type: #{self.class}
    |  command: #{cmd}
    |  exit status: #{data.status.exitstatus}".head_cut!
  end
  FileType.guess(@tmp)
end

#extractable?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/file_type.rb', line 122

def extractable?
  true
end

#mk_cmd(out) ⇒ Object



126
127
128
# File 'lib/file_type.rb', line 126

def mk_cmd ( out )
  extract_command < @path > out
end