[Filesystem] FileStream.write, FileStream.writeBytes, FileStream.writeBase64
authorPawel Kaczmarek <p.kaczmarek3@samsung.com>
Mon, 2 Mar 2015 14:36:34 +0000 (15:36 +0100)
committerRafal Galka <r.galka@samsung.com>
Tue, 3 Mar 2015 13:27:29 +0000 (22:27 +0900)
[Verification]
var documentsDir;
function onsuccess(files) {
  for (var i = 0; i < files.length; i++) {
    console.log("File Name is " + files[i].name);
  }

  var testFile = documentsDir.createFile('testFile01.txt');
  console.log('testFile', testFile);
  if (testFile !== null) {
    testFile.openStream(
            "rw",
            function (fs) {
              fs.write('This is test file data');
            }, function (e) {
      console.log("Error " + e.message);
    }, "UTF-8"
            );
  }
}

function onerror(error) {
  console.log("The error " + error.message + " occurred when listing the files in the selected folder");
}

tizen.filesystem.resolve(
        'documents',
        function (dir) {
          documentsDir = dir;
          dir.listFiles(onsuccess, onerror);
        }, function (e) {
    console.log("Error" + e.message);
  }, "rw"
);

Change-Id: I67b076ee8e26a4d9cf32c629bb821a65f8335443
Signed-off-by: Pawel Kaczmarek <p.kaczmarek3@samsung.com>
src/filesystem/js/file_stream.js

index ae2716a16578b60d8b93080585c1347db46271d9..445663ae375cb1591b5f758b334ba4dd463ea212 100644 (file)
@@ -46,11 +46,7 @@ function FileStream(data, mode, encoding) {
 }
 
 FileStream.prototype.close = function() {
-  var result = native_.callSync('FileStream_close', {});
-
-  if (native_.isFailure(result)) {
-    throw native_.getErrorObject(result);
-  }
+//  TODO: close
 };
 
 function _checkReadAccess(mode) {
@@ -178,11 +174,18 @@ FileStream.prototype.write = function() {
 
   _checkWriteAccess(this._mode);
 
-  var result = native_.callSync('FileStream_write', {});
+  var data = {
+    location: commonFS_.toRealPath(this._file.fullPath),
+    offset: this.position,
+    data: Base64.encode(args.stringData)
+  };
+
+  var result = native_.callSync('File_writeSync', data);
 
   if (native_.isFailure(result)) {
     throw native_.getErrorObject(result);
   }
+  this.position = args.stringData.length;
 };
 
 FileStream.prototype.writeBytes = function() {
@@ -196,7 +199,13 @@ FileStream.prototype.writeBytes = function() {
 
   _checkWriteAccess(this._mode);
 
-  var result = native_.callSync('FileStream_writeBytes', {});
+  var data = {
+    location: commonFS_.toRealPath(this._file.fullPath),
+    offset: this.position,
+    data: Base64.encode(String.fromCharCode.apply(String, args.byteData))
+  };
+
+  var result = native_.callSync('File_writeSync', data);
 
   if (native_.isFailure(result)) {
     throw native_.getErrorObject(result);
@@ -213,7 +222,13 @@ FileStream.prototype.writeBase64 = function() {
 
   _checkWriteAccess(this._mode);
 
-  var result = native_.callSync('FileStream_writeBase64', {});
+  var data = {
+    location: commonFS_.toRealPath(this._file.fullPath),
+    offset: this.position,
+    data: args.base64Data
+  };
+
+  var result = native_.callSync('File_writeSync', data);
 
   if (native_.isFailure(result)) {
     throw native_.getErrorObject(result);