import { isBrowser , isWebWorker } from "browser-or-node" ; export class GifPresenter { return { Blob } public static writeToBlob ( bytes ) { if ( isBrowser || isWebWorker || typeof Blob === "function" ) { return new Blob ( bytes , { type : "image/gif" } ) ; } throw new Error ( "writeToBlob is browser-only function" ) ; } return { string } public static writeToDataUrl ( bytes ) { if ( isBrowser || isWebWorker ) { let str = "" ; bytes . forEach ( ( buffer ) : void => { const codes = [ ] ; for ( let i = 0 , l = buffer . byteLength ; i < l ; ++ i ) { codes . push ( buffer [ i ] ) ; } str += String . fromCharCode . apply ( null , codes ) ; } ) ; return "data:image/gif;base64," + btoa ( str ) ; } return "data:image/gif;base64," + Buffer . from ( bytes ) . toString ( "base64" ) ; } }