当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript file-type类代码示例

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


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

示例1: detect

export function detect(filename: string=null, buffer: Buffer=null): DetectionResult | null {
  if (filename !== null) {
    const mimeType = filenameToTextMimetype(filename);
    if (mimeType !== null) {
      return {mimeType, charset: null };
    }

    const imageMimeType = mimeTypes.lookup(filename);
    if (imageMimeType !== null && imageMimeType !== false) {
      return { mimeType: imageMimeType, charset: null };
    }
  }

  // Check the data directly.
  if (buffer !== null) {
    const fileTypeResult = filetype(buffer);
    if (fileTypeResult !== null) {
      return {mimeType: fileTypeResult.mime, charset: null };
    }

    if ( ! isNotText(buffer)) {
      const result = jschardet.detect(buffer.slice(0, SAMPLE_SIZE).toString());
      if (result.encoding !== null && result.confidence > 0.8) {
        return { mimeType: "text/plain", charset: result.encoding };
      }
    }
  }

  return { mimeType: "application/octet-stream", charset: null };
}
开发者ID:sedwards2009,项目名称:extraterm,代码行数:30,代码来源:MimeTypeDetector.ts

示例2: fileType

 return getBuffer.then(data => {
   headers["Content-Type"] = contentType || fileType(data).mime;
   headers["Content-Length"] = data.length;
   headers["User-Agent"] = userAgent;
   return axios
     .post(url, data, { headers })
     .then(res => res.data)
     .catch(wrapError);
 });
开发者ID:nkjm,项目名称:line-bot-sdk-nodejs,代码行数:9,代码来源:http.ts

示例3: fileType

 return getBuffer.then(data => {
   return this.instance
     .post(url, data, {
       headers: {
         "Content-Type": contentType || fileType(data).mime,
         "Content-Length": data.length,
       },
     })
     .then(res => res.data);
 });
开发者ID:SaKu2110,项目名称:Alexa_LINE_Bot,代码行数:10,代码来源:http.ts

示例4: excludeBinaryFile

function excludeBinaryFile(file: eclint.IEditorConfigLintFile) {
	return !(file && file.isBuffer() && fileType(file.contents));
}
开发者ID:jedmao,项目名称:eclint,代码行数:3,代码来源:cli.ts

示例5: openFile

export async function openFile(data: any){
	let file_path = paths.projects+data.currentProject+'/'+data.newFile;
	try{
		var file_stat = await file_manager.stat_file(file_path);
	}
	catch(e){
		// if we are trying to open an example or template and we can't find the file, we are (probably)
		// trying to open a pd or supercollider project, so open _main* if it exists instead
		if (typeof data.exampleName !== 'undefined' || data.func === 'newProject'){
			for(let file of data.fileList){
				if (file.name.includes('_main')){
					data.newFile = file.name;
					await openFile(data);
					return;
				}
			}
		}
		data.error = 'error opening file '+data.newFile+': '+e.toString();
		data.fileData = 'Error opening file. Please open a different file to continue';
		data.fileName = data.newFile;
		data.newFile = undefined;
		data.readOnly = true;
		data.fileType = 0;
		return;
	}
	if (file_stat.size > max_file_size){
		data.error = 'file is too large: '+(file_stat.size/1000000)+'Mb';
		data.fileData = "The IDE can't open files larger than "+(max_file_size/1000000)+"Mb";
		data.readOnly = true;
		data.fileName = data.newFile;
		data.newFile = undefined;
		data.fileType = 0;
		return;
	}
	let chunk: Buffer = await readChunk(file_path, 0, 4100);
	let file_type = await fileType(chunk);
	if (file_type && (file_type.mime.includes('image') || file_type.mime.includes('audio'))){
		await file_manager.empty_directory(paths.media);
		await file_manager.make_symlink(file_path, paths.media+data.newFile);
		data.fileData = '';
		data.readOnly = true;
		data.fileName = data.newFile;
		data.newFile = undefined;
		data.fileType = file_type.mime;
		return;
	}
	let is_binary = await file_manager.is_binary(file_path);
	if (is_binary){
		data.error = 'can\'t open binary files';
		data.fileData = 'Binary files can not be edited in the IDE';
		data.fileName = data.newFile;
		data.newFile = undefined;
		data.readOnly = true;
		data.fileType = 0;
		return;
	}
	try{
		data.fileData = await file_manager.read_file(file_path);
	}
	catch(e){
		data.error = 'error opening file '+data.newFile+': '+e.toString();
		data.fileData = 'Error opening file. Please open a different file to continue';
		data.fileName = data.newFile;
		data.newFile = undefined;
		data.readOnly = true;
		data.fileType = 0;
		return;
	}
	if (data.newFile.split && data.newFile.includes('.')){
		data.fileType = data.newFile.split('.').pop();
	} else {
		data.fileType = 0;
	}
	data.fileName = data.newFile;
	data.newFile = undefined;
	data.readOnly = false;
	return;
}
开发者ID:BelaPlatform,项目名称:Bela,代码行数:78,代码来源:ProjectManager.ts


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