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


TypeScript stream.Stream类代码示例

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


在下文中一共展示了Stream类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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:

api.get(async (req: Request, res: Response) => {
    let stream: Stream = await objectModel
        .find({})
        .stream({ transform: JSON.stringify });

    stream.on("data", (doc: Object) => {
        res.write(doc, "ascii");
    }).on("error", (err: Error) => {
        console.log(err);
    }).on("close", () => {
        res.end("Done");
    });
});
开发者ID:vildantursic,项目名称:walter,代码行数:13,代码来源:objects.ts

示例3:

api.get(async (req: Request, res: Response) => {
    let stream: Stream = await complexModel
        .find({})
        .select({_id: 0, name: 1})
        .lean(true)
        .stream({ transform: JSON.stringify });

    stream.on("data", (doc: Object) => {
        res.write(doc, "ascii");
        complexIO.emit("complex", doc);
    }).on("error", (err: Error) => {
        console.log(err);
    }).on("close", () => {
        res.end("Done");
    });
});
开发者ID:vildantursic,项目名称:walter,代码行数:16,代码来源:complexes.ts

示例4: 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

示例5:

api.get(async (req: Request, res: Response) => {
    let stream: Stream = await bimModel
        .find({})
        .lean(true)
        .stream({ transform: JSON.stringify });

    res.type("application/json");

    stream.on("data", (doc: string) => {
        // res.write();
        entityIO.emit("entity", doc);
    }).on("error", (err: Error) => {
        console.log(err);
    }).on("close", () => {
        res.end(JSON.stringify({completed: true}));
    });
});
开发者ID:vildantursic,项目名称:walter,代码行数:17,代码来源:bim.ts

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10:

 stream.on('metadata', metadata => {
   // Create a response object with succeeds.
   // TODO: unify this logic with the decoration of gRPC response when it's
   // added. see: https://github.com/googleapis/gax-nodejs/issues/65
   stream.emit('response', {
     code: 200,
     details: '',
     message: 'OK',
     metadata,
   });
 });
开发者ID:googleapis,项目名称:gax-nodejs,代码行数:11,代码来源:streaming.ts


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