Skip to content

Commit

Permalink
Add "application/octet-stream" as an allowed file type
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuatcasey authored and ForestEckhardt committed Mar 23, 2022
1 parent 306103e commit d176542
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions vacation/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ func NewArchive(inputReader io.Reader) Archive {
// Decompress reads from Archive, determines the archive type of the input
// stream, and writes files into the destination specified.
//
// Archive decompression will also handle files that are types "text/plain;
// charset=utf-8" and write the contents of the input stream to a file name
// specified by the `Archive.WithName()` option in the destination directory.
// Archive decompression will also handle files that are types
// - "application/x-executable"
// - "text/plain; charset=utf-8"
// - "application/jar"
// - "application/octet-stream"
// and write the contents of the input stream to a file name specified by the
// `Archive.WithName()` option in the destination directory.
func (a Archive) Decompress(destination string) error {
// Convert reader into a buffered read so that the header can be peeked to
// determine the type.
Expand All @@ -48,8 +52,7 @@ func (a Archive) Decompress(destination string) error {

mime := mimetype.Detect(header)

// This switch case is reponsible for determining what the decompression
// strategy should be.
// This switch case is responsible for determining the decompression strategy
var decompressor Decompressor
switch mime.String() {
case "application/x-tar":
Expand All @@ -62,10 +65,11 @@ func (a Archive) Decompress(destination string) error {
decompressor = NewBzip2Archive(bufferedReader).StripComponents(a.components).WithName(a.name)
case "application/zip":
decompressor = NewZipArchive(bufferedReader).StripComponents(a.components)
case "application/x-executable":
case "application/x-executable",
"text/plain; charset=utf-8",
"application/jar",
"application/octet-stream":
decompressor = NewExecutable(bufferedReader).WithName(a.name)
case "text/plain; charset=utf-8", "application/jar":
decompressor = NewNopArchive(bufferedReader).WithName(a.name)
default:
return fmt.Errorf("unsupported archive type: %s", mime.String())
}
Expand Down

0 comments on commit d176542

Please sign in to comment.