2

I was using blob to write a file with javascript in the client side. Following is the code snippet I used:

var blob = new Blob(['hello'], {type: "text/plain;charset=utf-8"});
saveAs(blob, "path.m");

Unfortunately, there is a junk character at the beginning of the file as flagged by Matlab:

enter image description here

I don't know what this character is and how Blob is introducing them. But I need to fix it before I can generate an actual matlab .m file.

I request anybody who knows how to fix this to help me.

Thanks.

  • It's likely a BOM (byte order mark). –  Dec 28 '16 at 23:42
  • https://stackoverflow.com/questions/2223882/whats-different-between-utf-8-and-utf-8-without-bom#2223926 –  Dec 28 '16 at 23:44

1 Answers1

1

I found the solution to this problem. I changed the character set from utf-8 to ISO-8859-1 as follows:

var blob = new Blob(['hello'], {type: "text/plain;charset=ISO-8859-1"});

and it solved the problem.