当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript fs-extra-p.createWriteStream函数代码示例

本文整理汇总了TypeScript中fs-extra-p.createWriteStream函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createWriteStream函数的具体用法?TypeScript createWriteStream怎么用?TypeScript createWriteStream使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了createWriteStream函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: BluebirdPromise

 await new BluebirdPromise((resolve, reject) => {
   const rd = createReadStream(path.join(appImagePath, arch === Arch.ia32 ? "32" : "64", "runtime"))
   rd.on("error", reject)
   const wr = createWriteStream(image)
   wr.on("error", reject)
   wr.on("finish", resolve)
   rd.pipe(wr)
 })
开发者ID:reactsnipp,项目名称:electron-builder,代码行数:8,代码来源:appImage.ts

示例2: Promise

 return new Promise((resolve, reject) => {
   const reader = createReadStream(src)
   const writer = createWriteStream(dest, stats == null ? undefined : {mode: stats!!.mode})
   reader.on("error", reject)
   writer.on("error", reject)
   writer.on("open", () => {
     reader.pipe(writer)
   })
   writer.once("close", resolve)
 })
开发者ID:electron-userland,项目名称:electron-builder,代码行数:10,代码来源:fs.ts

示例3: buildInstaller

export async function buildInstaller(options: SquirrelOptions, outputDirectory: string, setupExe: string, packager: WinPackager, appOutDir: string) {
  const appUpdate = await packager.getTempFile("Update.exe")
  await BluebirdPromise.all([
    copy(path.join(options.vendorPath, "Update.exe"), appUpdate)
      .then(() => packager.sign(appUpdate)),
    BluebirdPromise.all([remove(`${outputDirectory.replace(/\\/g, "/")}/*-full.nupkg`), remove(path.join(outputDirectory, "RELEASES"))])
      .then(() => ensureDir(outputDirectory))
  ])

  if (options.remoteReleases) {
    await syncReleases(outputDirectory, options)
  }

  const embeddedArchiveFile = await packager.getTempFile("setup.zip")
  const embeddedArchive = archiver("zip", {zlib: {level: options.packageCompressionLevel == null ? 6 : options.packageCompressionLevel}})
  const embeddedArchiveOut = createWriteStream(embeddedArchiveFile)
  const embeddedArchivePromise = new BluebirdPromise(function (resolve, reject) {
    embeddedArchive.on("error", reject)
    embeddedArchiveOut.on("close", resolve)
  })
  embeddedArchive.pipe(embeddedArchiveOut)

  embeddedArchive.file(appUpdate, {name: "Update.exe"})
  embeddedArchive.file(options.loadingGif ? path.resolve(options.loadingGif) : path.join(__dirname, "..", "..", "templates", "install-spinner.gif"), {name: "background.gif"})

  const version = convertVersion(options.version)
  const packageName = `${options.name}-${version}-full.nupkg`
  const nupkgPath = path.join(outputDirectory, packageName)
  const setupPath = path.join(outputDirectory, setupExe || `${options.name || options.productName}Setup.exe`)

  await BluebirdPromise.all<any>([
    pack(options, appOutDir, appUpdate, nupkgPath, version, options.packageCompressionLevel),
    copy(path.join(options.vendorPath, "Setup.exe"), setupPath),
  ])

  embeddedArchive.file(nupkgPath, {name: packageName})

  const releaseEntry = await releasify(options, nupkgPath, outputDirectory, packageName)

  embeddedArchive.append(releaseEntry, {name: "RELEASES"})
  embeddedArchive.finalize()
  await embeddedArchivePromise

  const writeZipToSetup = path.join(options.vendorPath, "WriteZipToSetup.exe")
  await execWine(writeZipToSetup, [setupPath, embeddedArchiveFile])

  await packager.signAndEditResources(setupPath)
  if (options.msi && process.platform === "win32") {
    const outFile = setupExe.replace(".exe", ".msi")
    await msi(options, nupkgPath, setupPath, outputDirectory, outFile)
    // rcedit can only edit .exe resources
    await packager.sign(path.join(outputDirectory, outFile))
  }
}
开发者ID:heinzbeinz,项目名称:electron-builder,代码行数:54,代码来源:squirrelPack.ts

