当前位置: 首页>>代码示例>>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;未经允许,请勿转载。