I'm trying to use the Manta's Node.js SDK, from Joyent, to write a file from a readable stream.
The example given on the webpage is this:
var MemoryStream = require('memorystream');
var message = 'Hello World'
var opts = {
copies: 3,
headers: {
'access-control-allow-origin': '*',
'access-control-allow-methods': 'GET'
},
md5: crypto.createHash('md5').update(message).digest('base64'),
size: Buffer.byteLength(message),
type: 'text/plain'
};
var stream = new MemoryStream();
var w = client.createWriteStream('/jill/stor/hello_world.txt', opts);
stream.pipe(w);
w.once('close', function (res) {
console.log('all done');
});
stream.end(message);
But this is the case were we use a writeStream to put a file/object/string already into the program, what if I want to pass a readable stream to be written, like this?
function saveCopyToManta(cb){
var stream = fs.createReadStream('/tmp/' + filename);
var opts = {
copies: 3,
headers: {
'access-control-allow-origin': '*',
'access-control-allow-methods': 'GET'
},
md5: crypto.createHash('md5').update(message).digest('base64'),
size: filesize,
type: 'text/plain'
};
client.put('/someuser/stor/logs/+filename, stream, opts, function (err) {
if(err) cb(err);
else cb();
});
};
What should I do for this to work, regarding this line:
md5: crypto.createHash('md5').update(message).digest('base64'),
Thank you