示例4: downloadFile

  private async downloadFile(tasks: Array<Operation>): Promise<any> {
    const signature = this.signatureSize === 0 ? null : await this.readRemoteBytes(0, this.signatureSize - 1)

    const oldFileFd = await open(this.options.oldFile, "r")
    const newFileFd = await open(this.options.newFile, "w")
    const fileOut = createWriteStream(this.options.newFile, {fd: newFileFd})
    await new BluebirdPromise((resolve, reject) => {
      const streams: Array<any> = []
      const digestTransform = new DigestTransform(this.blockAwareFileInfo.sha512)
      // to simply debug, do manual validation to allow file to be fully written
      digestTransform.isValidateOnEnd = false
      streams.push(digestTransform)

      // noinspection JSArrowFunctionCanBeReplacedWithShorthand
      fileOut.on("finish", () => {
        (fileOut.close as any)(() => {
          try {
            digestTransform.validate()
          }
          catch (e) {
            reject(e)
            return
          }

          resolve()
        })
      })

      streams.push(fileOut)

      let lastStream = null
      for (const stream of streams) {
        stream.on("error", reject)
        if (lastStream == null) {
          lastStream = stream
        }
        else {
          lastStream = lastStream.pipe(stream)
        }
      }

      const firstStream = streams[0]

      let w: any
      if (this.options.useMultipleRangeRequest) {
        w = executeTasks(this, tasks, firstStream, oldFileFd, reject)
      }
      else {
        let attemptCount = 0
        let actualUrl: string | null = null
        this.logger.info(`Differential download: ${this.options.newUrl}`)
        w = (index: number) => {
          if (index >= tasks.length) {
            if (this.fileMetadataBuffer != null) {
              firstStream.write(this.fileMetadataBuffer)
            }
            firstStream.end()
            return
          }

          const operation = tasks[index++]
          if (operation.kind === OperationKind.COPY) {
            copyData(operation, firstStream, oldFileFd, reject, () => w(index))
          }
          else {
            const requestOptions = this.createRequestOptions("get", actualUrl)
            const range = `bytes=${operation.start}-${operation.end - 1}`
            requestOptions.headers!!.Range = range;
            (requestOptions as any).redirect = "manual"

            const debug = this.logger.debug
            if (debug != null) {
              debug(`effective url: ${actualUrl == null ? "" : removeQuery(actualUrl)}, range: ${range}`)
            }

            const request = this.httpExecutor.doRequest(requestOptions, response => {
              // Electron net handles redirects automatically, our NodeJS test server doesn't use redirects - so, we don't check 3xx codes.
              if (response.statusCode >= 400) {
                reject(createHttpError(response))
              }

              response.pipe(firstStream, {
                end: false
              })
              response.once("end", () => {
                if (++attemptCount === 100) {
                  attemptCount = 0
                  setTimeout(() => w(index), 1000)
                }
                else {
                  w(index)
                }
              })
            })
            request.on("redirect", (statusCode: number, method: string, redirectUrl: string) => {
              this.logger.info(`Redirect to ${removeQuery(redirectUrl)}`)
              actualUrl = redirectUrl
              request.followRedirect()
            })
            this.httpExecutor.addErrorAndTimeoutHandlers(request, reject)
//.........这里部分代码省略.........
开发者ID:ledinhphuong,项目名称:electron-builder,代码行数:101,代码来源:DifferentialDownloader.ts

示例5: pack

async function pack(options: SquirrelOptions, directory: string, updateFile: string, outFile: string, version: string, packager: WinPackager) {
  const archive = archiver("zip", {zlib: {level: options.packageCompressionLevel == null ? 9 : options.packageCompressionLevel}})
  const archiveOut = createWriteStream(outFile)
  const archivePromise = new BluebirdPromise((resolve, reject) => {
    archive.on("error", reject)
    archiveOut.on("error", reject)
    archiveOut.on("close", resolve)
  })
  archive.pipe(archiveOut)

  const author = options.authors
  const copyright = options.copyright || `Copyright Š ${new Date().getFullYear()} ${author}`
  const nuspecContent = `<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
  <metadata>
    <id>${options.appId}</id>
    <version>${version}</version>
    <title>${options.productName}</title>
    <authors>${author}</authors>
    <iconUrl>${options.iconUrl}</iconUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>${options.description}</description>
    <copyright>${copyright}</copyright>${options.extraMetadataSpecs || ""}
  </metadata>
</package>`
  debug(`Created NuSpec file:\n${nuspecContent}`)
  archive.append(nuspecContent.replace(/\n/, "\r\n"), {name: `${encodeURI(options.name).replace(/%5B/g, "[").replace(/%5D/g, "]")}.nuspec`})

  //noinspection SpellCheckingInspection
  archive.append(`<?xml version="1.0" encoding="utf-8"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
  <Relationship Type="http://schemas.microsoft.com/packaging/2010/07/manifest" Target="/${options.name}.nuspec" Id="Re0" />
  <Relationship Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="/package/services/metadata/core-properties/1.psmdcp" Id="Re1" />
</Relationships>`.replace(/\n/, "\r\n"), {name: ".rels", prefix: "_rels"})

  //noinspection SpellCheckingInspection
  archive.append(`<?xml version="1.0" encoding="utf-8"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
  <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />
  <Default Extension="nuspec" ContentType="application/octet" />
  <Default Extension="pak" ContentType="application/octet" />
  <Default Extension="asar" ContentType="application/octet" />
  <Default Extension="bin" ContentType="application/octet" />
  <Default Extension="dll" ContentType="application/octet" />
  <Default Extension="exe" ContentType="application/octet" />
  <Default Extension="dat" ContentType="application/octet" />
  <Default Extension="psmdcp" ContentType="application/vnd.openxmlformats-package.core-properties+xml" />
  <Default Extension="diff" ContentType="application/octet" />
  <Default Extension="bsdiff" ContentType="application/octet" />
  <Default Extension="shasum" ContentType="text/plain" />
  <Default Extension="mp3" ContentType="audio/mpeg" />
  <Default Extension="node" ContentType="application/octet" />
</Types>`.replace(/\n/, "\r\n"), {name: "[Content_Types].xml"})

  archive.append(`<?xml version="1.0" encoding="utf-8"?>
<coreProperties xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns="http://schemas.openxmlformats.org/package/2006/metadata/core-properties">
  <dc:creator>${author}</dc:creator>
  <dc:description>${options.description}</dc:description>
  <dc:identifier>${options.appId}</dc:identifier>
  <version>${version}</version>
  <keywords/>
  <dc:title>${options.productName}</dc:title>
  <lastModifiedBy>NuGet, Version=2.8.50926.602, Culture=neutral, PublicKeyToken=null;Microsoft Windows NT 6.2.9200.0;.NET Framework 4</lastModifiedBy>
</coreProperties>`.replace(/\n/, "\r\n"), {name: "1.psmdcp", prefix: "package/services/metadata/core-properties"})

  archive.file(updateFile, {name: "Update.exe", prefix: "lib/net45"})
  await encodedZip(archive, directory, "lib/net45", options.vendorPath, packager)
  await archivePromise
}
开发者ID:yuya-oc,项目名称:electron-builder,代码行数:70,代码来源:squirrelPack.ts

示例6: createWriteStream

 .then(() => {
   const downloadStream = createWriteStream(destination)
   response.pipe(downloadStream)
   downloadStream.on("finish", () => downloadStream.close(callback))
 })
开发者ID:MatthijsvandenBosch,项目名称:electron-builder,代码行数:5,代码来源:httpRequest.ts

示例7: BluebirdPromise

    await new BluebirdPromise((resolve, reject) => {
      const streams: Array<any> = []
      const digestTransform = new DigestTransform(this.packageInfo.sha512)
      // to simply debug, do manual validation to allow file to be fully written
      digestTransform.isValidateOnEnd = false
      streams.push(digestTransform)

      const fileOut = createWriteStream(this.options.packagePath)
      fileOut.on("finish", () => {
        (fileOut.close as any)(() => {
          try {
            digestTransform.validate()
          }
          catch (e) {
            reject(e)
            return
          }

          resolve()
        })
      })

      streams.push(fileOut)

      let lastStream = null
      for (const stream of streams) {
        stream.on("error", reject)
        if (lastStream == null) {
          lastStream = stream
        }
        else {
          lastStream = lastStream.pipe(stream)
        }
      }

      const firstStream = streams[0]

      const w = (index: number) => {
        if (index >= operations.length) {
          firstStream.end(this.fileMetadataBuffer)
          return
        }

        const operation = operations[index++]

        if (operation.kind === OperationKind.COPY) {
          const readStream = createReadStream(this.options.oldPackageFile, {
            fd: oldFileFd,
            autoClose: false,
            start: operation.start,
            // end is inclusive
            end: operation.end - 1,
          })
          readStream.on("error", reject)
          readStream.once("end", () => w(index))
          readStream.pipe(firstStream, {
            end: false
          })
        }
        else {
          // https://github.com/electron-userland/electron-builder/issues/1523#issuecomment-327084661
          // todo to reduce http requests we need to consolidate non sequential download operations (Multipart ranges)
          const requestOptions = this.createRequestOptions("get")
          requestOptions.headers!!.Range = `bytes=${operation.start}-${operation.end - 1}`
          const request = this.httpExecutor.doRequest(requestOptions, response => {
            // Electron net handles redirects automatically, our NodeJS test server doesn't use redirects - so, we don't check 3xx codes.
            if (response.statusCode >= 400) {
              reject(new HttpError(response))
            }

            response.pipe(firstStream, {
              end: false
            })
            response.once("end", () => w(index))
          })
          this.httpExecutor.addErrorAndTimeoutHandlers(request, reject)
          request.end()
        }
      }

      firstStream.write(signature, () => w(0))
    })
开发者ID:jwheare,项目名称:electron-builder,代码行数:82,代码来源:differentialPackage.ts


注:本文中的fs-extra-p.createWriteStream函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。