Permalink
Browse files

Removed files that are now in promised-io

  • Loading branch information...
1 parent 8bdc032 commit 0de931c4d1a72ed8b73bf8244f312bf3ac80ce3b @kriszyp committed Jul 6, 2010
Showing with 0 additions and 714 deletions.
  1. +0 −7 engines/rhino/lib/fs-promise.js
  2. +0 −110 lib/fs-promise.js
  3. +0 −546 lib/promise.js
  4. +0 −36 lib/pubsub.js
  5. +0 −15 lib/sys.js
@@ -1,7 +0,0 @@
-var File = require("file");
-exports.readFileSync = exports.read = File.read;
-exports.writeFileSync = exports.write = File.write;
-exports.statSync = File.stat;
-
-exports.makeTree = File.mkdirs;
-exports.makeDirectory = File.mkdir;
View
@@ -1,110 +0,0 @@
-/**
-* Node fs module that returns promises
-*/
-
-var fs = require("fs"),
- LazyArray = require("./lazy-array").LazyArray,
- Buffer = require("buffer").Buffer,
- defer = require("./promise").defer;
- convertNodeAsyncFunction = require("./promise").convertNodeAsyncFunction;
-
-// convert all the non-sync functions
-for (var i in fs) {
- if (i.match(/Sync$/) || i.match(/watch/)) {
- exports[i] = fs[i];
- }
- else{
- exports[i] = convertNodeAsyncFunction(fs[i]);
- }
-}
-function File(fd){
- var file = new LazyArray({
- some: function(callback){
- var deferred = defer();
- function readAndSend(){
- var buffer = new Buffer(4096);
- fs.read(fd, buffer, 0, 4096, null, function(err, bytesRead){
- if(err){
- deferred.reject(err);
- return;
- }
- if (bytesRead === 0){
- fs.close(fd);
- deferred.resolve();
- }
- else {
- var result;
- if(bytesRead < 4096){
- result = callback(buffer.slice(0, bytesRead));
- }else{
- result = callback(buffer);
- }
- if(result){
- deferred.resolve();
- }else{
- readAndSend(fd);
- }
- }
- });
- }
- readAndSend();
- return deferred.promise;
- },
- length: 0
- });
- file.fd = fd;
- file.write = function(contents){
-
- }
- return file;
-}
-File.prototype = LazyArray.prototype;
-
-var nodeRead = exports.read;
-exports.read = function(path, options){
- if(path instanceof File){
- arguments[0] = path.fd;
- return nodeRead.apply(this, arguments);
- }else{
- return exports.readFileSync(path, options).toString((options && options.charset) || "utf8");
- }
-};
-
-var nodeWrite = exports.write;
-exports.write = function(path, contents, options){
- if(path instanceof File){
- arguments[0] = path.fd;
- return nodeWrite.apply(this, arguments);
- }else{
- return exports.writeFileSync(path, contents, options);
- }
-};
-var nodeClose = exports.close;
-exports.close = function(path, contents, options){
- if(path instanceof File){
- arguments[0] = path.fd;
- }
- return nodeClose.apply(this, arguments);
-};
-
-
-nodeOpen = exports.open;
-exports.open = function(){
- return nodeOpen.apply(this, arguments).then(File);
-};
-
-exports.makeDirectory = exports.mkdirSync;
-
-exports.makeTree = function(path){
- var index = path.lastIndexOf('/');
- if(index === -1){
- return;
- }
- var path = path.substring(0, index);
- try{
- fs.statSync(path);
- }catch(e){
- exports.makeTree(path);
- fs.mkdirSync(path, 0777);
- }
-};
Oops, something went wrong.

0 comments on commit 0de931c

Please sign in to comment.