當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Stream.pipe方法代碼示例

本文整理匯總了TypeScript中stream.Stream.pipe方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Stream.pipe方法的具體用法?TypeScript Stream.pipe怎麽用?TypeScript Stream.pipe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在stream.Stream的用法示例。


在下文中一共展示了Stream.pipe方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: Promise

      transform?: FileTransform) => new Promise((resolve, reject) => {
    if (projectOptions.root === undefined) {
      throw new Error('projectOptions.root is undefined');
    }
    root = projectOptions.root;
    const config = new ProjectConfig(projectOptions);
    const analyzer = new BuildAnalyzer(config);

    bundler = new BuildBundler(config, analyzer, bundlerOptions);
    bundledStream = mergeStream(analyzer.sources(), analyzer.dependencies());
    if (transform) {
      bundledStream = bundledStream.pipe(transform);
    }
    bundledStream = bundledStream.pipe(bundler);
    bundler = new BuildBundler(config, analyzer);
    files = new Map<LocalFsPath, File>();
    bundledStream.on('data', (file: File) => {
      files.set(file.path, file);
    });
    bundledStream.on('end', () => {
      resolve(files);
    });
    bundledStream.on('error', (err: Error) => {
      reject(err);
    });
  });
開發者ID:MehdiRaash,項目名稱:tools,代碼行數:26,代碼來源:bundle_test.ts

示例2: lint

    lint(html: string|Stream): Promise<Issue[]> {

        var parser: SAXParser = new SAXParser({ locationInfo: true });
        var parseState: ParseState = new ParseState(this.scopes, this.voids);
        
        parseState.initPreRules(parser);

        let rules = this.rules;

        rules.forEach((rule) => {
            rule.init(parser, parseState);
        });

        parseState.initPostRules(parser);

        var work:SAXParser;

        if(typeof(html) === 'string')
        {
            var stream: Readable = new Readable();
            stream.push(html);
            stream.push(null);
            work = stream.pipe(parser);
        }else if(this.isStream(html))
        {
            work = html.pipe(parser);
        }
        else{
            throw new Error("html isn't pipeable");
        }

        var completed = new Promise<void>(function (resolve, reject) {
            work.on("end", () => {
                parseState.finalise();
                resolve();
            });
        });

        var ruleTasks = [];

        rules.forEach((rule) => {
            let task = completed.then(() => {
                return rule.finalise();
            });
            ruleTasks.push(task);
        });

        return Promise.all(ruleTasks).then(results => {

            var all = new Array<Issue>();

            results.forEach(parts => {
                all = all.concat(parts);
            });

            return all;
        });
    }
開發者ID:atsu85,項目名稱:template-lint,代碼行數:58,代碼來源:linter.ts

示例3: rawRequest

			req = rawRequest(opts, (res: http.IncomingMessage) => {
				const followRedirects: number = isNumber(options.followRedirects) ? options.followRedirects : 3;
				if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && followRedirects > 0 && res.headers['location']) {
					request(assign({}, options, {
						url: res.headers['location'],
						followRedirects: followRedirects - 1
					}), token).then(c, e);
				} else {
					let stream: Stream = res;

					if (res.headers['content-encoding'] === 'gzip') {
						stream = stream.pipe(createGunzip());
					}

					c({ res, stream } as IRequestContext);
				}
			});
開發者ID:donaldpipowitch,項目名稱:vscode,代碼行數:17,代碼來源:request.ts

示例4: rawRequest

			req = rawRequest(opts, (res: http.ClientResponse) => {
				const followRedirects = isNumber(options.followRedirects) ? options.followRedirects : 3;
				if (res.statusCode >= 300 && res.statusCode < 400 && followRedirects > 0 && res.headers['location']) {
					request(assign({}, options, {
						url: res.headers['location'],
						followRedirects: followRedirects - 1
					})).done(c, e);
				} else {
					let stream: Stream = res;

					if (res.headers['content-encoding'] === 'gzip') {
						stream = stream.pipe(createGunzip());
					}

					c({ res, stream });
				}
			});
開發者ID:JarnoNijboer,項目名稱:vscode,代碼行數:17,代碼來源:request.ts

示例5: lint

  lint(html: string | Stream, path?: string): Promise<Issue[]> {
    var parser = this.parserBuilder.build();
    parser.init(this.rules, this.ast, path);

    if (typeof (html) === 'string') {
      var stream: Readable = new Readable();
      stream.push(html);
      stream.push(null);
      stream.pipe(parser);
    } else if (this.isStream(html)) {
      html.pipe(parser);
    }
    else {
      throw new Error("html isn't pipeable");
    }

    var completed = new Promise<void>(function (resolve, reject) {
      parser.on("end", () => {
        parser.finalise();
        resolve();
      });
    });

    var ruleTasks = [];

    this.rules.forEach((rule) => {
      let task = completed.then(() => {
        return rule.finalise(this.ast.root);
      });
      ruleTasks.push(task);
    });

    return Promise.all(ruleTasks).then(results => {

      var all = new Array<Issue>();

      results.forEach(parts => {
        all = all.concat(parts);
      });

      all = all.sort((a, b) => (a.line - b.line) * 1000 + (a.column - b.column));

      return all;
    });
  }
開發者ID:MeirionHughes,項目名稱:template-lint,代碼行數:45,代碼來源:linter.ts

示例6: request

	return request(options).then(result => new TPromise<IXHRResponse>((c, e, p) => {
		const res = result.res;
		let stream: Stream = res;

		if (res.headers['content-encoding'] === 'gzip') {
			stream = stream.pipe(createGunzip());
		}

		const data: string[] = [];
		stream.on('data', c => data.push(c));
		stream.on('end', () => {
			const status = res.statusCode;

			if (options.followRedirects > 0 && (status >= 300 && status <= 303 || status === 307)) {
				let location = res.headers['location'];
				if (location) {
					let newOptions = {
						type: options.type, url: location, user: options.user, password: options.password, responseType: options.responseType, headers: options.headers,
						timeout: options.timeout, followRedirects: options.followRedirects - 1, data: options.data
					};
					xhr(newOptions).done(c, e, p);
					return;
				}
			}

			const response: IXHRResponse = {
				responseText: data.join(''),
				status,
				getResponseHeader: header => res.headers[header],
				readyState: 4
			};

			if ((status >= 200 && status < 300) || status === 1223) {
				c(response);
			} else {
				e(response);
			}
		});
	}, err => {
開發者ID:1833183060,項目名稱:vscode,代碼行數:39,代碼來源:rawHttpService.ts

示例7: async

  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

示例8: onEnd

			const send = (size: number, data: string | Stream | null) => {
				response.writeHead(200, {
					'Content-Type': contentType,
					'Content-Length': size
				});

				if (!data) {
					response.end();
					return;
				}

				if (typeof data === 'string') {
					response.end(data, onEnd);
				} else {
					data.on('end', () => onEnd());
					data.on('error', (error: Error) => {
						onEnd(error);
						// If the read stream errors, the write stream has to be
						// manually closed
						response.end();
					});
					data.pipe(response);
				}
			};
開發者ID:jason0x43,項目名稱:intern,代碼行數:24,代碼來源:Server.ts


注:本文中的stream.Stream.pipe方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。