Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for cpio #590

Merged
merged 6 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ export type FileExtension =
| 'parquet'
| 'class'
| 'arj'
; // eslint-disable-line semi-style
| 'cpio'
; // eslint-disable-line semi-style
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect


export type MimeType =
| 'image/jpeg'
Expand Down Expand Up @@ -290,6 +291,7 @@ export type MimeType =
| 'application/x-parquet'
| 'application/java-vm'
| 'application/x-arj'
| 'application/x-cpio'
; // eslint-disable-line semi-style

export type FileTypeResult = {
Expand Down
14 changes: 14 additions & 0 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ class FileTypeParser {
};
}

if (this.check([0xC7, 0x71])) {
return {
ext: 'cpio',
mime: 'application/x-cpio',
};
}

if (this.check([0x60, 0xEA])) {
return {
ext: 'arj',
Expand Down Expand Up @@ -981,6 +988,13 @@ class FileTypeParser {
}
}

if (this.checkString('070707')) {
return {
ext: 'cpio',
mime: 'application/x-cpio',
};
}

// -- 7-byte signatures --

if (this.checkString('BLENDER')) {
Expand Down
Binary file added fixture/fixture-ascii.cpio
Binary file not shown.
Binary file added fixture/fixture-bin.cpio
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@
"dwg",
"parquet",
"class",
"arj"
"arj",
"cpio"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect indentation

],
"dependencies": {
"readable-web-to-node-stream": "^3.0.2",
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ Returns a `Set<string>` of supported MIME types.
- [`cfb`](https://en.wikipedia.org/wiki/Compound_File_Binary_Format) - Compount File Binary Format
- [`chm`](https://en.wikipedia.org/wiki/Microsoft_Compiled_HTML_Help) - Microsoft Compiled HTML Help
- [`class`](https://en.wikipedia.org/wiki/Java_class_file) - Java class file
- [`cpio`](https://en.wikipedia.org/wiki/Cpio) - Cpio archive
- [`cr2`](https://fileinfo.com/extension/cr2) - Canon Raw image file (v2)
- [`cr3`](https://fileinfo.com/extension/cr3) - Canon Raw image file (v3)
- [`crx`](https://developer.chrome.com/extensions/crx) - Google Chrome extension
Expand Down
2 changes: 2 additions & 0 deletions supported.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export const extensions = [
'parquet',
'class',
'arj',
'cpio',
];

export const mimeTypes = [
Expand Down Expand Up @@ -287,4 +288,5 @@ export const mimeTypes = [
'application/x-parquet',
'application/java-vm',
'application/x-arj',
'application/x-cpio',
];
4 changes: 4 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ const names = {
dwg: [
'fixture-line-weights',
],
cpio: [
'fixture-bin',
'fixture-ascii',
],
};

// Define an entry here only if the file type has potential
Expand Down