Skip to content

Commit

Permalink
perf(remix-architect): Performance improvements on isBinaryType
Browse files Browse the repository at this point in the history
  • Loading branch information
Pannatier Guillaume authored and Pannatier Guillaume committed Dec 3, 2022
1 parent 81bea3f commit 9619d19
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
- guatedude2
- guerra08
- gunners6518
- gyx1000
- hadizz
- hardingmatt
- helderburato
Expand Down
11 changes: 11 additions & 0 deletions packages/remix-architect/__tests__/binaryType-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { isBinaryType } from "../binaryTypes";

describe('architect isBinaryType', () => {
it('should detect binary contentType correctly', () => {
expect(isBinaryType(undefined)).toBe(false);
expect(isBinaryType(null)).toBe(false);
expect(isBinaryType('text/html; charset=utf-8')).toBe(false);
expect(isBinaryType('application/octet-stream')).toBe(true);
expect(isBinaryType('application/octet-stream; charset=test')).toBe(true);
});
});
7 changes: 4 additions & 3 deletions packages/remix-architect/binaryTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Common binary MIME types
* @see https://github.com/architect/functions/blob/45254fc1936a1794c185aac07e9889b241a2e5c6/src/http/helpers/binary-types.js
*/
const binaryTypes = [
const binaryTypes = new Set([
"application/octet-stream",
// Docs
"application/epub+zip",
Expand Down Expand Up @@ -60,9 +60,10 @@ const binaryTypes = [
"application/x-tar",
"application/x-zip",
"application/zip",
];
]);

export function isBinaryType(contentType: string | null | undefined) {
if (!contentType) return false;
return binaryTypes.some((t) => contentType.includes(t));
let [ test ] = contentType.split(';');
return binaryTypes.has(test);
}

0 comments on commit 9619d19

Please sign in to comment.