本文整理汇总了TypeScript中on-finished.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: next
const handler: express.RequestHandler = (req, res, next) => {
// mount safety
if (req._logging) {
return next();
}
const start = Date.now();
const writeHead = res.writeHead;
// flag as logging
req._logging = true;
(res as any).writeHead = (code: number, headers: any) => {
res.writeHead = writeHead;
res.writeHead(code, headers);
res.__statusCode = code;
res.__headers = headers || {};
};
onFinished(res, () => {
res.responseTime = Date.now() - start;
// status code response level handling
let level = log4js.levels.INFO;
if (res.statusCode >= 300) {
level = log4js.levels.WARN;
}
if (res.statusCode >= 400) {
level = log4js.levels.ERROR;
}
const line = format(req, res);
if (line) {
return logger.log(level, line);
}
});
return next();
};
示例2: done
function done(err?: Error | null) {
if (isDone) return;
isDone = true;
stream.unpipe(busboy);
drainStream(stream);
busboy.removeAllListeners();
onFinished(req, () => {
if (err) return cb(err);
cb(null, [params, files]);
});
}
示例3: sendfile
// pipe the send file stream
function sendfile(res, file, options, callback) {
var done = false;
var streaming;
// request aborted
function onaborted() {
if (done) return;
done = true;
var err = new Error('Request aborted');
err.code = 'ECONNABORTED';
callback(err);
}
// directory
function ondirectory() {
if (done) return;
done = true;
var err = new Error('EISDIR, read');
err.code = 'EISDIR';
callback(err);
}
// errors
function onerror(err) {
if (done) return;
done = true;
callback(err);
}
// ended
function onend() {
if (done) return;
done = true;
callback();
}
// file
function onfile() {
streaming = false;
}
// finished
function onfinish(err) {
if (err && err.code === 'ECONNRESET') return onaborted();
if (err) return onerror(err);
if (done) return;
setImmediate(function () {
if (streaming !== false && !done) {
onaborted();
return;
}
if (done) return;
done = true;
callback();
});
}
// streaming
function onstream() {
streaming = true;
}
file.on('directory', ondirectory);
file.on('end', onend);
file.on('error', onerror);
file.on('file', onfile);
file.on('stream', onstream);
onFinished(res, onfinish);
if (options.headers) {
// set headers on successful transfer
file.on('headers', function headers(res) {
var obj = options.headers;
var keys = Object.keys(obj);
for (var i = 0; i < keys.length; i++) {
var k = keys[i];
res.setHeader(k, obj[k]);
}
});
}
// pipe
file.pipe(res);
}
示例4: sendStream
export function sendStream(ws: ServerResponse, read: Readable): T.Task<void> {
onFinished(ws, destroyStream.bind(null, read));
return pipeStream(ws, read as any, { end: false });
}
示例5: sendFilePath
export function sendFilePath(ws: ServerResponse, path: string, range: FileRange, hook: T.Task<void>): T.Task<void> {
const stream = pathCreateReadStream(path, range);
onFinished(ws, destroyStream.bind(null, stream));
return pipeStream(ws, stream as any, { end: false }).then(hook);
}