示例#1
0
//Private------------------------------------------------------------
function ImgProcessor(filePath, options) {
  options = options || {};
  var self = this;
  var size = options.size || {width: 100, height: 100};
  var roundCorners = options.round;
  var newFile = temp.path({suffix: '.png'});
  var mime = utils.mime.type(newFile);

  gm(filePath)
   .resize(size.width, size.height)
   .write(newFile, function(err) {
       if(!err) {
         if (roundCorners) { 
           roundedCorners(newFile, function(finishFile) {
             self.emit('finish', finishFile, mime);
           }); 
         } else {
           self.emit('finish', newFile, mime);
         }
       } else {
         self.emit('error', err);
         console.log(err);
       }
    });

  return this;
}
示例#2
0
 function processFile(err, string) {
   if (err) { callback(err); return; }
   var headers = {
     "Content-Type": Mime.type(path),
     "Cache-Control": "public, max-age=32000000"
   };
   var buffer = new Buffer(string.length);
   buffer.write(string, 'binary');
   postProcess(headers, buffer, version, path, this);
 },
function assertPadded(res, padded) {
    if (padded) {
        assert.eql(expectPaddedRes, res.body);
        assert.eql(mime.type('.js'), res.headers['content-type']);
        assert.eql(expectPaddedRes.length, res.headers['content-length']);
    
    } else {
        assert.eql(expectRes, res.body);     
    }
}
示例#4
0
http.ServerResponse.prototype.contentType = function(type){
    return this.header('Content-Type', mime.type(type));
};
 res.addListener('end', function() {
     assert.eql(mime.type('.js'), res.headers['content-type']);
     assert.eql('gzip', res.headers['content-encoding']);
     // test compression
     //assert.eql("cb({data: 'data'})", res.body);
 });
 function(res) {
     assert.eql(mime.type('.js'), res.headers['content-type']);
     assert.eql(expect.length, res.headers['content-length']);
 }