import path from "path" ; import { ExifToolTask } from "./ExifToolTask" ; import { Maybe } from "./Maybe" ; import { toS } from "./String" ; const StdoutRe = /\b(\d+) output files? created/i ; /**
 * Task that returns an error string (to prevent retries), or undefined if
 * everything seems to have worked.
 */ export class BinaryExtractionTask extends ExifToolTask < Maybe < string > > { private constructor ( args ) { super ( args ) ; } static for ( tagname , imgSrc , imgDest ) { const args = [ "-b" , "-" + tagname , path . resolve ( imgSrc ) , "-w" , "%0f" + path . resolve ( imgDest ) , ] ; return new BinaryExtractionTask ( args ) ; } parse ( stdout , err ? ) { const s = toS ( stdout ) . trim ( ) ; const m = StdoutRe . exec ( s ) ; if ( err != null ) { throw err ; } else if ( m == null ) { throw new Error ( "Missing expected status message (got " + stdout + ")" ) ; } else if ( m [ 1 ] === "1" ) { return ; } else { return s ; } } }