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 Asar #378

Merged
merged 14 commits into from
Aug 1, 2020
6 changes: 4 additions & 2 deletions core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ declare namespace core {
| 'avif'
| 'eps'
| 'lzh'
| 'pgp';
| 'pgp'
| 'asar';

type MimeType =
| 'image/jpeg'
Expand Down Expand Up @@ -262,7 +263,8 @@ declare namespace core {
| 'application/vnd.sketchup.skp'
| 'image/avif'
| 'application/x-lzh-compressed'
| 'application/pgp-encrypted';
| 'application/pgp-encrypted'
| 'application/asar';

interface FileTypeResult {
/**
Expand Down
18 changes: 18 additions & 0 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,24 @@ async function _fromTokenizer(tokenizer) {
}
}
}

// Check for Asar
try {
// Check header_size
buffer.readUInt32LE(4);

// Check header
// Header's first char should be "{" because expect JSON
if (check([0x7B], {offset: 16})) {
const jsonSize = buffer.readUInt32LE(12);
const header = buffer.slice(16, jsonSize + 16).toString();
JSON.parse(header);
return {
ext: 'asar',
mime: 'application/asar'
};
}
} catch (_) {}
}

const stream = readableStream => new Promise((resolve, reject) => {
Expand Down
Binary file added fixture/fixture.asar
Binary file not shown.
Binary file added fixture/fixture2.asar
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@
"avif",
"eps",
"lzh",
"pgp"
"pgp",
"asar"
],
"devDependencies": {
"@types/node": "^13.1.4",
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ Returns a set of supported MIME types.
- [`eps`](https://en.wikipedia.org/wiki/Encapsulated_PostScript) - Encapsulated PostScript
- [`lzh`](https://en.wikipedia.org/wiki/LHA_(file_format)) - LZH archive
- [`pgp`](https://en.wikipedia.org/wiki/Pretty_Good_Privacy) - Pretty Good Privacy
- [`asar`](https://github.com/electron/asar#format) - Asar

*Pull requests are welcome for additional commonly used file types.*

Expand Down
6 changes: 4 additions & 2 deletions supported.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ module.exports = {
'avif',
'eps',
'lzh',
'pgp'
'pgp',
'asar'
],
mimeTypes: [
'image/jpeg',
Expand Down Expand Up @@ -260,6 +261,7 @@ module.exports = {
'application/vnd.sketchup.skp',
'image/avif',
'application/x-lzh-compressed',
'application/pgp-encrypted'
'application/pgp-encrypted',
'application/asar'
]
};
4 changes: 4 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const names = {
'fixture-adts-mpeg4-2',
'fixture-id3v2'
],
asar: [
'fixture',
'fixture2'
],
arw: [
'fixture',
'fixture2',
Expand Down