fix(image-stream): Remove inability to fallback to octet-stream (#1363)

Using `mime-types` in that place made it impossible to use other
other file extensions like `.sdcard` and have them treated as `application/octet-stream`
when drag and dropping images into Etcher.

This moves the fallback logic in `lib/image-stream` to `.getFromFilePath()`,
to still facilitate proper MIME type detection, while allowing it to fall back
to the octet-stream handler, if there's no available handler for a specific type.

Change-Type: patch
Changelog-Entry: Fix not treating unknown images as octet-stream
This commit is contained in:
Jonas Hermsmeier 2017-04-27 18:00:53 +02:00 committed by GitHub
parent 1cf4cdcee9
commit becca2d05e
5 changed files with 13 additions and 14 deletions

1
.gitattributes vendored
View File

@ -32,3 +32,4 @@ Makefile text
*.xz binary *.xz binary
*.zip binary *.zip binary
*.dmg binary *.dmg binary
*.rpi-sdcard binary

View File

@ -76,14 +76,9 @@ exports.getFromFilePath = (file) => {
} }
return utils.getArchiveMimeType(file).then((type) => { return utils.getArchiveMimeType(file).then((type) => {
if (!_.has(handlers, type)) { const MIME_TYPE_RAW_IMAGE = 'application/octet-stream';
throw errors.createUserError({ const mimeType = _.has(handlers, type) ? type : MIME_TYPE_RAW_IMAGE;
title: 'Invalid image', return _.invoke(handlers, mimeType, file, {
description: `The ${type} format is not supported`
});
}
return _.invoke(handlers, type, file, {
size: fileStats.size size: fileStats.size
}); });
}); });

View File

@ -41,10 +41,6 @@ exports.getArchiveMimeType = (filename) => {
const mimeType = mime.lookup(filename); const mimeType = mime.lookup(filename);
if (mimeType) { if (mimeType) {
if (mimeType === 'application/x-iso9660-image') {
return Bluebird.resolve(MIME_TYPE_RAW_IMAGE);
}
return Bluebird.resolve(mimeType); return Bluebird.resolve(mimeType);
} }

Binary file not shown.

View File

@ -61,10 +61,10 @@ describe('ImageStream: Utils', function() {
}); });
}); });
it('should resolve application/octet-stream for an uncompressed iso', function() { it('should resolve application/x-iso9660-image for an uncompressed iso', function() {
const file = path.join(DATA_PATH, 'images', 'raspberrypi.iso'); const file = path.join(DATA_PATH, 'images', 'raspberrypi.iso');
return utils.getArchiveMimeType(file).then((type) => { return utils.getArchiveMimeType(file).then((type) => {
m.chai.expect(type).to.equal('application/octet-stream'); m.chai.expect(type).to.equal('application/x-iso9660-image');
}); });
}); });
@ -82,6 +82,13 @@ describe('ImageStream: Utils', function() {
}); });
}); });
it('should resolve application/octet-stream for an unrecognized file type', function() {
const file = path.join(DATA_PATH, 'unrecognized', 'random.rpi-sdcard');
return utils.getArchiveMimeType(file).then((type) => {
m.chai.expect(type).to.equal('application/octet-stream');
});
});
}); });
describe('.extractStream()', function() { describe('.extractStream()', function() {