file-type 14.5.0 → 14.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/core.d.ts CHANGED
@@ -23,6 +23,7 @@ declare namespace core {
23
23
  | 'icns'
24
24
  | 'jxr'
25
25
  | 'psd'
26
+ | 'indd'
26
27
  | 'zip'
27
28
  | 'tar'
28
29
  | 'rar'
@@ -133,7 +134,9 @@ declare namespace core {
133
134
  | 'skp'
134
135
  | 'avif'
135
136
  | 'eps'
136
- | 'lzh';
137
+ | 'lzh'
138
+ | 'pgp'
139
+ | 'asar';
137
140
 
138
141
  type MimeType =
139
142
  | 'image/jpeg'
@@ -148,6 +151,7 @@ declare namespace core {
148
151
  | 'image/icns'
149
152
  | 'image/vnd.ms-photo'
150
153
  | 'image/vnd.adobe.photoshop'
154
+ | 'application/x-indesign'
151
155
  | 'application/epub+zip'
152
156
  | 'application/x-xpinstall'
153
157
  | 'application/vnd.oasis.opendocument.text'
@@ -258,7 +262,9 @@ declare namespace core {
258
262
  | 'video/MP2P'
259
263
  | 'application/vnd.sketchup.skp'
260
264
  | 'image/avif'
261
- | 'application/x-lzh-compressed';
265
+ | 'application/x-lzh-compressed'
266
+ | 'application/pgp-encrypted'
267
+ | 'application/x-asar';
262
268
 
263
269
  interface FileTypeResult {
264
270
  /**
@@ -330,7 +336,7 @@ declare namespace core {
330
336
  /**
331
337
  Supported file extensions.
332
338
  */
333
- const extensions: readonly core.FileExtension[];
339
+ const extensions: Set<core.FileExtension>;
334
340
 
335
341
  /**
336
342
  Supported MIME types.
package/core.js CHANGED
@@ -353,7 +353,20 @@ async function _fromTokenizer(tokenizer) {
353
353
  }
354
354
  }
355
355
 
356
- await tokenizer.ignore(zipHeader.compressedSize);
356
+ // Try to find next header manually when current one is corrupted
357
+ if (zipHeader.compressedSize === 0) {
358
+ let nextHeaderIndex = -1;
359
+
360
+ while (nextHeaderIndex < 0 && (tokenizer.position < tokenizer.fileInfo.size)) {
361
+ await tokenizer.peekBuffer(buffer, {mayBeLess: true});
362
+
363
+ nextHeaderIndex = buffer.indexOf('504B0304', 0, 'hex');
364
+ // Move position to the next header if found, skip the whole buffer otherwise
365
+ await tokenizer.ignore(nextHeaderIndex >= 0 ? nextHeaderIndex : buffer.length);
366
+ }
367
+ } else {
368
+ await tokenizer.ignore(zipHeader.compressedSize);
369
+ }
357
370
  }
358
371
  } catch (error) {
359
372
  if (!(error instanceof strtok3.EndOfStreamError)) {
@@ -1182,6 +1195,24 @@ async function _fromTokenizer(tokenizer) {
1182
1195
  };
1183
1196
  }
1184
1197
 
1198
+ if (check([0x04, 0x00, 0x00, 0x00]) && buffer.length >= 16) { // Rough & quick check Pickle/ASAR
1199
+ const jsonSize = buffer.readUInt32LE(12);
1200
+ if (jsonSize > 12 && jsonSize < 240 && buffer.length >= jsonSize + 16) {
1201
+ try {
1202
+ const header = buffer.slice(16, jsonSize + 16).toString();
1203
+ const json = JSON.parse(header);
1204
+ // Check if Pickle is ASAR
1205
+ if (json.files) { // Final check, assuring Pickle/ASAR format
1206
+ return {
1207
+ ext: 'asar',
1208
+ mime: 'application/x-asar'
1209
+ };
1210
+ }
1211
+ } catch (_) {
1212
+ }
1213
+ }
1214
+ }
1215
+
1185
1216
  if (
1186
1217
  check([0x30, 0x30, 0x30, 0x30, 0x30, 0x30], {offset: 148, mask: [0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8]}) && // Valid tar checksum
1187
1218
  tarHeaderChecksumMatches(buffer)
@@ -1262,6 +1293,13 @@ async function _fromTokenizer(tokenizer) {
1262
1293
  };
1263
1294
  }
1264
1295
 
1296
+ if (check([0x06, 0x06, 0xED, 0xF5, 0xD8, 0x1D, 0x46, 0xE5, 0xBD, 0x31, 0xEF, 0xE7, 0xFE, 0x74, 0xB7, 0x1D])) {
1297
+ return {
1298
+ ext: 'indd',
1299
+ mime: 'application/x-indesign'
1300
+ };
1301
+ }
1302
+
1265
1303
  // Increase sample size from 256 to 512
1266
1304
  await tokenizer.peekBuffer(buffer, {length: Math.min(512, tokenizer.fileInfo.size), mayBeLess: true});
1267
1305
 
@@ -1282,6 +1320,13 @@ async function _fromTokenizer(tokenizer) {
1282
1320
  };
1283
1321
  }
1284
1322
 
1323
+ if (checkString('-----BEGIN PGP MESSAGE-----')) {
1324
+ return {
1325
+ ext: 'pgp',
1326
+ mime: 'application/pgp-encrypted'
1327
+ };
1328
+ }
1329
+
1285
1330
  // Check for MPEG header at different starting offsets
1286
1331
  for (let start = 0; start < 2 && start < (buffer.length - 16); start++) {
1287
1332
  // Check MPEG 1 or 2 Layer 3 header, or 'layer 0' for ADTS (MPEG sync-word 0xFFE)
@@ -1340,7 +1385,8 @@ const stream = readableStream => new Promise((resolve, reject) => {
1340
1385
  const pass = new stream.PassThrough();
1341
1386
  let outputStream;
1342
1387
  if (stream.pipeline) {
1343
- outputStream = stream.pipeline(readableStream, pass, () => {});
1388
+ outputStream = stream.pipeline(readableStream, pass, () => {
1389
+ });
1344
1390
  } else {
1345
1391
  outputStream = readableStream.pipe(pass);
1346
1392
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "file-type",
3
- "version": "14.5.0",
3
+ "version": "14.7.0",
4
4
  "description": "Detect the file type of a Buffer/Uint8Array/ArrayBuffer",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/file-type",
@@ -66,6 +66,7 @@
66
66
  "icns",
67
67
  "jxr",
68
68
  "psd",
69
+ "indd",
69
70
  "zip",
70
71
  "tar",
71
72
  "rar",
@@ -176,7 +177,9 @@
176
177
  "skp",
177
178
  "avif",
178
179
  "eps",
179
- "lzh"
180
+ "lzh",
181
+ "pgp",
182
+ "asar"
180
183
  ],
181
184
  "devDependencies": {
182
185
  "@types/node": "^13.1.4",
@@ -188,7 +191,7 @@
188
191
  },
189
192
  "dependencies": {
190
193
  "readable-web-to-node-stream": "^2.0.0",
191
- "strtok3": "^6.0.0",
194
+ "strtok3": "^6.0.3",
192
195
  "token-types": "^2.0.0",
193
196
  "typedarray-to-buffer": "^3.1.5"
194
197
  },
package/readme.md CHANGED
@@ -1,4 +1,4 @@
1
- # file-type [![Build Status](https://travis-ci.com/sindresorhus/file-type.svg?branch=master)](https://travis-ci.ocomrg/sindresorhus/file-type)
1
+ # file-type [![Build Status](https://travis-ci.com/sindresorhus/file-type.svg?branch=master)](https://travis-ci.com/github/sindresorhus/file-type)
2
2
 
3
3
  > Detect the file type of a Buffer/Uint8Array/ArrayBuffer
4
4
 
@@ -289,6 +289,7 @@ Returns a set of supported MIME types.
289
289
  - [`icns`](https://en.wikipedia.org/wiki/Apple_Icon_Image_format)
290
290
  - [`jxr`](https://en.wikipedia.org/wiki/JPEG_XR)
291
291
  - [`psd`](https://en.wikipedia.org/wiki/Adobe_Photoshop#File_format)
292
+ - [`indd`](https://en.wikipedia.org/wiki/Adobe_InDesign#File_format)
292
293
  - [`zip`](https://en.wikipedia.org/wiki/Zip_(file_format))
293
294
  - [`tar`](https://en.wikipedia.org/wiki/Tar_(computing)#File_format)
294
295
  - [`rar`](https://en.wikipedia.org/wiki/RAR_(file_format))
@@ -400,6 +401,8 @@ Returns a set of supported MIME types.
400
401
  - [`avif`](https://en.wikipedia.org/wiki/AV1#AV1_Image_File_Format_(AVIF)) - AV1 Image File Format
401
402
  - [`eps`](https://en.wikipedia.org/wiki/Encapsulated_PostScript) - Encapsulated PostScript
402
403
  - [`lzh`](https://en.wikipedia.org/wiki/LHA_(file_format)) - LZH archive
404
+ - [`pgp`](https://en.wikipedia.org/wiki/Pretty_Good_Privacy) - Pretty Good Privacy
405
+ - [`asar`](https://github.com/electron/asar#format) - Archive format primarily used to enclose Electron applications
403
406
 
404
407
  *Pull requests are welcome for additional commonly used file types.*
405
408
 
package/supported.js CHANGED
@@ -21,6 +21,7 @@ module.exports = {
21
21
  'icns',
22
22
  'jxr',
23
23
  'psd',
24
+ 'indd',
24
25
  'zip',
25
26
  'tar',
26
27
  'rar',
@@ -131,7 +132,9 @@ module.exports = {
131
132
  'skp',
132
133
  'avif',
133
134
  'eps',
134
- 'lzh'
135
+ 'lzh',
136
+ 'pgp',
137
+ 'asar'
135
138
  ],
136
139
  mimeTypes: [
137
140
  'image/jpeg',
@@ -145,6 +148,7 @@ module.exports = {
145
148
  'image/bmp',
146
149
  'image/vnd.ms-photo',
147
150
  'image/vnd.adobe.photoshop',
151
+ 'application/x-indesign',
148
152
  'application/epub+zip',
149
153
  'application/x-xpinstall',
150
154
  'application/vnd.oasis.opendocument.text',
@@ -256,6 +260,8 @@ module.exports = {
256
260
  'video/MP2P',
257
261
  'application/vnd.sketchup.skp',
258
262
  'image/avif',
259
- 'application/x-lzh-compressed'
263
+ 'application/x-lzh-compressed',
264
+ 'application/pgp-encrypted',
265
+ 'application/x-asar'
260
266
  ]
261
267
  };