Skip to content

Commit

Permalink
Add support for Zstandard compressed file (#439)
Browse files Browse the repository at this point in the history
* Add support for Zstandard compressed file

https://en.wikipedia.org/wiki/Zstandard

**Zstandard**

Filename extension:
.zst

Internet media type:
application/zstd

Magic number	:
28 b5 2f fd

Type of format	Data compression:
Standard	RFC 8478

Website:
https://github.com/facebook/zstd/blob/dev/doc/zstd_compression_format.md

* fix "Invalid number literal casing"
  • Loading branch information
ardavank authored Mar 6, 2021
1 parent 2cc0869 commit 9319167
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 6 deletions.
7 changes: 4 additions & 3 deletions core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ declare namespace core {
| 'asar'
| 'stl'
| 'chm'
| '3mf';
| '3mf'
| 'zst';

type MimeType =
| 'image/jpeg'
Expand Down Expand Up @@ -268,7 +269,8 @@ declare namespace core {
| 'application/x-asar'
| 'model/stl'
| 'application/vnd.ms-htmlhelp'
| 'model/3mf';
| 'model/3mf'
| 'application/zstd';

interface FileTypeResult {
/**
Expand Down Expand Up @@ -376,4 +378,3 @@ declare namespace core {
}

export = core;

7 changes: 7 additions & 0 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,13 @@ async function _fromTokenizer(tokenizer) {
};
}

if (check([0x28, 0xB5, 0x2F, 0xFD])) {
return {
ext: 'zst',
mime: 'application/zstd'
};
}

// -- 5-byte signatures --

if (check([0x4F, 0x54, 0x54, 0x4F, 0x00])) {
Expand Down
Binary file added fixture/fixture.tar.zst
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@
"asar",
"stl",
"chm",
"3mf"
"3mf",
"zst"
],
"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 @@ -297,6 +297,7 @@ Returns a set of supported MIME types.
- [`rar`](https://en.wikipedia.org/wiki/RAR_(file_format)) - Archive file
- [`gz`](https://en.wikipedia.org/wiki/Gzip) - Archive file
- [`bz2`](https://en.wikipedia.org/wiki/Bzip2) - Archive file
- [`zst`](https://en.wikipedia.org/wiki/Zstandard) - Archive file
- [`7z`](https://en.wikipedia.org/wiki/7z) - 7-Zip archive
- [`dmg`](https://en.wikipedia.org/wiki/Apple_Disk_Image) - Apple Disk Image
- [`mp4`](https://en.wikipedia.org/wiki/MPEG-4_Part_14#Filename_extensions) - MPEG-4 Part 14 video file
Expand Down
6 changes: 4 additions & 2 deletions supported.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ module.exports = {
'asar',
'stl',
'chm',
'3mf'
'3mf',
'zst'
],
mimeTypes: [
'image/jpeg',
Expand Down Expand Up @@ -266,6 +267,7 @@ module.exports = {
'application/x-asar',
'model/stl',
'application/vnd.ms-htmlhelp',
'model/3mf'
'model/3mf',
'application/zstd'
]
};
3 changes: 3 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ const names = {
Z: [
'fixture.tar'
],
zst: [
'fixture.tar'
],
mkv: [
'fixture',
'fixture2'
Expand Down

0 comments on commit 9319167

Please sign in to comment.