Merge branch 'develop' into update_svg_detection

This commit is contained in:
Colby Gutierrez-Kraybill 2022-03-11 17:36:36 -05:00 committed by GitHub
commit 6953397c58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 7 deletions

View file

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

View file

@ -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

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'},
svg: {ext: 'svg', mime: 'image/svg+xml'},
webp: {ext: 'webp', mime: 'image/webp'},

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.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"

BIN
test/fixtures/test.mp3 vendored Normal file

Binary file not shown.