當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript on-finished.default函數代碼示例

本文整理匯總了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();
 };
開發者ID:croquiscom,項目名稱:Crary-Node,代碼行數:32,代碼來源:logger.ts

示例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]);
      });
    }
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:12,代碼來源:parser.ts

示例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);
}
開發者ID:yogendrap,項目名稱:PlZoo,代碼行數:90,代碼來源:Response.ts

示例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 });
}
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:4,代碼來源:send-stream.ts

示例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);
}
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:5,代碼來源:send-stream.ts


注:本文中的on-finished.default函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。