Commit 56913167 authored by Himanshu Kapoor's avatar Himanshu Kapoor Committed by Himanshu Kapoor

Use `binary` property on the file object

Backend sends a `binary` property as `false` for some files that
may have a "binary" mime type but are not actually binary. Use that
if it is available before determining if a file is binary or text.

Changelog: fixed
parent 3e840e6e
......@@ -44,8 +44,8 @@ const KNOWN_TYPES = [
];
export function isTextFile({ name, raw, binary, content, mimeType = '' }) {
// some file objects already have a `binary` property set on them. If true, return false
if (binary) return false;
// some file objects already have a `binary` property set on them. If so, use it first
if (typeof binary === 'boolean') return !binary;
const knownType = KNOWN_TYPES.find((type) => type.isMatch(mimeType, name));
if (knownType) return knownType.isText;
......
......@@ -90,6 +90,9 @@ describe('WebIDE utils', () => {
it('returns true if there is a `binary` property already set on the file object', () => {
expect(isTextFile({ name: 'abc.txt', content: '' })).toBe(true);
expect(isTextFile({ name: 'abc.txt', content: '', binary: true })).toBe(false);
expect(isTextFile({ name: 'abc.tex', content: 'éêė' })).toBe(false);
expect(isTextFile({ name: 'abc.tex', content: 'éêė', binary: false })).toBe(true);
});
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment