import m from"path";import l from"fs";import b from"url";import{pipeline as u}from"stream/promises";import{g as d}from"./got-BLig4ziO.mjs";import"./_commonjsHelpers-CLLqo0NO.mjs";import"events";import"util";import"stream";import"http";import"https";import"dns";import"os";import"buffer";import"zlib";import"http2";import"tls";import"net";import"./constants-DED7MIJj.mjs";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};e.SENTRY_RELEASE={id:"4.2.860"}}catch{}})();try{(function(){var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="d7ff52db-70c6-4e29-bc44-1ee370d00eb3",e._sentryDebugIdIdentifier="sentry-dbid-d7ff52db-70c6-4e29-bc44-1ee370d00eb3")})()}catch{}function y(e){if(!/^data:/i.test(e))throw new TypeError('`uri` does not appear to be a Data URI (must begin with "data:")');e=e.replace(/\r?\n/g,"");const t=e.indexOf(",");if(t===-1||t<=4)throw new TypeError("malformed data: URI");const o=e.substring(5,t).split(";");let r="",i=!1;const a=o[0]||"text/plain";let s=a;for(let n=1;n<o.length;n++)o[n]==="base64"?i=!0:o[n]&&(s+=`;${o[n]}`,o[n].indexOf("charset=")===0&&(r=o[n].substring(8)));!o[0]&&!r.length&&(s+=";charset=US-ASCII",r="US-ASCII");const p=i?"base64":"ascii",c=unescape(e.substring(t+1)),f=Buffer.from(c,p);return f.type=a,f.typeFull=s,f.charset=r,f}async function g(e,t,o){const r=m.join(t,o);if(e.protocol==="file:")await l.promises.copyFile(b.fileURLToPath(e),r);else if(e.protocol==="data:"){const i=y(e.href);await l.promises.writeFile(r,i)}else try{await u(d.stream(e),l.createWriteStream(r))}catch(i){if(i.code==="ERR_INVALID_PROTOCOL"){logger.error(i);const a=await d.head(e,{followRedirect:!1});return g(new URL(a.headers.location.replace("fileproxy://","file://")),t,o)}throw i}return r}export{g as downloadFile};
//# sourceMappingURL=download-C2kdRpx0.mjs.map
