本文整理汇总了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;未经允许,请勿转载。 |
请发表评论