Skip to content

Commit eda03a7

Browse files
authored
Add detector for .tar.gz (gunzipped tarball file) (#763)
1 parent c54c744 commit eda03a7

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

core.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Primary entry point, Node.js specific entry point is index.js
44

55
import * as Token from 'token-types';
66
import * as strtok3 from 'strtok3/core';
7-
import {ZipHandler} from '@tokenizer/inflate';
7+
import {ZipHandler, GzipHandler} from '@tokenizer/inflate';
88
import {getUintBE} from 'uint8array-extras';
99
import {
1010
stringToBytes,
@@ -238,7 +238,7 @@ export class FileTypeParser {
238238
}
239239

240240
async fromStream(stream) {
241-
const tokenizer = await strtok3.fromWebStream(stream, this.tokenizerOptions);
241+
const tokenizer = strtok3.fromWebStream(stream, this.tokenizerOptions);
242242
try {
243243
return await this.fromTokenizer(tokenizer);
244244
} finally {
@@ -408,6 +408,21 @@ export class FileTypeParser {
408408
}
409409

410410
if (this.check([0x1F, 0x8B, 0x8])) {
411+
const gzipHandler = new GzipHandler(tokenizer);
412+
413+
const stream = gzipHandler.inflate();
414+
try {
415+
const compressedFileType = await this.fromStream(stream);
416+
if (compressedFileType && compressedFileType.ext === 'tar') {
417+
return {
418+
ext: 'tar.gz',
419+
mime: 'application/gzip',
420+
};
421+
}
422+
} finally {
423+
await stream.cancel();
424+
}
425+
411426
return {
412427
ext: 'gz',
413428
mime: 'application/gzip',

fixture/fixture.gz

87 Bytes
Binary file not shown.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,12 @@
243243
"jar",
244244
"rm",
245245
"ppsm",
246-
"ppsx"
246+
"ppsx",
247+
"tar.gz"
247248
],
248249
"dependencies": {
249-
"@tokenizer/inflate": "^0.2.7",
250-
"strtok3": "^10.2.2",
250+
"@tokenizer/inflate": "^0.3.1",
251+
"strtok3": "^10.3.1",
251252
"token-types": "^6.0.0",
252253
"uint8array-extras": "^1.4.0"
253254
},

readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,8 @@ abortController.abort(); // Abort file-type reading from the Blob stream.
607607
- [`sqlite`](https://www.sqlite.org/fileformat2.html) - SQLite file
608608
- [`stl`](https://en.wikipedia.org/wiki/STL_(file_format)) - Standard Tesselated Geometry File Format (ASCII only)
609609
- [`swf`](https://en.wikipedia.org/wiki/SWF) - Adobe Flash Player file
610-
- [`tar`](https://en.wikipedia.org/wiki/Tar_(computing)#File_format) - Tarball archive file
610+
- [`tar`](https://en.wikipedia.org/wiki/Tar_(computing)#File_format) - Tape archive or tarball
611+
- [`tar.gz`](https://en.wikipedia.org/wiki/Gzip) - Gzipped tape archive (tarball)
611612
- [`tif`](https://en.wikipedia.org/wiki/Tagged_Image_File_Format) - Tagged Image file
612613
- [`ttc`](https://en.wikipedia.org/wiki/TrueType#TrueType_Collection) - TrueType Collection font
613614
- [`ttf`](https://en.wikipedia.org/wiki/TrueType) - TrueType font

supported.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export const extensions = [
174174
'rm',
175175
'ppsm',
176176
'ppsx',
177+
'tar.gz',
177178
];
178179

179180
export const mimeTypes = [

test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const names = {
113113
'fixture-bali',
114114
],
115115
gz: [
116-
'fixture.tar',
116+
'fixture',
117117
],
118118
xz: [
119119
'fixture.tar',
@@ -279,6 +279,9 @@ const names = {
279279
ppsm: [
280280
'fixture',
281281
],
282+
'tar.gz': [
283+
'fixture',
284+
],
282285
};
283286

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

0 commit comments

Comments
 (0)