Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
mime-detect
Advanced tools
Detect mime type and encoding (aka Content-Type) from buffer, file content and filename.
Detect mime type and encoding (aka Content-Type) from buffer, file content and filename.
Supported both node.js and browser. (It can be bundled with esbuild.)
Powered by:
npm i mime-detect
Alternatively, you can also install it pnpm or yarn for better DX.
import { readdirSync, readFileSync } from 'fs'
import { join } from 'path'
import {
detectBufferMime,
detectFileMime,
detectFilenameMime,
} from 'mime-detect'
// return Promise<string> if not given callback
console.log(await detectFileMime('image.jpg'))
// print 'image/jpeg'
// also support callback-style for less async overhead
detectFileMime('index.html', (error, mime) => console.log(mime))
// print 'text/html; charset=us-ascii'
// also can detect from in-memory binary data
let mime = await detectBufferMime(buffer)
// If the mime is text/plain or application/octet-stream, it can determine mime from filename. Otherwise, the original mime will be returned
mime = detectFilenameMime('users.csv', mime)
export function detectFileMime(file: string, cb: DetectMimeCallback): void
export function detectFileMime(file: string): Promise<string>
export function detectFilenameMime(file: string, mime?: string): string
export function detectBufferMime(buffer: Buffer, cb: DetectMimeCallback): void
export function detectBufferMime(buffer: Buffer): Promise<string>
export interface DetectMimeCallback {
(error: Error, mime?: string): void
(error: null, mime: string): void
}
This project is licensed with BSD-2-Clause
This is free, libre, and open-source software. It comes down to four essential freedoms [ref]:
FAQs
Detect mime type and encoding (aka Content-Type) from buffer, file content and filename.
The npm package mime-detect receives a total of 665 weekly downloads. As such, mime-detect popularity was classified as not popular.
We found that mime-detect demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.