本文整理匯總了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);
}