diff --git a/.travis.yml b/.travis.yml index dd36277..875ef96 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: node_js node_js: - - 6 + - 8 - node env: - NODE_ENV=production diff --git a/index.js b/index.js index 008275f..34b67fa 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,13 @@ module.exports.bufferCheck = input => { }, options); for (let i = 0; i < header.length; i++) { - if (header[i] !== buf[i + options.offset]) { + // If a bitmask is set + if (options.mask) { + // If header doesn't equal `buf` with bits masked off + if (header[i] !== (options.mask[i] & buf[i + options.offset])) { + return false; + } + } else if (header[i] !== buf[i + options.offset]) { return false; } } @@ -69,6 +75,16 @@ module.exports.bufferCheck = input => { return typesList.wav; } + // Check for MPEG header at different starting offsets + for (let start = 0; start < 2 && start < (buf.length - 16); start++) { + if ( + check([0x49, 0x44, 0x33], {offset: start}) || // ID3 header + check([0xFF, 0xE2], {offset: start, mask: [0xFF, 0xE2]}) // MPEG 1 or 2 Layer 3 header + ) { + return typesList.mp3; + } + } + if (check([0x00, 0x00, 0x00, 0x0C, 0x6A, 0x50, 0x20, 0x20, 0x0D, 0x0A, 0x87, 0x0A])) { // JPEG-2000 family diff --git a/lib/typeslist.js b/lib/typeslist.js index 3119d2c..4a4ba32 100644 --- a/lib/typeslist.js +++ b/lib/typeslist.js @@ -6,6 +6,7 @@ module.exports = { jp2: {ext: 'jpg', mime: 'image/jpg'}, json: {ext: 'json', mime: 'application/json'}, mj2: {ext: 'jpg', mime: 'image/jpg'}, + mp3: {ext: 'mp3', mime: 'audio/mpeg'}, png: {ext: 'png', mime: 'image/png'}, svg: {ext: 'svg', mime: 'image/svg+xml'}, webp: {ext: 'webp', mime: 'image/webp'}, diff --git a/package-lock.json b/package-lock.json index 148a270..e4c4e23 100644 --- a/package-lock.json +++ b/package-lock.json @@ -307,7 +307,7 @@ "integrity": "sha1-OciRjO/1eZ+D+UkqhI9iWt0Mdm8=", "dev": true, "requires": { - "hoek": "2.16.3" + "hoek": "^5.0.3" } }, "brace-expansion": { diff --git a/package.json b/package.json index 27a4b58..042914d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "scratch-asset-types", - "version": "1.0.0", - "description": "Data typing discovering and MIME content-type handling across all media types that the Scratch environment expects", + "version": "1.0.1", + "description": "Data typing discovery and MIME content-type handling across all media types that the Scratch environment expects", "repository": { "type": "git", "url": "git+ssh://git@github.com/LLK/scratch-asset-types.git" @@ -10,12 +10,12 @@ "test": "make test" }, "author": "Massachusetts Institute of Technology", - "license": "private", + "license": "MIT", "devDependencies": { "babel-eslint": "^8.0.3", "eslint": "^4.13.1", "eslint-config-scratch": "^5.0.0", - "tap": "^11.0.0" + "tap": "^11.1.4" }, "dependencies": { "read-chunk": "^2.1.0" diff --git a/test/fixtures/test.mp3 b/test/fixtures/test.mp3 new file mode 100644 index 0000000..ea7e6d2 Binary files /dev/null and b/test/fixtures/test.mp3 differ