}
}
+exports.writeFile = function (filename, data, encoding) {
+ var promise = new node.Promise();
+
+ encoding = encoding || "utf8"; // default to utf8
+
+ node.fs.open(filename, node.O_WRONLY | node.O_TRUNC | node.O_CREAT, 0666)
+ .addCallback(function (fd) {
+ function doWrite (_data) {
+ node.fs.write(fd, _data, 0, encoding)
+ .addErrback(function () {
+ node.fs.close(fd);
+ })
+ .addCallback(function (written) {
+ if (written == _data.length) {
+ node.fs.close(fd);
+ } else {
+ doWrite(_data.slice(written));
+ }
+ });
+ }
+ doWrite(data);
+ })
+ .addErrback(function () {
+ promise.emitError()
+ });
+
+ return promise;
+};
+
exports.File = function (filename, mode, options) {
var self = this;