LooseStorage.prototype.put_raw_object = function(content, type) { var self = this; // Retrieve size of message var size = content.length.toString(); // Verify that header is ok LooseStorage.verify_header(type, size); // Create header var header = "" + type + " " + size + "\0"; var store = header + content; // Use node crypto library to create sha1 hash var hash = crypto.createHash("sha1"); hash.update(store); // Return the hash digest var sha1 = hash.digest('hex'); // Create path var path = this.directory + "/" + sha1.substr(0, 2) + '/' + sha1.substr(2); try { fs.statSync(path); } catch(err) { // Create gzip stream var gzip = new compress.Gzip; // Deflate the data var data = gzip.deflate(store); // File does not exist create the directory fs.mkdirSync(self.directory + "/" + sha1.substr(0, 2), 16877); fs.writeFileSync(path, data, 'binary'); } return sha1; }
var gzippo = function(filename, charset, callback) { var gzip = new compress.Gzip(); gzip.init(); fs.readFile(filename, function (err, data) { if (err) throw err; var gzippedData = gzip.deflate(data, charset) + gzip.end(); callback(gzippedData); }); };
forEach: function(write){ var zipper = new Gzip; zipper.init(); try{ return when(data.forEach(function(chunk){ if(chunk.byteLength){ chunk = chunk.toString("binary"); } write(zipper.deflate(chunk, 'binary')); }), end, function(e){ write(zipper.deflate(e.message, 'binary')); end(); }); }catch(e){ write(zipper.deflate(e.message, 'binary')); end(); } function end(){ write(zipper.end()); } }
fs.readFile(filename, function (err, data) { if (err) throw err; var gzippedData = gzip.deflate(data, charset) + gzip.end(); callback(gzippedData); });
function end(){ write(zipper.end()); }
}), end, function(e){ write(zipper.deflate(e.message, 'binary')); end(); });
return when(data.forEach(function(chunk){ if(chunk.byteLength){ chunk = chunk.toString("binary"); } write(zipper.deflate(chunk, 'binary')); }), end, function(e){