Skip to content

Commit

Permalink
Revert "move only ingore to try catch, early return pdf"
Browse files Browse the repository at this point in the history
This reverts commit 3b90419.
  • Loading branch information
eric-yuan-vanta committed Feb 17, 2023
1 parent 3b90419 commit 5f1435e
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,28 +613,22 @@ class FileTypeParser {
if (this.checkString('%PDF')) {
try {
await tokenizer.ignore(1350);
const maxBufferSize = 10 * 1024 * 1024;
const buffer = Buffer.alloc(Math.min(maxBufferSize, tokenizer.fileInfo.size));
await tokenizer.readBuffer(buffer, {mayBeLess: true});

// Check if this is an Adobe Illustrator file
if (buffer.includes(Buffer.from('AIPrivateData'))) {
return {
ext: 'ai',
mime: 'application/postscript',
};
}
} catch (error) {
// Swallow end of stream error if file is too small for the Adobe AI check
if (!(error instanceof strtok3.EndOfStreamError)) {
throw error;
}

return {
ext: 'pdf',
mime: 'application/pdf',
};
}

const maxBufferSize = 10 * 1024 * 1024;
const buffer = Buffer.alloc(Math.min(maxBufferSize, tokenizer.fileInfo.size));
await tokenizer.readBuffer(buffer, {mayBeLess: true});

// Check if this is an Adobe Illustrator file
if (buffer.includes(Buffer.from('AIPrivateData'))) {
return {
ext: 'ai',
mime: 'application/postscript',
};
}

// Assume this is just a normal PDF
Expand Down

0 comments on commit 5f1435e

Please sign in to comment.