diff options
-rw-r--r-- | lib/fs/index.js | 55 | ||||
-rw-r--r-- | lib/fs/node.js | 13 |
2 files changed, 1 insertions, 67 deletions
diff --git a/lib/fs/index.js b/lib/fs/index.js index 3e0d711..8a3ca1e 100644 --- a/lib/fs/index.js +++ b/lib/fs/index.js @@ -1,13 +1,10 @@ var _ = require('lodash'); var path = require('path'); -var Buffer = require('buffer').Buffer; -var destroy = require('destroy'); -var os = require('os'); var Promise = require('../utils/promise'); /* -A filesystem is an interface to read/write files +A filesystem is an interface to read files GitBook can works with a virtual filesystem, for example in the browser. */ @@ -36,11 +33,6 @@ FS.prototype.stat = function(filename) { // To implement for each fs }; -// Write a file and returns a promise -FS.prototype.write = function(filename, buffer) { - // To implement for each fs -}; - // List files/directories in a directory FS.prototype.readdir = function(folder) { // To implement for each fs @@ -49,11 +41,6 @@ FS.prototype.readdir = function(folder) { // These methods don't require to be redefined, by default it uses .exists, .read, .write, .list // For optmization, it can be redefined: -// Allocate a new temporary directory -FS.prototype.tmpdir = function() { - return path.resolve(os.tmpdir(), 'gitbook_tmp_'+Date.now()); -}; - // List files in a directory FS.prototype.listFiles = function(folder) { return this.readdir(folder) @@ -96,46 +83,6 @@ FS.prototype.readAsString = function(filename) { }); }; -// Write a stream to a file and returns a promise -FS.prototype.writeStream = function(filename, stream) { - var bufs = []; - var d = Promise.defer(); - - var cleanup = function() { - destroy(stream); - stream.removeAllListeners(); - }; - - stream.on('data', function(d) { - bufs.push(d); - }); - - stream.on('error', function(err) { - cleanup(); - - d.reject(err); - }); - - stream.on('end', function(){ - cleanup(); - - var buf = Buffer.concat(bufs); - d.resolve(buf); - }); - - return d.promise; -}; - -// Copy a file -FS.prototype.copy = function(from, to) { - var that = this; - - return this.read(from) - .then(function(buf) { - return that.write(to, buf); - }); -}; - // Find a file in a folder (case incensitive) // Return the real filename FS.prototype.findFile = function findFile(root, filename) { diff --git a/lib/fs/node.js b/lib/fs/node.js index 330391a..fc2517e 100644 --- a/lib/fs/node.js +++ b/lib/fs/node.js @@ -26,19 +26,6 @@ NodeFS.prototype.stat = function(filename) { return fs.stat(filename); }; -// Write a file and returns a promise -NodeFS.prototype.write = function(filename, buffer) { - var folder = path.dirname(filename); - return Promise() - .then(function() { - if (!folder) return; - return fs.mkdirp(folder); - }) - .then(function() { - return fs.writeFile(filename, buffer); - }); -}; - // List files in a directory NodeFS.prototype.readdir = function(folder) { return fs.readdir(folder) |