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


TypeScript Stream.on方法代碼示例

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


在下文中一共展示了Stream.on方法的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: 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

示例3:

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

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

示例5: Promise

 return new Promise(function(resolve, reject) {
   var results = [];
   stream
     .on('data', function(result) {
       results.push(result);
     })
     .on('end', function() {
       resolve(
         Buffer.isBuffer(results[0])
           ? Buffer.concat(results).toString()
           : results
       );
     })
     .on('error', reject);
 });
開發者ID:jpdjere,項目名稱:MinCyT,代碼行數:15,代碼來源:to-promise.ts

示例6:

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

示例7:

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

示例8: forwardEvents

  /**
   * Forward events from an API request stream to the user's stream.
   * @param {Stream} stream - The API request stream.
   */
  forwardEvents(stream: Stream) {
    const eventsToForward = ['metadata', 'response', 'status'];

    eventsToForward.forEach(event => {
      stream.on(event, this.emit.bind(this, event));
    });

    // We also want to supply the status data as 'response' event to support
    // the behavior of google-cloud-node expects.
    // see:
    // https://github.com/GoogleCloudPlatform/google-cloud-node/pull/1775#issuecomment-259141029
    // https://github.com/GoogleCloudPlatform/google-cloud-node/blob/116436fa789d8b0f7fc5100b19b424e3ec63e6bf/packages/common/src/grpc-service.js#L355
    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,代碼行數:28,代碼來源:streaming.ts

示例9:

 eventsToForward.forEach(event => {
   stream.on(event, this.emit.bind(this, event));
 });
開發者ID:googleapis,項目名稱:gax-nodejs,代碼行數:3,代碼來源:streaming.ts

示例10: resolve

	return new Promise<void>((resolve) => {
		s.on('end', () => resolve());
	})
開發者ID:hbenl,項目名稱:vscode-firefox-debug,代碼行數:3,代碼來源:sourceMapUtil.ts


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