Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Generated on Jun 13, 2024 via pnpm
Package created
24 Apr 2014
Version published
4 Jun 2023
Maintainers
1
Total deps
12
Direct deps
3
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
10 Packages, Including:
@tokenizer/token@0.3.0
file-type@18.5.0
peek-readable@5.0.0
readable-stream@3.6.2
readable-web-to-node-stream@3.0.2
safe-buffer@5.2.1
string_decoder@1.3.0
strtok3@7.0.0
token-types@5.0.1
util-deprecate@1.0.2

BSD 3-Clause "New" or "Revised" License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
place-warranty
Cannot
use-trademark
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
ieee754@1.2.1

ISC License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
inherits@2.0.4
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

3
All Dependencies CSV
β“˜ This is a list of file-type 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities
readable-web-to-node-stream3.0.24.78 kBMIT
prod
strtok37.0.010.82 kBMIT
prod
token-types5.0.15.7 kBMIT
prod

Visualizations

Frequently Asked Questions

What does file-type do?

File-Type is a powerful npm package developed by Sindre Sorhus that allows for the detection of a file type from a Buffer, Uint8Array, or ArrayBuffer. This resource is designed to detect binary-based file formats and checks the magic number of a buffer to ascertain the file type. However, keep in mind that File-Type is not suitable for text-based formats like '.txt', '.csv', and '.svg'. Notably, the package also welcomes contributions for commonly used modern file formats.

How do you use file-type?

To utilize File-Type, you would first install the npm package using the command npm install file-type. It's important to note that this package is an ESM package, meaning your project also needs to be ESM.

When it comes to using File-Type in your project, there are multiple methods you can use, ranging from detecting file types from files, buffers, streams, and more. For instance, if you want to determine the file type from a file, you can import fileTypeFromFile from 'file-type' and use it as follows:

import {fileTypeFromFile} from 'file-type';

console.log(await fileTypeFromFile('Unicorn.png'));
//=> {ext: 'png', mime: 'image/png'}

In a case where you want to determine the file type from a Buffer, you can import fileTypeFromBuffer and readChunk:

import {fileTypeFromBuffer} from 'file-type';
import {readChunk} from 'read-chunk';

const buffer = await readChunk('Unicorn.png', {length: 4100});

console.log(await fileTypeFromBuffer(buffer));
//=> {ext: 'png', mime: 'image/png'}

For determining a file type from a stream:

import fs from 'node:fs';
import {fileTypeFromStream} from 'file-type';

const stream = fs.createReadStream('Unicorn.mp4');

console.log(await fileTypeFromStream(stream));
//=> {ext: 'mp4', mime: 'video/mp4'}

Then you could also determine file type from a remote:

import got from 'got';
import {fileTypeFromStream} from 'file-type';

const url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg';

const stream = got.stream(url);

console.log(await fileTypeFromStream(stream));
//=> {ext: 'jpg', mime: 'image/jpeg'}

For usage in a browser:

import {fileTypeFromStream} from 'file-type';

const url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg';

const response = await fetch(url);
const fileType = await fileTypeFromStream(response.body);

console.log(fileType);
//=> {ext: 'jpg', mime: 'image/jpeg'}

Where are the file-type docs?

Comprehensive documentation for File-Type can be found directly in the File-Type repository on GitHub. This documentation includes details on its usage, API, and supported file types. Whether you're trying to identify the file type of a Buffer, Uint8Array or ArrayBuffer, or trying to understand the promise for an object that's returned from the numerous methods; the File-Type docs provide all the pertinent information.