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


TypeScript progress-stream.default函数代码示例

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


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

示例1: async

  const extractEntry = async (
    entry: yauzl.Entry,
    err: Error,
    src: NodeJS.ReadableStream
  ) => {
    if (err) {
      throw err;
    }

    const entryPath = join(destination, entry.fileName);
    logger.info(`Extracting ${entryPath}`);

    await sf.mkdirp(dirname(entryPath));
    const dst = createWriteStream(entryPath);
    const progressStream = progress({
      length: entry.uncompressedSize,
      time: 100,
    });
    let progressFactor = entry.compressedSize / zipfile.fileSize;
    progressStream.on("progress", info => {
      opts.onProgress({
        progress: progressOffset + (info.percentage / 100) * progressFactor,
      });
    });
    /****************************************************************************
     * 💩 Crash course in Node Streams 💩
     *
     * Survival tips:
     *
     * 1. pipe() returns the destination stream.
     *    This is so you can chain pipe() calls, lulling you into a false sense of security.
     *
     * 2. If you don't subscribe to the "error" event, ***that's an uncaught exception***,
     *    which takes down the whole app.
     *
     *    It is thrown from what I can only assume is a scheduler, because the error does
     *    not have any stack trace anyway. It doesn't throw in the current function, or reject
     *    the current promise.
     *
     * 3. Whenever a destination stream encounters an error, it will unpipe itself
     *    from its source.
     *
     * 4. Errors do not propagate.
     *
     *    So, if you have A->B->C and C craps out, A->B will still be live and happily
     *    hanging forever once it's filled whatever buffer space it has.
     *
     * 5. Nobody agrees on what the final event is - might be "finish", "close", "end", or "error",
     *    gotta read the docs (and hope the docs are right!)
     *
     * 6. Stream "end"/"finish"/etc. *does* propagate, because in src.pipe(dst, opts?),
     *    opts = {end: true} is the default.
     *
     * 7. If you have A->B->C and A finishes, it doesn't mean C is done. In our case,
     *    A decompresses a zlib stream, B measures progress, and C writes to a file, so
     *    we have to wait for C to be done.
     *
     ***************************************************************************/
    src.pipe(progressStream).pipe(dst);
    await new Promise((_resolve, _reject) => {
      let timeout = setTimeout(() => {
        logger.warn(
          `Extracting a single entry took more than 10 seconds, something's wrong`
        );
      }, 10 * 1000 /* 10 seconds */);
      let resolve = () => {
        clearTimeout(timeout);
        _resolve();
      };
      let reject = (err: Error) => {
        clearTimeout(timeout);
        _reject(err);
      };

      src.on("error", err => {
        logger.warn(`Caught yauzl error: ${err.stack}`);
        reject(err);
      });
      progressStream.on("error", err => {
        logger.warn(`Caught progress stream error: ${err.stack}`);
        reject(err);
      });
      dst.on("error", err => {
        logger.warn(`Caught output stream error: ${err.stack}`);
        reject(err);
      });
      dst.on("finish", () => {
        resolve();
      });
    });

    progressOffset += progressFactor;
    await sf.chmod(entryPath, 0o755);

    const fileBuffer = await sf.readFile(entryPath, { encoding: null });
    const signedHash = crc32.buf(fileBuffer);
    // this converts an int32 to an uint32 (which is what yauzl reports)
    const hash = new Uint32Array([signedHash])[0];
    if (hash !== entry.crc32) {
      await sf.unlink(entryPath);
//.........这里部分代码省略.........
开发者ID:itchio,项目名称:itch,代码行数:101,代码来源:unzip.ts

示例2: progress

 sink: () => {
   progressStream = progress({ length: totalSize, time: 500 });
   progressStream.on("progress", info => {
     onProgress({
       progress: info.percentage / 100,
       eta: info.eta,
       bps: info.speed,
       doneBytes: (info.percentage / 100) * totalSize,
       totalBytes: totalSize,
     });
     logger.info(
       `${info.percentage.toFixed(1)}% done, eta ${info.eta.toFixed(
         1
       )}s @ ${fileSize(info.speed)}/s`
     );
   });
   progressStream.pipe(fileSink);
   return progressStream;
 },
开发者ID:itchio,项目名称:itch,代码行数:19,代码来源:download.ts

示例3: download

        let request = https.get(options, res => {
            // handle redirection
            if (res.statusCode === 302) {
                return download(res.headers.location).then(is => resolve(is)).catch(err => reject(err));
            }
            else if (res.statusCode !== 200) {
                return reject(Error(`Download failed with code ${res.statusCode}.`));
            }
			let len = parseInt(res.headers['content-length'], 10);
			let progressStream = progress({
				length: len,
				time: 500
			});
			downloadProgressItem.text = 'Completing Java installation';
			downloadProgressItem.show();
			progressStream.on('progress', function (progressData) {
				downloadProgressItem.text = 'Completing Java installation ' + Number.parseInt(progressData.percentage) + '%';
			});
            return resolve(res.pipe(progressStream));
        });
开发者ID:silverbulleters,项目名称:vsc-spellchecker,代码行数:20,代码来源:downloadManager.ts

示例4: Error

  const extractEntry = async (entry: yauzl.Entry, err: Error, src: Stream) => {
    if (err) {
      throw err;
    }

    const entryPath = join(destination, entry.fileName);

    await sf.mkdirp(dirname(entryPath));
    const dst = createWriteStream(entryPath);
    const progressStream = progress({
      length: entry.uncompressedSize,
      time: 100,
    });
    let progressFactor = entry.compressedSize / zipfile.fileSize;
    progressStream.on("progress", info => {
      opts.onProgress({
        progress: progressOffset + info.percentage / 100 * progressFactor,
      });
    });
    progressStream.pipe(dst);
    src.pipe(progressStream);
    await sf.promised(dst);
    progressOffset += progressFactor;
    await sf.chmod(entryPath, 0o755);

    const fileBuffer = await sf.readFile(entryPath, { encoding: null });
    const signedHash = crc32.buf(fileBuffer);
    // this converts an int32 to an uint32 (which is what yauzl reports)
    const hash = new Uint32Array([signedHash])[0];
    if (hash !== entry.crc32) {
      await sf.unlink(entryPath);
      throw new Error(
        `CRC32 mismatch for ${entry.fileName}: expected ${
          entry.crc32
        } got ${hash}`
      );
    }
  };
开发者ID:HorrerGames,项目名称:itch,代码行数:38,代码来源:unzip.ts

示例5: require

    return new Promise<any>((resolve, reject) => {

        var p = null;

        if (isUrlLocal(url)) {
            const URL = require('url').Url;
            var localUrl = url;
            if (!localUrl.startsWith("file:/")) {

                localUrl = path.join(path.dirname(previousVersionsLocalPath), new URL().parse(localUrl).path);
            }

            let localPath = new URL().parse(localUrl).path;
            var stat = fs.statSync(localPath);
            var str = fsProgress({
                length: stat.size,
                time: 100 /* ms */
            });

            str.on('progress', function (progress: any) {
                var p: any = {};
                p["percentage"] = progress.percentage / 100;
                progressCallback(p);

                if (progress.percentage >= 100) {
                    progressCallback(1);
                    hash(filePath).then(function (newMd5sum: string) {
                        if (newMd5sum == md5sum) {
                            resolve(filePath);
                        } else {
                            reject("Bad MD5 expected: '" + md5sum + "' got: '" + newMd5sum + "'");
                        }
                    }, function (error: string) {
                        reject(error);
                    });
                }
                /*
                {
                    percentage: 9.05,
                    transferred: 949624,
                    length: 10485760,
                    remaining: 9536136,
                    eta: 42,
                    runtime: 3,
                    delta: 295396,
                    speed: 949624
                }
                */
            });

            p = fs.createReadStream(localPath)
                .pipe(str);


        } else {

            p = progress(request(url))
                .on("progress", function (state: any) {
                    progressCallback(state);
                })
                .on("error", function (error: Error) {
                    reject(error);
                })
                .on("end", function () {
                    progressCallback(1);
                    hash(filePath).then(function (newMd5sum: string) {
                        if (newMd5sum == md5sum) {
                            resolve(filePath);
                        } else {
                            reject("Bad MD5 expected: '" + md5sum + "' got: '" + newMd5sum + "'");
                        }
                    }, function (error: string) {
                        reject(error);
                    });
                });
        }
        p.pipe(fs.createWriteStream(filePath));
    });
开发者ID:into-cps,项目名称:intocps-ui,代码行数:78,代码来源:Downloader.ts


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