[Filesystem] Add support for ISO-8859-1
[platform/core/api/webapi-plugins.git] / src / filesystem / js / file_stream.js
index a81ead3..7703a88 100644 (file)
@@ -243,6 +243,18 @@ FileStream.prototype.readBase64 = function() {
     return base64_encode(readBytes.apply(this, arguments));
 };
 
+function check_characters_outside_latin1(str) {
+    var len = str.length;
+    for (var i = 0; i < len; ++i) {
+        if (str.charCodeAt(i) > 255) {
+            throw new WebAPIException(
+                WebAPIException.IO_ERR,
+                'Invalid character at ' + i + ': ' + str.charAt(i) + ' (not ISO-8859-1)'
+            );
+        }
+    }
+}
+
 function write() {
     var args = validator_.validateArgs(arguments, [
         {
@@ -269,6 +281,10 @@ function write() {
         rewrite: this._rewrite
     };
 
+    if (data.encoding == 'iso-8859-1') {
+        check_characters_outside_latin1(data.data);
+    }
+
     var result = native_.callSync('File_writeString', data);
 
     if (native_.isFailure(result)) {