Gathering detailed insights and metrics for @labelbox/magic-bytes.js
Gathering detailed insights and metrics for @labelbox/magic-bytes.js
npm install @labelbox/magic-bytes.js
Typescript
Module System
Node Version
NPM Version
75.7
Supply Chain
97.1
Quality
82.8
Maintenance
100
Vulnerability
100
License
TypeScript (87.25%)
HTML (6.97%)
CSS (3.48%)
JavaScript (2.3%)
Total Downloads
31,598
Last Day
5
Last Week
10
Last Month
37
Last Year
5,259
136 Stars
213 Commits
26 Forks
1 Watching
7 Branches
14 Contributors
Minified
Minified + Gzipped
Latest Version
1.0.15
Package Id
@labelbox/magic-bytes.js@1.0.15
Unpacked Size
209.03 kB
Size
16.91 kB
File Count
29
NPM Version
8.5.0
Node Version
16.14.2
Cumulative downloads
Total Downloads
Last day
0%
5
Compared to previous day
Last week
150%
10
Compared to previous week
Last month
68.2%
37
Compared to previous month
Last year
-70.2%
5,259
Compared to previous year
Magic Bytes is a javascript library analyzing the first bytes of a file to tell you its type. The procedure is based on https://en.wikipedia.org/wiki/List_of_file_signatures.
Run npm install magic-bytes.js
On server:
1import filetype from 'magic-bytes.js' 2 3filetype(fs.readFileSync("myimage.png")) // ["png"]
Using HTML:
1<input type="file" id="file" />
2
3 <script src="node_modules/magic-bytes.js/dist/browser.js" type="application/javascript"></script>
4<script>
5 document.getElementById("file").addEventListener('change', (event, x) => {
6 const fileReader = new FileReader();
7 fileReader.onloadend = (f) => {
8 const bytes = new Uint8Array(f.target.result);
9 console.log("Possible filetypes: " + filetypeinfo(bytes))
10 }
11 fileReader.readAsArrayBuffer(event.target.files[0])
12 })
13</script>
The following functions are availble:
filetypeinfo(bytes: number[])
Contains typeinformation like name, extension and mime type: [{typename: "zip"}, {typename: "jar"}]
filetypenames(bytes: number[])
: Contains type names only: ["zip", "jar"]
filetypemime(bytes: number[])
: Contains type mime types only: ["application/zip", "application/jar"]
filetypeextensions(bytes: number[])
: Contains type extensions only: ["zip", "jar"]
Both function return an empty array []
otherwise, which means it could not detect the file signature. Keep in mind that
txt files for example fall in this category.
You don't have to load the whole file in memory. For validating a file uploaded to S3 using Lambda for example, it may be
enough to load the files first 100 bytes and validate against them. This is especially useful for big files.
see examples for practical usage.
Run npm test
See examples/
The create-snapshot.js
creates a new tree. The tree has a similar shape to the following
1{ 2 "0x47": { 3 "0x49": { 4 "0x46": { 5 "0x38": { 6 "0x37": { 7 "0x61": { 8 "matches": [ 9 { 10 "typename": "gif", 11 "mime": "image/gif", 12 "extension": "gif" 13 } 14 ] 15 } 16 }, 17 } 18 } 19 } 20 } 21}
It acts as a giant lookup map for the given byte signatures. To check all available entries, have a look at pattern-tree.js
and its
generated pattern-tree.snapshot
, which acts as a static resource.
Please refer to src/pattern-tree.js
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
Found 5/27 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
24 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-20
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More