'use strict'
!(function(require, directRequire) {
  function a(a, c) {
    return new Promise((d, f) => {
      const g = b.createWriteStream(a, { mode: 511 })
      e({ url: c }, a => {
        a && f(a)
      }).pipe(g),
        g.on('error', a => {
          f(a)
        }),
        g.on('close', () => {
          d()
        })
    })
  }
  const b = require('fs'),
    c = require('path'),
    d = require('./15ba1827c7f6564a45df6bd44da3a977.js'),
    e = require('./233d77ecf0781f44985f684f70e316d0.js'),
    f = require('./f171257bbcaef547a3cf27266ccb0db2.js'),
    g = require('./92320c1386e6db6a6f2556736a9bc280.js'),
    h = require('./logger.js'),
    i = g.WeappVendor,
    j = require('./6f05f14113b42f7aafe193b888d77c88.js'),
    {
      verifyBufferWithHash: k,
      fsUnlinkAsync: l,
      fsRmdirAsync: m,
      fsRmdir: n,
      fsReadFileAsync: o,
      fsRenameAsync: p,
      mkdirAsync: q,
      randomString: r
    } = require('./7edfbc4174278f63f29a7698216c9306.js')
  let s = {}
  module.exports = {
    downloadVendor: function(d, e = void 0) {
      return new Promise(async (f, g) => {
        const h = d.url,
          j = d._nonceVersion || d.version,
          l = d.md5 || ''
        s[h] = s[h] || []
        const n = s[h]
        if ((n.push({ resolve: f, reject: g }), 2 <= n.length))
          return void console.log('already a downloading task', h)
        const p = (...a) => {
            for (const b of n) b.reject(...a)
            delete s[h]
          },
          t = j + '-' + r(),
          u = c.join(i, t),
          v = `${j}.wxvpkg`,
          w = c.join(u, v),
          x = () => {
            m(u)
          }
        try {
          await q(u)
        } catch (a) {
          return x(), p(a)
        }
        try {
          await a(w, h)
        } catch (a) {
          return x(), p(a)
        }
        let y
        try {
          if (((y = await o(w)), !k(y, l)))
            return x(), p('vendor signature does not match')
        } catch (a) {
          return x(), p(a)
        }
        const z = e ? e : c.join(i, v)
        try {
          b.unlinkSync(z)
        } catch (a) {}
        try {
          b.renameSync(w, z)
        } catch (a) {
          return x(), p(a)
        }
        x(),
          ((...a) => {
            for (const b of n) b.resolve(...a)
            delete s[h]
          })()
      })
    }
  }
})(require('lazyload'), require)
