Socket
Socket
Sign inDemoInstall

file-type

Package Overview
Dependencies
11
Maintainers
2
Versions
142
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 17.1.6 to 18.0.0

2

core.d.ts

@@ -390,3 +390,3 @@ import {Readable as ReadableStream} from 'node:stream';

if (stream2.fileType && stream2.fileType.mime === 'image/jpeg') {
if (stream2.fileType?.mime === 'image/jpeg') {
// stream2 can be used to stream the JPEG image (from the very beginning of the stream)

@@ -393,0 +393,0 @@ }

import {Buffer} from 'node:buffer';
import * as Token from 'token-types';
import * as strtok3 from 'strtok3/core';
import * as strtok3 from 'strtok3/core'; // eslint-disable-line n/file-extension-in-import
import {

@@ -29,3 +29,3 @@ stringToBytes,

if (!(buffer && buffer.length > 1)) {
if (!(buffer?.length > 1)) {
return;

@@ -341,3 +341,4 @@ }

if (zipHeader.filename === 'mimetype' && zipHeader.compressedSize === zipHeader.uncompressedSize) {
const mimeType = (await tokenizer.readToken(new Token.StringType(zipHeader.compressedSize, 'utf-8'))).trim();
let mimeType = await tokenizer.readToken(new Token.StringType(zipHeader.compressedSize, 'utf-8'));
mimeType = mimeType.trim();

@@ -1504,3 +1505,2 @@ switch (mimeType) {

export async function fileTypeStream(readableStream, {sampleSize = minimumBytes} = {}) {
// eslint-disable-next-line node/no-unsupported-features/es-syntax
const {default: stream} = await import('node:stream');

@@ -1519,3 +1519,3 @@

// Read the input stream and detect the filetype
const chunk = readableStream.read(sampleSize) || readableStream.read() || Buffer.alloc(0);
const chunk = readableStream.read(sampleSize) ?? readableStream.read() ?? Buffer.alloc(0);
try {

@@ -1522,0 +1522,0 @@ const fileType = await fileTypeFromBuffer(chunk);

{
"name": "file-type",
"version": "17.1.6",
"version": "18.0.0",
"description": "Detect the file type of a Buffer/Uint8Array/ArrayBuffer",

@@ -22,3 +22,3 @@ "license": "MIT",

"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
"node": ">=14.16"
},

@@ -201,14 +201,13 @@ "scripts": {

"readable-web-to-node-stream": "^3.0.2",
"strtok3": "^7.0.0-alpha.9",
"token-types": "^5.0.0-alpha.2"
"strtok3": "^7.0.0",
"token-types": "^5.0.1"
},
"devDependencies": {
"@tokenizer/token": "^0.3.0",
"@types/node": "^16.11.10",
"ava": "^3.15.0",
"@types/node": "^18.7.13",
"ava": "^4.3.1",
"commonmark": "^0.30.0",
"noop-stream": "^1.0.0",
"tsd": "^0.19.0",
"typescript": "^4.5.2",
"xo": "^0.46.4"
"tsd": "^0.22.0",
"xo": "^0.51.0"
},

@@ -224,9 +223,9 @@ "xo": {

"no-bitwise": "off",
"@typescript-eslint/no-unsafe-assignment": "off"
"@typescript-eslint/no-unsafe-assignment": "off",
"unicorn/text-encoding-identifier-case": "off"
}
},
"ava": {
"serial": true,
"verbose": true
"serial": true
}
}

@@ -321,3 +321,3 @@ # file-type

if (stream2.fileType && stream2.fileType.mime === 'image/jpeg') {
if (stream2.fileType?.mime === 'image/jpeg') {
// stream2 can be used to stream the JPEG image (from the very beginning of the stream)

@@ -324,0 +324,0 @@ }

export function stringToBytes(string) {
return [...string].map(character => character.charCodeAt(0));
return [...string].map(character => character.charCodeAt(0)); // eslint-disable-line unicorn/prefer-code-point
}

@@ -20,8 +20,8 @@

for (let i = offset; i < offset + 148; i++) {
sum += buffer[i];
for (let index = offset; index < offset + 148; index++) {
sum += buffer[index];
}
for (let i = offset + 156; i < offset + 512; i++) {
sum += buffer[i];
for (let index = offset + 156; index < offset + 512; index++) {
sum += buffer[index];
}

@@ -28,0 +28,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc