• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript mime.lookup函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中mime.lookup函数的典型用法代码示例。如果您正苦于以下问题:TypeScript lookup函数的具体用法?TypeScript lookup怎么用?TypeScript lookup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了lookup函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: sendFile

/**
 * Sends the file in response
 * @param Response response
 */
function sendFile(response: http.ServerResponse, request: http.ServerRequest)
{
    try
    {
        let buf = fs.readFileSync(directoryPath);
        let type = mime.lookup(directoryPath);

        let fileExtension = directoryPath.substr(directoryPath.lastIndexOf('.')+1);

        response.statusCode = 200;
        response.setHeader('Content-Length', status["size"].toString());
        response.setHeader('Content-Type', type);
        response.setHeader('X-Content-Type-Options', 'nosniff');
        response.setHeader('X-XSS-Protection', '1; mode=block');
        response.setHeader('X-Frame-Options', 'SAMEORIGIN');
        response.setHeader('Cache-Control', 'private, max-age=10800');

        //Check for Gzip support
        if (request.headers['accept-encoding'] && request.headers['accept-encoding'].match(/\bgzip\b/)) 
        {
            if (fileExtension === "css" || fileExtension === "js" || fileExtension === "html") 
            {
                buf = encodeToGZIP(buf, response);
            }
        }

        response.end(buf, 'binary');
    }
    catch (e)
    {
        ErrorLogger().Debug(e);
    }
}
开发者ID:Kasperki,项目名称:NodeBlog,代码行数:37,代码来源:FileServer.ts


示例2: processRequest

			function processRequest() {
				try {
					var stat = fs.statSync(filename);
					if(!stat.isFile()) {
						if (stat.isDirectory()) {
							filename = pathJoin(filename, "index.html");
							stat = fs.statSync(filename);
							if(!stat.isFile()) throw "next";
						} else {
							throw "next";
						}
					}
				} catch(e) {
					return next();
				}

				// server content
				var content = fs.readFileSync(filename);
				content = handleRangeHeaders(content, req, res);
				res.setHeader("Access-Control-Allow-Origin", "*"); // To support XHR, etc.
				res.setHeader("Content-Type", mime.lookup(filename));
				res.setHeader("Content-Length", content.length);
				if(options.headers) {
					for(var name in options.headers) {
						res.setHeader(name, options.headers[name]);
					}
				}
				if (res.send) res.send(content);
				else res.end(content);
			}
开发者ID:Xananax,项目名称:wpack,代码行数:30,代码来源:connectMiddleware.ts


示例3: pushResources

export function pushResources(
    options: ServerOptions, req: express.Request, res: Response) {
  if (res.push && options.protocol === 'h2' && options.pushManifestPath &&
      !req.get('x-is-push')) {
    // TODO: Handle preload link headers
    const pushManifest =
        getPushManifest(options.root, options.pushManifestPath);
    const resources = pushManifest[req.path];
    if (resources) {
      const root = options.root;
      for (const filename of Object.keys(resources)) {
        const stream =
            res.push(filename, {
                 request: {accept: '*/*'},
                 response: {
                   'content-type': mime.lookup(filename),

                   // Add an X-header to the pushed request so we don't trigger
                   // pushes for pushes
                   'x-is-push': 'true'
                 }
               })
                .on('error',
                    (err: {}) =>
                        console.error('failed to push', filename, err));
        fs.createReadStream(path.join(root, filename)).pipe(stream);
      }
    }
  }
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:30,代码来源:push.ts


示例4: sendMission

function sendMission(request, response, missionId: number, missionZip: string, downloadMissionName: string) {
    var missionWorkingDir = `${Settings.PATH.Mission.WORKING_DIR}/${missionId}`;
    var missionZipPath = `${missionWorkingDir}/${missionZip}`;
    response.setHeader('Content-disposition', `attachment; filename=${downloadMissionName}.zip`);
    response.setHeader('Content-type', mime.lookup(missionZipPath));
    response.sendFile(missionZipPath, { root: './' }, () => removeMissionWorkingDir(missionWorkingDir) );
}
开发者ID:Cyruz143,项目名称:shipyard,代码行数:7,代码来源:App.ts


示例5: uploadBlob

async function uploadBlob(blobService: azure.BlobService, quality: string, blobName: string, file: string): Promise<void> {
	const blobOptions = {
		contentType: mime.lookup(file),
		cacheControl: 'max-age=31536000, public'
	};

	await new Promise((c, e) => blobService.createBlockBlobFromLocalFile(quality, blobName, file, blobOptions, err => err ? e(err) : c()));
}
开发者ID:FabianLauer,项目名称:vscode,代码行数:8,代码来源:publish.ts


示例6: readWithFallback

 private async readWithFallback(filepath, extensions): Promise<{Body: Buffer, ContentType: string}> {
     for (let ext of extensions) {
         try {
             var res = await readFile(filepath + ext);
             return {Body: res, ContentType: mime.lookup(filepath + ext)};
         } catch (err) {}
     }
     throw new Error(filepath + ' not found');
 }
开发者ID:notenoughneon,项目名称:anypub,代码行数:9,代码来源:filepublisher.ts


示例7: function

 fs.readFile(pathname.substr(1), function (err, data) {
     if (err) {
         console.log(err);
         response.writeHead(404, { 'Content-Type': 'text/html' });
     } else {
         response.writeHead(200, { 'Content-Type': mime.lookup(pathname) });
         response.end(data, 'binary')
     }
 });   
开发者ID:,项目名称:,代码行数:9,代码来源:


示例8: function

module.exports.download = function(req, res) {
    var id = req.param('id');
    var name = req.param('name');
    var file = req.param('file');
    var path = KDataBase + '/' + name + '/' + file;
    console.log('download: ' + path);
    //var SkipperDisk = require('skipper-disk');
    //var fileAdapter = SkipperDisk(/* optional opts */);
    //fileAdapter.read(path).on('error', function (err) {
    //    return res.serverError(err);
    //}).pipe(res);
    var mimetype = mime.lookup(path);
    res.setHeader('Content-disposition', 'attachment; filename=' + file);
    res.setHeader('Content-type', mimetype);
    var filestream = fs.createReadStream(path);
    filestream.pipe(res)
};
开发者ID:swcho,项目名称:ossdb,代码行数:17,代码来源:PackageController.ts


示例9: put

 async put(path, obj, contentType): Promise<void> {
     var params = {
         Bucket: this.bucket,
         Key: normalizePath(path),
         Body: obj,
         ContentType: contentType !== undefined ? contentType : mime.lookup(path)
     };
     await this.putObject(params);
     debug('put ' + params.Key);
     // S3 doesn't infer '.html' on filenames,
     // so we have to put both 'path' and 'path.html'
     if (params.ContentType === 'text/html' && !/\.html$/.test(params.Key)) {
         params.Key = params.Key + '.html';
         await this.putObject(params);
         debug('put ' + params.Key);
     }
 }
开发者ID:notenoughneon,项目名称:anypub,代码行数:17,代码来源:s3publisher.ts


示例10: viewStatic

export function viewStatic( filename: string, headers: relaxjs.ResponseHeaders  = {} ) : Q.Promise< relaxjs.Embodiment > {
  var fname = '[view static]';
  var log = _log.child( { func: 'internals.viewStatic'} );

  var mtype = mime.lookup(filename);
  var laterAction = Q.defer< relaxjs.Embodiment >();
  var staticFile = '.' + filename;
  log.info('serving %s',staticFile);

  if ( !fs.existsSync(staticFile) ) {
    log.warn('File "%s" not found',staticFile);
    laterAction.reject( new relaxjs.RxError(`File ${filename} not found`, 'File Not Found', 404 ) );
  }
  else {
    fs.stat( staticFile , ( err, stats: fs.Stats ) => {
      log.info(`Sreaming ${staticFile}`);
      headers['content-length'] = stats.size.toString();
      var readStream = fs.createReadStream( staticFile );
      var reply = new relaxjs.Embodiment( mtype, 200, readStream );
      reply.additionalHeaders = headers;
      laterAction.resolve( reply );
    });

  }

  /*
  fs.readFile( staticFile, function( err : Error, content : Buffer ) {
    if ( err ) {
      log.warn('%s file "%s" not found',fname,staticFile);
      laterAction.reject( new relaxjs.RxError( filename + ' not found', 'File Not Found', 404 ) );
    }
    else {
      var reply = new relaxjs.Embodiment( mtype, 200, content );
      reply.additionalHeaders = headers;
      laterAction.resolve( reply );
    }
  });
  */

  return laterAction.promise;
}
开发者ID:micurs,项目名称:relaxjs,代码行数:41,代码来源:internals.ts



注:本文中的mime.lookup函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript mime-types.contentType函数代码示例发布时间:2022-05-25
下一篇:
TypeScript mime.getType函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap