本文整理汇总了TypeScript中stream.Readable.push方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Readable.push方法的具体用法?TypeScript Readable.push怎么用?TypeScript Readable.push使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stream.Readable
的用法示例。
在下文中一共展示了Readable.push方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('pretty no color/label/debug', () => {
const result = pretty({ colorize: false, withLabel: false, debug: false });
const stream = new Readable();
stream.push('{ "msg": "Test message", "time": 1514074545477, "level": 20, "label": "TestStream" }');
stream.push(null);
stream.pipe(result).pipe(process.stdout);
});
示例2: stringToStream
function stringToStream(str:string){
var stream = new Readable();
stream._read= ()=>{};
stream.push(str);
stream.push(null);
return stream;
}
示例3: it
it("should not throw error when given a stream", async (done) => {
var linter: Linter = new Linter([
new SelfCloseRule(),
]);
var html = new Readable();
html.push("<template/>");
html.push(null);
var result: Issue[];
var error: Error;
try {
result = await linter.lint(html);
}
catch (err) {
error = err;
}
expect(error).toBeUndefined();
expect(result).toBeDefined();
expect(result.length).toBe(1);
done();
});
示例4: test
test('tapToVSError', t => {
const s = new stream.Readable();
s.push(testString2);
s.push(null);
const w = new stream.Writable();
let resultString = '';
w._write = function (chunk, encoding, done) {
//console.log('+=+' + chunk.toString());
resultString += chunk.toString();
done();
};
const option = new Options(null, 'c:/base');
const tapToVSError = new TapToVSError(option);
const teststream = tapToVSError.stream();
s.pipe(teststream).pipe(w);
w.on('finish', function () {
console.log('resultString = ' + resultString);
t.ok(teststream, 'teststream');
t.ok(resultString, 'resultString');
t.end();
});
});
示例5: writeAuthTimestamp
private async writeAuthTimestamp(bucketAddress: string, timestamp: number): Promise<void> {
// Recheck cache for a larger timestamp to avoid race conditions from slow storage.
let cachedTimestamp = this.cache.get(bucketAddress)
if (cachedTimestamp && cachedTimestamp > timestamp) {
return
}
const authTimestampFileDir = this.getAuthTimestampFileDir(bucketAddress)
// Convert our number to a Buffer.
const contentBuffer = Buffer.from(timestamp.toString(), 'utf8')
// Wrap the buffer in a stream for driver consumption.
const contentStream = new Readable()
contentStream.push(contentBuffer, 'utf8')
contentStream.push(null) // Mark EOF
await this.driver.performWrite({
storageTopLevel: authTimestampFileDir,
path: AUTH_TIMESTAMP_FILE_NAME,
stream: contentStream,
contentLength: contentBuffer.length,
contentType: 'text/plain; charset=UTF-8'
})
// In a race condition, use the newest timestamp.
cachedTimestamp = this.cache.get(bucketAddress)
if (cachedTimestamp && cachedTimestamp > timestamp) {
timestamp = cachedTimestamp
}
this.cache.set(bucketAddress, timestamp)
}
示例6: 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;
});
}
示例7: stringToStream
export function stringToStream(text: string): Readable | undefined {
if (!text) {
return undefined;
}
const s = new Readable();
s.push(text);
s.push(null);
return s;
}
示例8: generateStream
export function generateStream(
collections: Tyr.CollectionInstance[],
opts: DefinitionGenerationOptions = { type: 'isomorphic' }
) {
const stream = new Readable();
const td = resolveGenerationMethod(opts.type)(collections, opts);
stream.push(td);
stream.push(null);
return stream;
}
示例9: if
read: () => {
if (i === 0) {
emitter.push(file1);
} else if (i === 1) {
emitter.push(file2);
} else {
emitter.push(null);
}
i++;
}