[Filesystem] FileStream.close
authorPawel Kaczmarek <p.kaczmarek3@samsung.com>
Tue, 3 Mar 2015 10:22:44 +0000 (11:22 +0100)
committerRafal Galka <r.galka@samsung.com>
Tue, 3 Mar 2015 13:28:32 +0000 (22:28 +0900)
[Verification]
Following TCT should pass:
FileStream_close

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

index 445663a..b40eee8 100644 (file)
@@ -41,12 +41,23 @@ function FileStream(data, mode, encoding) {
       value: data,
       writable: false,
       enumerable: false
+    },
+    _closed: {
+      value: false,
+      writable: true,
+      enumerable: false
     }
   });
 }
 
+function _checkClosed(stream) {
+  if (stream._closed) {
+    throw new tizen.WebAPIException(tizen.WebAPIException.IO_ERR, 'Stream is closed.');
+  }
+}
+
 FileStream.prototype.close = function() {
-//  TODO: close
+  this._closed = true;
 };
 
 function _checkReadAccess(mode) {
@@ -69,6 +80,8 @@ FileStream.prototype.read = function() {
     }
   ]);
 
+  _checkClosed(this);
+
   if (args.charCount <= 0) {
     throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
         'Argument "charCount" must be greater than 0');
@@ -102,6 +115,8 @@ FileStream.prototype.readBytes = function() {
     }
   ]);
 
+  _checkClosed(this);
+
   if (args.byteCount <= 0) {
     throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
         'Argument "byteCount" must be greater than 0');
@@ -140,6 +155,8 @@ FileStream.prototype.readBase64 = function() {
     }
   ]);
 
+  _checkClosed(this);
+
   if (args.byteCount <= 0) {
     throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
         'Argument "byteCount" must be greater than 0');
@@ -172,6 +189,7 @@ FileStream.prototype.write = function() {
     }
   ]);
 
+  _checkClosed(this);
   _checkWriteAccess(this._mode);
 
   var data = {
@@ -197,6 +215,7 @@ FileStream.prototype.writeBytes = function() {
     }
   ]);
 
+  _checkClosed(this);
   _checkWriteAccess(this._mode);
 
   var data = {
@@ -220,6 +239,7 @@ FileStream.prototype.writeBase64 = function() {
     }
   ]);
 
+  _checkClosed(this);
   _checkWriteAccess(this._mode);
 
   var data = {