Permalink
Browse files

Forgot to implement 'buffer' option on the other schemes

  • Loading branch information...
1 parent 94ca006 commit d94e91e36e27a9341a2b2dc683989264b0c54c4c @slaskis slaskis committed Mar 2, 2012
Showing with 16 additions and 8 deletions.
  1. +8 −4 lib/schemes/file.js
  2. +8 −4 lib/schemes/ftp.js
View
@@ -3,14 +3,18 @@
*
* Available options:
*
-* {Boolean} stream For when you only want the callback to receive a stream instead of the complete body as the second argument. Defaults to `false`.
+* {Boolean} buffer For when you only want the body to be buffered and returned as the second argument instead of receiving the direct stream. Defaults to `true`.
* {String} encoding The encoding of the file to read.
*/
var fs = require("fs")
, path = require("path")
, utils = require("../utils");
module.exports = function(uri,opts,output){
+ // Default to buffer (using `opts.stream` for backward compability)
+ if( !opts.hasOwnProperty('buffer') )
+ opts.buffer = !opts.stream;
+
if( uri.isRelative() ){
uri.pathname = path.join(process.cwd(),uri.pathname);
uri.normalize()
@@ -21,10 +25,10 @@ module.exports = function(uri,opts,output){
var args = opts.start && opts.end ? [uri.pathname,opts] : [uri.pathname]
try {
if( typeof output == "function" ){
- if( opts.stream ){
- output(null,fs.createReadStream.apply(fs,args));
- } else {
+ if( opts.buffer ){
fs.readFile(uri.pathname,opts.encoding,output);
+ } else {
+ output(null,fs.createReadStream.apply(fs,args));
}
} else {
fs.createReadStream.apply(fs,args).pipe(output)
View
@@ -3,7 +3,7 @@
*
* Available options:
*
-* {Boolean} stream For when you only want the callback to receive a stream instead of the complete body as the second argument. Defaults to `false`.
+* {Boolean} buffer For when you only want the body to be buffered and returned as the second argument instead of receiving the direct stream. Defaults to `true`.
* {Boolean} anonymous If no user info is in the URI, add anonymous. Defaults to `true`.
*/
var ftp = require("ftp")
@@ -12,6 +12,10 @@ var ftp = require("ftp")
module.exports = function(uri,opts,output){
var client = new ftp()
, authenticated = false;
+
+ // Default to buffer (using `opts.stream` for backward compability)
+ if( !opts.hasOwnProperty('buffer') )
+ opts.buffer = !opts.stream;
if( !uri.userinfo && opts.anonymous !== false ){
uri.username = "anonymous";
@@ -45,10 +49,10 @@ module.exports = function(uri,opts,output){
stream.on("error",function(){ client.end() })
stream.on("end",function(){ client.end() })
if( typeof output == "function" ){
- if( opts.stream ){
- output(null,stream);
- } else {
+ if( opts.buffer ){
utils.buffer(null,uri.pathname,stream,output)
+ } else {
+ output(null,stream);
}
} else {
stream.pipe(output);

0 comments on commit d94e91e

Please sign in to comment.