Beispiel #1
0
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;
}
Beispiel #2
0
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);
	});
};
Beispiel #3
0
						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());
							}
						}
Beispiel #4
0
	fs.readFile(filename, function (err, data) {
		if (err) throw err;
		var gzippedData = gzip.deflate(data, charset) + gzip.end();
		callback(gzippedData);
	});
Beispiel #5
0
							function end(){
								write(zipper.end());
							}
Beispiel #6
0
								}), end, function(e){
									write(zipper.deflate(e.message, 'binary'));
									end();
								});
Beispiel #7
0
								return when(data.forEach(function(chunk){
									if(chunk.byteLength){
										chunk = chunk.toString("binary");
									}
									write(zipper.deflate(chunk, 'binary'));
								}), end, function(e){