nodeca / probe-image-size

Get image size without full download. Supported image types: JPG, GIF, PNG, WebP, BMP, TIFF, SVG, PSD, ICO.
MIT License
988 stars 77 forks source link

Add response headers to response #24

Closed qsniyg closed 6 years ago

qsniyg commented 6 years ago

The way I implemented it was like this (in stream.js):

function resolve1(data) {
  data.headers = stream.headers;
  resolve(data);
}
...
pStream.once('data', resolve1);

This is very useful for my use case, where I need to know various other headers as well as just the size.

puzrin commented 6 years ago

I'd like to keep output data clean. IMHO, code is very modular and you can make your own custom http wrapper with minimal efforts.

qsniyg commented 6 years ago

you can make your own custom http wrapper with minimal efforts

How exactly would I do this? I've looked through the source code, but I haven't found any way to do this, other than by modifying the library itself.

puzrin commented 6 years ago
  1. Copy existing http.js into your project.
  2. Update relative requires to something like require('probe-image-size/stream') (replace . with probe-image-size)
  3. Add your custom modifications.
  4. Use your modified file instead of library.