Skip to content

Commit 9faa5af

Browse files
committed
Added a check for binary files in createFile
1 parent 465e406 commit 9faa5af

4 files changed

Lines changed: 20 additions & 5 deletions

File tree

dist/grapesjs-plugin-export.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/grapesjs-plugin-export.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default (editor, opts = {}) => {
2525
<body>${ed.getHtml()}</body>
2626
<html>`,
2727
},
28+
isBinary: null,
2829
...opts,
2930
};
3031

@@ -34,7 +35,21 @@ export default (editor, opts = {}) => {
3435
// Add command
3536
editor.Commands.add(commandName, {
3637
createFile(zip, name, content) {
37-
zip.file(name, content);
38+
const opts = {};
39+
const ext = name.split('.')[1];
40+
const isBinary = config.isBinary ?
41+
config.isBinary(content, name) :
42+
!(ext && ['html', 'css'].indexOf(ext) >= 0) &&
43+
!/^[\x00-\x7F]*$/.test(content);
44+
45+
if (isBinary) {
46+
opts.binary = true;
47+
}
48+
49+
editor.log(['Create file', { name, content, opts }],
50+
{ ns: 'plugin-export' });
51+
52+
zip.file(name, content, opts);
3853
},
3954

4055
async createDirectory(zip, root) {

0 commit comments

Comments
 (0)