PageRenderTime 40ms CodeModel.GetById 22ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/src/hx/MimeTypes.hx

http://github.com/slaskis/s3upload
Haxe | 158 lines | 144 code | 5 blank | 9 comment | 8 complexity | 1a087bbf898167c38d72b658e83f084f MD5 | raw file
  1class MimeTypes {
  2	static var TYPES = [
  3		["application/andrew-inset","ez"],
  4		["application/atom+xml","atom"],
  5		["application/mac-binhex40","hqx"],
  6		["application/mac-compactpro","cpt"],
  7		["application/mathml+xml","mathml"],
  8		["application/msword","doc"],
  9		["application/octet-stream","bin","dms","lha","lzh","exe","class","so","dll","dmg"],
 10		["application/oda","oda"],
 11		["application/ogg","ogg"],
 12		["application/pdf","pdf"],
 13		["application/postscript","ai","eps","ps"],
 14		["application/rdf+xml","rdf"],
 15		["application/smil","smi","smil"],
 16		["application/srgs","gram"],
 17		["application/srgs+xml","grxml"],
 18		["application/vnd.adobe.apollo-application-installer-package+zip","air"],
 19		["application/vnd.mif","mif"],
 20		["application/vnd.mozilla.xul+xml","xul"],
 21		["application/vnd.ms-excel","xls"],
 22		["application/vnd.ms-powerpoint","ppt"],
 23		["application/vnd.rn-realmedia","rm"],
 24		["application/vnd.wap.wbxml","wbxml"],
 25		["application/vnd.wap.wmlc","wmlc"],
 26		["application/vnd.wap.wmlscriptc","wmlsc"],
 27		["application/voicexml+xml","vxml"],
 28		["application/x-bcpio","bcpio"],
 29		["application/x-cdlink","vcd"],
 30		["application/x-chess-pgn","pgn"],
 31		["application/x-cpio","cpio"],
 32		["application/x-csh","csh"],
 33		["application/x-director","dcr","dir","dxr"],
 34		["application/x-dvi","dvi"],
 35		["application/x-futuresplash","spl"],
 36		["application/x-gtar","gtar"],
 37		["application/x-hdf","hdf"],
 38		["application/x-javascript","js"],
 39		["application/x-koan","skp","skd","skt","skm"],
 40		["application/x-latex","latex"],
 41		["application/x-netcdf","nc","cdf"],
 42		["application/x-photoshop","psd"],
 43		["application/x-sh","sh"],
 44		["application/x-shar","shar"],
 45		["application/x-shockwave-flash","swf"],
 46		["application/x-stuffit","sit"],
 47		["application/x-sv4cpio","sv4cpio"],
 48		["application/x-sv4crc","sv4crc"],
 49		["application/x-tar","tar"],
 50		["application/x-tcl","tcl"],
 51		["application/x-tex","tex"],
 52		["application/x-texinfo","texinfo","texi"],
 53		["application/x-troff","t","tr","roff"],
 54		["application/x-troff-man","man"],
 55		["application/x-troff-me","me"],
 56		["application/x-troff-ms","ms"],
 57		["application/x-ustar","ustar"],
 58		["application/x-wais-source","src"],
 59		["application/xhtml+xml","xhtml","xht"],
 60		["application/xml","xml","xsl"],
 61		["application/xml-dtd","dtd"],
 62		["application/xslt+xml","xslt"],
 63		["application/zip","zip"],
 64		["audio/basic","au","snd"],
 65		["audio/midi","mid","midi","kar"],
 66		["audio/mpeg","mp3","mpga","mp2"],
 67		["audio/x-aiff","aif","aiff","aifc"],
 68		["audio/x-mpegurl","m3u"],
 69		["audio/x-pn-realaudio","ram","ra"],
 70		["audio/x-wav","wav"],
 71		["chemical/x-pdb","pdb"],
 72		["chemical/x-xyz","xyz"],
 73		["image/bmp","bmp"],
 74		["image/cgm","cgm"],
 75		["image/gif","gif"],
 76		["image/ief","ief"],
 77		["image/jpeg","jpg","jpeg","jpe"],
 78		["image/png","png"],
 79		["image/svg+xml","svg"],
 80		["image/tiff","tiff","tif"],
 81		["image/vnd.djvu","djvu","djv"],
 82		["image/vnd.wap.wbmp","wbmp"],
 83		["image/x-cmu-raster","ras"],
 84		["image/x-icon","ico"],
 85		["image/x-portable-anymap","pnm"],
 86		["image/x-portable-bitmap","pbm"],
 87		["image/x-portable-graymap","pgm"],
 88		["image/x-portable-pixmap","ppm"],
 89		["image/x-rgb","rgb"],
 90		["image/x-xbitmap","xbm"],
 91		["image/x-xpixmap","xpm"],
 92		["image/x-xwindowdump","xwd"],
 93		["model/iges","igs","iges"],
 94		["model/mesh","msh","mesh","silo"],
 95		["model/vrml","wrl","vrml"],
 96		["text/calendar","ics","ifb"],
 97		["text/css","css"],
 98		["text/html","html","htm"],
 99		["text/plain","txt","asc"],
100		["text/richtext","rtx"],
101		["text/rtf","rtf"],
102		["text/sgml","sgml","sgm"],
103		["text/tab-separated-values","tsv"],
104		["text/vnd.wap.wml","wml"],
105		["text/vnd.wap.wmlscript","wmls"],
106		["text/x-setext","etx"],
107		["video/mpeg","mpg","mpeg","mpe"],
108		["video/quicktime","mov","qt"],
109		["video/vnd.mpegurl","m4u","mxu"],
110		["video/x-flv","flv"],
111		["video/x-msvideo","avi"],
112		["video/x-sgi-movie","movie"],
113		["x-conference/x-cooltalk","ice"]
114	];
115	
116	var types : Array<Array<String>>;
117	
118	public function new() types = TYPES.copy()
119	
120	/**
121	 * Returns the mimetype for the given extension.
122	 */
123	public function getMimeType(extension:String):String {
124		extension = extension.toLowerCase();
125		for( a in types ) {
126			for( b in a ) {
127				if (b == extension)	{
128					return a[0];
129				}
130			}
131		}
132		return null;
133	}
134
135	/**
136	 * Returns the prefered extension for the given mimetype.
137	 */
138	public function getExtension(mimetype:String):String {
139		mimetype = mimetype.toLowerCase();
140		for( a in types ) {
141			if(a[0] == mimetype) {
142				return a[1];
143			}
144		}
145		return null;
146	}
147
148	/**
149	 * Adds a mimetype to the map. The order of the extensions matters. The most preferred should come first.
150	 */
151	public function addMimeType(mimetype:String, extensions:Array<String>)	{
152		var newType = [mimetype];
153		for( a in extensions ) {
154			newType.push(a);
155		}
156		types.push(newType);
157	}
158}