本文整理汇总了TypeScript中stream.Readable类的典型用法代码示例。如果您正苦于以下问题:TypeScript Readable类的具体用法?TypeScript Readable怎么用?TypeScript Readable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Readable类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: onData
function onData(stream: Readable, session: SMTPServerSession, callback: (err?: Error) => void): void {
console.log(`[${session.id}] onData started`);
let messageLength = 0;
stream.on('data', (chunk: Buffer) => {
console.log(`[${session.id}] onData got data chunk ${chunk.length} bytes`);
messageLength += chunk.length;
});
stream.once('end', () => {
console.log(`[${session.id}] onData finished after reading ${messageLength} bytes`);
callback();
});
}
示例2: 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;
}
示例3: collectData
private collectData(stream: Readable): Buffer[] {
const buffers: Buffer[] = [];
stream.on('data', (data: Buffer) => {
buffers.push(data);
});
return buffers;
}
示例4: it
it("Copy Complete", () => {
log("Init Output / Input Stream");
inSource = new FileSource({path: file});
file0 = path.resolve(file0dir, "./out.log");
outSource = new FileSource();
input = inSource.createReadableStream(
(option) => {log("input option", option); return option; },
) as Readable;
output = outSource.createWritableStream(
(option) => {
option.path = file0,
log("output option", option);
return option;
},
) as Writable;
input.pipe(output);
return new Promise((resolve, reject) => {
input.on("end", () => {
log("Input End!");
const json = fse.readJsonSync(file0);
if (JSON.stringify(TEST_JSON) === JSON.stringify(json)) {
log("Successfully Copy");
resolve();
} else {
log("Failed to Copy");
reject();
}
});
});
});
示例5: lint
lint(html: string): Promise<Issue[]> {
var parser: SAXParser = new SAXParser({ locationInfo: true });
var parseState: ParseState = new ParseState(this.scopes, this.voids);
var stream: Readable = new Readable();
parseState.initPreRules(parser);
let rules = this.rules;
rules.forEach((rule) => {
rule.init(parser, parseState);
});
parseState.initPostRules(parser);
stream.push(html);
stream.push(null);
var work = stream.pipe(parser);
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;
});
}
示例6: 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));
}
示例7: Promise
return Promise.resolve(mkdirp(targetDirName, void 0, token)).then(() => new Promise((c, e) => {
if (token.isCancellationRequested) {
return;
}
try {
istream = createWriteStream(targetFileName, { mode });
istream.once('close', () => c());
istream.once('error', e);
stream.once('error', e);
stream.pipe(istream);
} catch (error) {
e(error);
}
}));
示例8: handleError
(err, result) => {
if (err) {
handleError(err)
} else {
result.rows.map(row => stream.push(row))
stream.push(null)
}
}
示例9: 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')));
});
示例10: initialize
function initialize(){
GERRIT_STREAM
.pipe(TO_GERRIT_EVENT(), { end: false })
.pipe(REGISTER_REVIEWER_ADDED(), { end: false })
.pipe(TO_NOTIFICATION_OBJECT(), { end: false })
.pipe(TO_NATIVE_NOTIFICATION(platform), { end: false })
.pipe(TO_FILE(), { end: false });
}