Merge pull request from colbygk/release/1.1.0

Release/1.1.0

Fixes issue 
Adds support for mp3 detection
Updates license to MIT
Updates testing environment to node 8
Updates version to 1.1.0
This commit is contained in:
Colby Gutierrez-Kraybill 2018-04-26 20:02:26 -04:00 committed by GitHub
commit f5af1f8486
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 25 additions and 8 deletions

View file

@ -1,6 +1,6 @@
language: node_js
node_js:
- 6
- 8
- node
env:
- NODE_ENV=production

View file

@ -16,7 +16,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;
}
}
@ -51,6 +57,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

View file

@ -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'},
webp: {ext: 'webp', mime: 'image/webp'},
wav: {ext: 'wav', mime: 'audio/x-wav'},

2
package-lock.json generated
View file

@ -307,7 +307,7 @@
"integrity": "sha1-OciRjO/1eZ+D+UkqhI9iWt0Mdm8=",
"dev": true,
"requires": {
"hoek": "2.16.3"
"hoek": "^5.0.3"
}
},
"brace-expansion": {

View file

@ -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.1.0",
"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"

BIN
test/fixtures/test.mp3 vendored Normal file

Binary file not shown.

View file

@ -3,7 +3,7 @@ const fileType = require('../../index');
const typesList = require('../../lib/typeslist');
const checkList = [
'gif', 'jpg', 'json', 'png', 'wav', 'webp', 'zip'];
'gif', 'jpg', 'json', 'mp3', 'png', 'wav', 'webp', 'zip'];
tap.test('check-types', t => {
checkList.forEach(thisType => {