Skip to content

Commit

Permalink
Add support for cpio (#590)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcfreire committed Apr 24, 2023
1 parent 935470e commit f84e96c
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export type FileExtension =
| 'parquet'
| 'class'
| 'arj'
| 'cpio'
; // eslint-disable-line semi-style

export type MimeType =
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"
],
"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

0 comments on commit f84e96c

Please sign in to comment.