本文整理汇总了TypeScript中stream.Transform类的典型用法代码示例。如果您正苦于以下问题:TypeScript Transform类的具体用法?TypeScript Transform怎么用?TypeScript Transform使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Transform类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: checkFileForChanges
public async checkFileForChanges(
transform: Transform,
file: File,
enc: string,
callback: (error: any, data: any) => any,
) {
if (file.isNull()) {
callback(null, null);
return;
}
try {
const changed = await this.hasFileOrDependenciesChanged(
file,
this.getOutputFileName(file.path),
);
if (changed) {
transform.push(file);
}
} catch (error) {
transform.emit(
"error",
new PluginError(
MODULE_NAME,
`Error processing \'${file.path}\': ${error}`,
),
);
} finally {
callback(null, null);
}
}
示例2: createStringStream
function createStringStream() {
var s = new stream.Transform();
s._transform = function (data, encoding, callback) {
callback(null, data);
};
s.setEncoding("utf8");
return s;
}
示例3: createDecompressionStream
static createDecompressionStream(): stream.Transform
{
var decompressor = new Decompressor();
var NodeStream: typeof stream = require("stream");
var decompressionStream = new NodeStream.Transform({ decodeStrings: true, highWaterMark: 65536 });
decompressionStream._transform = (data: Buffer, encoding: string, done: Function) =>
{
var buffer = decompressor.decompressBlock(convertToByteArray(data));
decompressionStream.push(buffer);
done();
}
return decompressionStream;
}
示例4: createDecompressionStream
static createDecompressionStream(): stream.Transform {
const decompressor = new Decompressor();
const NodeStream: typeof stream = require("stream");
const decompressionStream = new NodeStream.Transform({ decodeStrings: true, highWaterMark: 65536 });
decompressionStream._transform = (data: Buffer, encoding: string, done: Function) => {
let buffer: Buffer;
try {
buffer = BufferTools.uint8ArrayToBuffer(decompressor.decompressBlock(BufferTools.bufferToUint8Array(data)));
}
catch (e) {
decompressionStream.emit("error", e);
return;
}
decompressionStream.push(buffer);
done();
}
return decompressionStream;
}
示例5: StringifyStream
function StringifyStream() {
stream.Transform.call(this);
this._readableState.objectMode = false;
this._writableState.objectMode = true;
}
示例6: constructor
constructor(options) {
super(options);
Transform.call(Inspector, Transform);
}
示例7: TimeoutError
const handleRequest = (request: http.ClientRequest) => {
if (shouldAbort) {
request.abort();
return;
}
currentRequest = request;
request.on('error', error => {
if (request.aborted || error.message === 'socket hang up') {
return;
}
if (error instanceof TimedOutTimeoutError) {
error = new TimeoutError(error, timings, options);
} else {
error = new RequestError(error, options);
}
if (emitter.retry(error) === false) {
emitError(error);
}
});
timings = timer(request);
uploadProgress(request, emitter, uploadBodySize);
if (options.gotTimeout) {
// TODO: Properly type this. `preNormalizeArguments` coerces `gotTimeout` to `Delays`.
timedOut(request, options.gotTimeout as Delays, options);
}
emitter.emit('request', request);
const uploadComplete = () => {
request.emit('upload-complete');
};
try {
if (is.nodeStream(options.body)) {
options.body.once('end', uploadComplete);
options.body.pipe(request);
options.body = undefined;
} else if (options.body) {
request.end(options.body, uploadComplete);
} else if (input && (options.method === 'POST' || options.method === 'PUT' || options.method === 'PATCH')) {
input.once('end', uploadComplete);
input.pipe(request);
} else {
request.end(uploadComplete);
}
} catch (error) {
emitError(new RequestError(error, options));
}
};
示例8:
decompressionStream._transform = (data: Buffer, encoding: string, done: Function) => {
let buffer: Buffer;
try {
buffer = BufferTools.uint8ArrayToBuffer(decompressor.decompressBlock(BufferTools.bufferToUint8Array(data)));
}
catch (e) {
decompressionStream.emit("error", e);
return;
}
decompressionStream.push(buffer);
done();
}
示例9:
decompressionStream._transform = (data: Buffer, encoding: string, done: Function) =>
{
var buffer = decompressor.decompressBlock(convertToByteArray(data));
decompressionStream.push(buffer);
done();
}