Commit bf5486b5 authored by Himanshu Kapoor's avatar 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 bf553406
......@@ -43,7 +43,10 @@ const KNOWN_TYPES = [
},
];
export function isTextFile({ name, raw, content, mimeType = '' }) {
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;
const knownType = KNOWN_TYPES.find((type) => type.isMatch(mimeType, name));
if (knownType) return knownType.isText;
......
......@@ -86,6 +86,11 @@ describe('WebIDE utils', () => {
expect(isTextFile({ name: 'abc.dat', content: '' })).toBe(true);
expect(isTextFile({ name: 'abc.dat', content: ' ' })).toBe(true);
});
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);
});
});
describe('trimPathComponents', () => {
......
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