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


TypeScript Readable.on方法代码示例

本文整理汇总了TypeScript中stream.Readable.on方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Readable.on方法的具体用法?TypeScript Readable.on怎么用?TypeScript Readable.on使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stream.Readable的用法示例。


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

示例1: error

	return new Promise<Buffer>((complete, error) => {
		let done = false;
		let buffer = Buffer.allocUnsafe(bytes);
		let bytesRead = 0;

		stream.on('data', (data: Buffer) => {
			let bytesToRead = Math.min(bytes - bytesRead, data.length);
			data.copy(buffer, bytesRead, 0, bytesToRead);
			bytesRead += bytesToRead;

			if (bytesRead === bytes) {
				(stream as any).destroy(); // Will trigger the close event eventually
			}
		});

		stream.on('error', (e: Error) => {
			if (!done) {
				done = true;
				error(e);
			}
		});

		stream.on('close', () => {
			if (!done) {
				done = true;
				complete(buffer.slice(0, bytesRead));
			}
		});
	});
开发者ID:KTXSoftware,项目名称:KodeStudio,代码行数:29,代码来源:util.ts

示例2: Promise

 return new Promise(resolve => {
   let result: string = "";
   stream.on("data", (chunk: Buffer) => {
     result += chunk.toString();
   });
   stream.on("end", () => {
     resolve(result);
   });
 });
开发者ID:nkjm,项目名称:line-bot-sdk-nodejs,代码行数:9,代码来源:stream.ts

示例3: resolve

 return new Promise<string>((resolve, reject) => {
     let data = [];
     stream.on('data', (chunk) => { 
         data.push(chunk); 
     });
     stream.on('end', () => {
         resolve(Buffer.concat(data).toString());
     });
     stream.on('error', (error) => {
         reject(error);
     });
 });
开发者ID:edupsousa,项目名称:node-termux-api,代码行数:12,代码来源:ApiResult.ts

示例4: function

 return Observable.create(function (observer: Observer<T>) {
   const dataHandler = (data: T) => observer.next(data);
   const errorHandler = (err: any) => observer.error(err);
   const endHandler = () => observer.complete();
   stream.on("data", dataHandler);
   stream.on("error", errorHandler);
   stream.on("end", endHandler);
   stream.resume();
   return function() {
     stream.removeListener("data", dataHandler);
     stream.removeListener("error", errorHandler);
     stream.removeListener("end", endHandler);
   };
 }).share();
开发者ID:dancasey,项目名称:node-rx-server,代码行数:14,代码来源:rxserver.ts

示例5: collectData

	private collectData(stream: Readable): Buffer[] {
		const buffers: Buffer[] = [];
		stream.on('data', (data: Buffer) => {
			buffers.push(data);
		});
		return buffers;
	}
开发者ID:naturtle,项目名称:vscode,代码行数:7,代码来源:fileSearch.ts

示例6: forwardData

	private forwardData(stream: Readable, encoding: string, cb: (err: Error, stdout?: string) => void): NodeStringDecoder {
		const decoder = new StringDecoder(encoding);
		stream.on('data', (data: Buffer) => {
			cb(null, decoder.write(data));
		});
		return decoder;
	}
开发者ID:naturtle,项目名称:vscode,代码行数:7,代码来源:fileSearch.ts

示例7:

    return new Promise<void>(function(resolve, reject) {
        var ws = fs.createWriteStream(path);
        ws.on('finish', resolve)
        .on('error', reject);

        stream.on('error', reject);
        stream.pipe(ws);
    });
开发者ID:kildevaeld,项目名称:assets,代码行数:8,代码来源:utils.ts

示例8: c

	return new Promise<string>((c, e) => {
		const shasum = crypto.createHash(hashName);

		stream
			.on('data', shasum.update.bind(shasum))
			.on('error', e)
			.on('close', () => c(shasum.digest('hex')));
	});
开发者ID:PKRoma,项目名称:vscode,代码行数:8,代码来源:publish.ts

示例9: readToEnd

export function readToEnd(stream: Readable,
                          callback: (error: Error, chunks?: any[]) => void) {
  const chunks: Array<Buffer | string> = [];
  return stream
  .on('error', callback)
  .on('data', chunk => chunks.push(chunk))
  .on('end', () => callback(null, chunks));
}
开发者ID:chbrown,项目名称:streaming,代码行数:8,代码来源:index.ts

示例10: subscribeToDataEvent

function subscribeToDataEvent(readable: Readable, outputChannel: OutputChannel, saveData: boolean, dataStorage: string): void {
    readable.on('data', chunk => {
        const chunkAsString = typeof chunk === 'string' ? chunk : chunk.toString();
        outputChannel.append(chunkAsString);
        if (saveData) {
            dataStorage += chunkAsString;
        }
    });
}
开发者ID:KalitaAlexey,项目名称:RustyCode,代码行数:9,代码来源:OutputChannelProcess.ts


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