diff --git a/.gitattributes b/.gitattributes index 8d2169d9..59f60375 100644 --- a/.gitattributes +++ b/.gitattributes @@ -27,6 +27,7 @@ Makefile text *.icns binary *.ico binary *.img binary +*.iso binary *.png binary *.xz binary *.zip binary diff --git a/lib/image-stream/utils.js b/lib/image-stream/utils.js index 81bfc06c..dcd1a940 100644 --- a/lib/image-stream/utils.js +++ b/lib/image-stream/utils.js @@ -37,10 +37,14 @@ const fs = require('fs'); * }); */ exports.getArchiveMimeType = (filename) => { - + const MIME_TYPE_RAW_IMAGE = 'application/octet-stream'; const mimeType = mime.lookup(filename); if (mimeType) { + if (mimeType === 'application/x-iso9660-image') { + return Bluebird.resolve(MIME_TYPE_RAW_IMAGE); + } + return Bluebird.resolve(mimeType); } @@ -53,7 +57,7 @@ exports.getArchiveMimeType = (filename) => { const buffer = Buffer.alloc(FILE_TYPE_ID_BYTES); return fs.readAsync(fileDescriptor, buffer, BUFFER_START, FILE_TYPE_ID_BYTES, null).then(() => { - return _.get(fileType(buffer), [ 'mime' ], 'application/octet-stream'); + return _.get(fileType(buffer), [ 'mime' ], MIME_TYPE_RAW_IMAGE); }); }); diff --git a/tests/image-stream/data/images/raspberrypi.iso b/tests/image-stream/data/images/raspberrypi.iso new file mode 100644 index 00000000..1cf96222 Binary files /dev/null and b/tests/image-stream/data/images/raspberrypi.iso differ diff --git a/tests/image-stream/iso.spec.js b/tests/image-stream/iso.spec.js new file mode 100644 index 00000000..cecd5c8c --- /dev/null +++ b/tests/image-stream/iso.spec.js @@ -0,0 +1,63 @@ +/* + * Copyright 2016 resin.io + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +const m = require('mochainon'); +const fs = require('fs'); +const path = require('path'); +const DATA_PATH = path.join(__dirname, 'data'); +const IMAGES_PATH = path.join(DATA_PATH, 'images'); +const imageStream = require('../../lib/image-stream/index'); +const tester = require('./tester'); + +describe('ImageStream: ISO', function() { + + this.timeout(20000); + + describe('.getFromFilePath()', function() { + + describe('given an iso image', function() { + tester.extractFromFilePath( + path.join(IMAGES_PATH, 'raspberrypi.iso'), + path.join(IMAGES_PATH, 'raspberrypi.iso')); + }); + + }); + + describe('.getImageMetadata()', function() { + + it('should return the correct metadata', function() { + const image = path.join(IMAGES_PATH, 'raspberrypi.iso'); + const expectedSize = fs.statSync(image).size; + + return imageStream.getImageMetadata(image).then((metadata) => { + m.chai.expect(metadata).to.deep.equal({ + path: image, + size: { + original: expectedSize, + final: { + estimation: false, + value: expectedSize + } + } + }); + }); + }); + + }); + +}); diff --git a/tests/image-stream/utils.spec.js b/tests/image-stream/utils.spec.js index 84aabd80..691d2a26 100644 --- a/tests/image-stream/utils.spec.js +++ b/tests/image-stream/utils.spec.js @@ -61,6 +61,13 @@ describe('ImageStream: Utils', function() { }); }); + it('should resolve application/octet-stream for an uncompressed iso', function() { + const file = path.join(DATA_PATH, 'images', 'raspberrypi.iso'); + return utils.getArchiveMimeType(file).then((type) => { + m.chai.expect(type).to.equal('application/octet-stream'); + }); + }); + it('should resolve application/x-apple-diskimage for a compressed Apple disk image', function() { const file = path.join(DATA_PATH, 'dmg', 'zlib-compressed.dmg'); return utils.getArchiveMimeType(file).then((type) => {