當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。