Class: Caco::Unpacker

Inherits:
Trailblazer::Operation
  • Object
show all
Defined in:
lib/caco/unpacker.rb

Instance Method Summary collapse

Instance Method Details

#build_integrity_command(ctx, pack:, mime_type:) ⇒ Object



57
58
59
60
61
62
# File 'lib/caco/unpacker.rb', line 57

def build_integrity_command(ctx, pack:, mime_type:, **)
  return (ctx[:integrity_command] = "tar tzf #{pack}") if mime_type == "application/gzip"
  return (ctx[:integrity_command] = "tar tjf #{pack}") if mime_type == "application/x-bzip"
  return (ctx[:integrity_command] = "tar tf #{pack}") if mime_type == "application/x-tar"
  ctx[:integrity_command] = "tar tf #{pack}"
end

#build_unknown_command(ctx, pack:, dest:, mime_type:) ⇒ Object



70
71
72
73
74
75
# File 'lib/caco/unpacker.rb', line 70

def build_unknown_command(ctx, pack:, dest:, mime_type:, **)
  basename = File.basename(pack)
  return ctx[:command] = "gunzip -c #{pack} > #{dest}/#{basename}" if mime_type == "application/gzip"
  ctx[:failure_reason] = "unknown_format"
  false
end

#find_format(ctx, pack:, dest:) ⇒ Object



64
65
66
67
68
# File 'lib/caco/unpacker.rb', line 64

def find_format(ctx, pack:, dest:, **)
  ctx[:unknown_file_mime] = Marcel::MimeType.for pack
rescue StandardError
  false
end