Skip to content

Commit

Permalink
started streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Sep 20, 2010
1 parent 2bdd87f commit fdab959
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/knox/client.js
Expand Up @@ -14,6 +14,7 @@ var utils = require('./utils')
, http = require('http')
, join = require('path').join
, mime = require('mime')
, sys = require('sys')
, fs = require('fs');

/**
Expand Down Expand Up @@ -160,6 +161,20 @@ Client.prototype.putFile = function(src, filename, headers, fn){
});
};

Client.prototype.putStream = function(stream, filename, headers, fn){
var self = this;
if ('function' == typeof headers) fn = headers;
fs.stat(stream.path, function(err, stat){
if (err) return fn(err);
var req = self.put(filename, utils.merge({
'Content-Length': stat.size
}, headers));
sys.pump(stream, req, function(err){
console.log(err);
});
});
};

/**
* GET `filename` with optional `headers`.
*
Expand Down
10 changes: 10 additions & 0 deletions test/ns3.test.js
Expand Up @@ -113,6 +113,16 @@ module.exports = {
});
},

'test .putStream()': function(assert, done){
var stream = fs.createReadStream(jsonFixture)
, headers = { 'Content-Type': 'application/json' };
client.putStream(stream, '/test/user.json', headers, function(err, res){
console.log(err);
console.log(res.statusCode);
console.log(res.headers);
});
},

'test .getFile()': function(assert, done){
client.getFile('/test/user.json', function(err, res){
assert.ok(!err);
Expand Down

0 comments on commit fdab959

Please sign in to comment.