You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to have exifr.parse function on a buffer that just contains exif data rather than a whole file?
I'm currently relying on Sharp to gather some file metadata (like width/height/orientation), and would like to use Exifr to (optionally) parse the Exif information if Sharp returns it. I do not have a Buffer with the full file contents available (nor am I able to get it), so I was hoping I could stream the file to sharp, have sharp prepare an Exif buffer, and parse that out with Exifr.
For example:
import{createReadStream}from'node:fs';import{pipeline}from'node:stream/promises';importsharpfrom'sharp';import{parse}from'exifr';conststream=createReadStream('./path/to/large/file.jpg');constgetMetadata=(stream)=>newPromise((resolve,reject)=>{pipeline(stream,sharp().metadata(async(err,sharpMetadata)=>{if(err)returnreject(err);// Do stuff with sharp metadataif(sharpMetadata.exif){constexifData=awaitparse(sharpMetadata.exif);// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}// etc});});
At the moment, the highlighted section errors with an error: Error: Unknown file format, which I believe stems from the fact that exifr expects the buffer to contain all file data, rather than just the exif information.
The text was updated successfully, but these errors were encountered:
For now, we might be able to extend the Exifr class and inject the corresponding parser manually (based on image type detected by sharp).
Super dirty examplary code:
import{Exifr}from'exifr';constformatMap={jpeg: 'JpegFileParser'// ...};classCustomExifrextendsExifr{constructor(parser,options){this.fileParser=parser;super(options);}}// sharp stuffif(sharpMetadata.exif){constparserType=formatMap[sharpMetadata.format];if(parserType){// try...catchconstParser=(awaitimport(`exifr/file-parsers/${sharpMetadata.format}`)).[parserType];constexifr=newCustomExifr(newParser(/* <need to look into parser options> */),exifrOptions);awaitexifr.read(sharpMetadata.exif);constexifData=awaitexifr.parse();//}//}//
No idea whether a) those classes are indeed exported and available b) this would be sufficient or still too few / wrong data for exifr to process...
Obivously, if this approach would work and with the agreement of @MikeKovarik, we could then handle this in exifr itself (happy to come up with a PR in that case).
Heya!
Is it possible to have
exifr.parse
function on a buffer that just contains exif data rather than a whole file?I'm currently relying on Sharp to gather some file metadata (like width/height/orientation), and would like to use Exifr to (optionally) parse the Exif information if Sharp returns it. I do not have a Buffer with the full file contents available (nor am I able to get it), so I was hoping I could stream the file to sharp, have sharp prepare an Exif buffer, and parse that out with Exifr.
For example:
At the moment, the highlighted section errors with an error:
Error: Unknown file format
, which I believe stems from the fact that exifr expects the buffer to contain all file data, rather than just the exif information.The text was updated successfully, but these errors were encountered: