Commit 4cfb489b authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '288006-binary' into 'master'

Use `binary` property on the file object

See merge request gitlab-org/gitlab!68643
parents 17af6be9 bf5486b5
...@@ -43,7 +43,10 @@ const KNOWN_TYPES = [ ...@@ -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)); const knownType = KNOWN_TYPES.find((type) => type.isMatch(mimeType, name));
if (knownType) return knownType.isText; if (knownType) return knownType.isText;
......
...@@ -86,6 +86,11 @@ describe('WebIDE utils', () => { ...@@ -86,6 +86,11 @@ describe('WebIDE utils', () => {
expect(isTextFile({ name: 'abc.dat', content: '' })).toBe(true); expect(isTextFile({ name: 'abc.dat', content: '' })).toBe(true);
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', () => { 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