file-type
Advanced tools
Comparing version 14.7.0 to 14.7.1
21
core.js
@@ -7,4 +7,3 @@ 'use strict'; | ||
tarHeaderChecksumMatches, | ||
uint32SyncSafeToken, | ||
uint8ArrayUtf8ByteString | ||
uint32SyncSafeToken | ||
} = require('./util'); | ||
@@ -468,3 +467,3 @@ const supported = require('./supported'); | ||
// For some cases, we're specific, everything else falls to `video/mp4` with `mp4` extension. | ||
const brandMajor = uint8ArrayUtf8ByteString(buffer, 8, 12).replace('\0', ' ').trim(); | ||
const brandMajor = buffer.toString('binary', 8, 12).replace('\0', ' ').trim(); | ||
switch (brandMajor) { | ||
@@ -1218,12 +1217,2 @@ case 'avif': | ||
if ( | ||
check([0x30, 0x30, 0x30, 0x30, 0x30, 0x30], {offset: 148, mask: [0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8]}) && // Valid tar checksum | ||
tarHeaderChecksumMatches(buffer) | ||
) { | ||
return { | ||
ext: 'tar', | ||
mime: 'application/x-tar' | ||
}; | ||
} | ||
if (check([0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E])) { | ||
@@ -1309,6 +1298,4 @@ return { | ||
if ( | ||
check([0x30, 0x30, 0x30, 0x30, 0x30, 0x30], {offset: 148, mask: [0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8]}) && // Valid tar checksum | ||
tarHeaderChecksumMatches(buffer) | ||
) { | ||
// Requires a buffer size of 512 bytes | ||
if (tarHeaderChecksumMatches(buffer)) { | ||
return { | ||
@@ -1315,0 +1302,0 @@ ext: 'tar', |
{ | ||
"name": "file-type", | ||
"version": "14.7.0", | ||
"version": "14.7.1", | ||
"description": "Detect the file type of a Buffer/Uint8Array/ArrayBuffer", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
15
util.js
@@ -5,6 +5,2 @@ 'use strict'; | ||
const uint8ArrayUtf8ByteString = (array, start, end) => { | ||
return String.fromCharCode(...array.slice(start, end)); | ||
}; | ||
exports.tarHeaderChecksumMatches = buffer => { // Does not check if checksum field characters are valid | ||
@@ -15,5 +11,10 @@ if (buffer.length < 512) { // `tar` header size, cannot compute checksum without it | ||
const readSum = parseInt(buffer.toString('utf8', 148, 154).replace(/\0.*$/, '').trim(), 8); // Read sum in header | ||
if (isNaN(readSum)) { | ||
return false; | ||
} | ||
const MASK_8TH_BIT = 0x80; | ||
let sum = 256; // Intitalize sum, with 256 as sum of 8 spaces in checksum field | ||
let sum = 256; // Initialize sum, with 256 as sum of 8 spaces in checksum field | ||
let signedBitSum = 0; // Initialize signed bit sum | ||
@@ -35,4 +36,2 @@ | ||
const readSum = parseInt(uint8ArrayUtf8ByteString(buffer, 148, 154), 8); // Read sum in header | ||
// Some implementations compute checksum incorrectly using signed bytes | ||
@@ -48,4 +47,2 @@ return ( | ||
exports.uint8ArrayUtf8ByteString = uint8ArrayUtf8ByteString; | ||
/** | ||
@@ -52,0 +49,0 @@ ID3 UINT32 sync-safe tokenizer token. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73231
2008