Permalink
Browse files

Handle truncate system calls, which are not supported

  • Loading branch information...
1 parent e42e09e commit 7a15ae6d63bba7b36f5a892902cbe907f248f565 @kunklejr committed Sep 25, 2012
Showing with 44 additions and 2 deletions.
  1. +22 −2 efs.js
  2. +22 −0 test/efs-test.js
View
24 efs.js
@@ -11,7 +11,7 @@ exports.init = function (algorithm, password) {
efs.open = function (path, flags, mode, callback) {
if (flags.indexOf('w') !== 0) {
- return callback(new Error('[node-efs] does not support open for read operations'));
+ return callback(new Error('[node-efs] only supports open for write operations'));
}
var args = copyArgs(arguments);
@@ -51,7 +51,7 @@ exports.init = function (algorithm, password) {
efs.openSync = function (path, flags, mode) {
if (flags.indexOf('w') !== 0) {
- return callback(new Error('[node-efs] does not support open for read operations'));
+ return callback(new Error('[node-efs] only supports open for write operations'));
}
var fd = fs.openSync(path, flags, mode);
@@ -216,6 +216,26 @@ exports.init = function (algorithm, password) {
return fstream;
};
+ efs.truncate = function () {
+ var err = new Error('[node-efs] efs.truncate is an unsupported operation');
+
+ if (typeof arguments[arguments.length - 1] === 'function') {
+ arguments[arguments.length - 1](err);
+ } else {
+ throw err;
+ }
+ };
+
+ efs.truncateSync = function () {
+ var err = new Error('[node-efs] efs.truncateSync is an unsupported operation');
+
+ if (typeof arguments[arguments.length - 1] === 'function') {
+ arguments[arguments.length - 1](err);
+ } else {
+ throw err;
+ }
+ };
+
return efs;
};
View
@@ -239,6 +239,28 @@ vows.describe('efs').addBatch({
efs.unlink(appendFileSyncPath, this.callback);
}
},
+
+ '#truncate': {
+ topic: function () {
+ efs.truncate(this.callback);
+ },
+
+ 'should return an error': function (err, success) {
+ assert.isNotNull(err);
+ }
+ },
+
+ '#truncate without callback': {
+ 'throws an error': function () {
+ assert.throws(efs.truncate);
+ }
+ },
+
+ '#truncateSync': {
+ 'throws an error': function () {
+ assert.throws(efs.truncateSync);
+ }
+ }
}).export(module);
function ticks(num, func) {

0 comments on commit 7a15ae6

Please sign in to comment.