Пример #1
0
 self._zip.stream(prop, function(err, stream) {
     if ( err) self._callError(err);
     var imageSizeStream = ImageSizeStream()
     .on('size', function(dimensions) {
         self._data.images[index].mimeType =  mime.lookup(dimensions.type);
         self._data.images[index].width = dimensions.width;
         self._data.images[index].height = dimensions.height;
     });
     stream.pipe(imageSizeStream);
     self._archive.entry(stream, { name: path.join(self._model.imagePath,name) , date: self._date}, function(err) {
         index++;
         if ( err) self._callError(err);
         cb();
     });
 });
Пример #2
0
  return new Promise(function(resolve, reject){
    var size = createImageSizeStream();

    var request = http.get(url, function(response) {
      response.pipe(size);
    });

    size.on('size', function(dimensions) {
      resolve(dimensions);
      request.abort();
    }).on('error', function(err) {
      reject(err);
    });

  });
Пример #3
0
 q.push(function(cb) {
     var name = path.join(self._model.imagePath,image);
     var content = fs.createReadStream(path.join(self._comic,image));
     var imageSizeStream = ImageSizeStream({limit:256*1024})
     .on('size', function(dimensions) {
         self._data.images[cIndex].mimeType =  mime.lookup(dimensions.type);
         self._data.images[cIndex].width = dimensions.width;
         self._data.images[cIndex].height = dimensions.height;
     })
     .on('error', function(err) {
         throw err;
     });
     content.pipe(imageSizeStream);
     self._archive.entry(content, { name: name , date: self._date}, function(err) {
         if ( err) self._callError(err);
         cb();
     });
 })
Пример #4
0
module.exports = function httpImageSizePromise(url, options) {
  var proxy;
  var size = imageSizeStream(options);

  return wrapPromise(function(resolve, reject) {
    size
      .on('error', function(err) {
        proxy.destroy();
        reject(err);
      })
      .on('size', function(dimensions) {
        proxy.destroy();
        resolve(dimensions);
      });

    proxy = got(url, options)
      .on('error', reject)
      .pipe(size);
  });
};