# HG changeset patch # User Claus Gittinger # Date 1416757689 -3600 # Node ID 7c44ae7a6d6be3106cbae1cb9e1815ff99b42efa # Parent 5f9df070dfed6702fbaf76f47505f70c687fcdfb class: MIMETypes added: #mimeTypeOfData:suffix: changed: #fileInfoForMimeType: #mimeTypeOfData: #mimeTypeOfData:fileName: diff -r 5f9df070dfed -r 7c44ae7a6d6b MIMETypes.st --- a/MIMETypes.st Sun Nov 23 16:00:20 2014 +0100 +++ b/MIMETypes.st Sun Nov 23 16:48:09 2014 +0100 @@ -805,6 +805,10 @@ provides. This info here is returned by systems which have no file (i.e. MSDOS) and for types of which file does not know about (smalltalk files, for example)" + TypeToInfoMapping isNil ifTrue:[ + self initializeFileInfoMappings + ]. + ^ TypeToInfoMapping at:mimeType ifAbsent:nil " @@ -976,6 +980,14 @@ Returns nil, if unknown. This is done using some heuristics, and may need some improvement" + ^ self mimeTypeOfData:someData suffix:nil +! + +mimeTypeOfData:someData suffix:fileNameSuffixOrNilIfUnknown + "this tries to guess the mime type of contents of someData. + Returns nil, if unknown. + This is done using some heuristics, and may need some improvement" + |buffer lcBuffer size idx idx2| someData isEmptyOrNil ifTrue:[^ nil]. @@ -1012,6 +1024,11 @@ patternString := pattern asString. (buffer startsWith:patternString) ifTrue:[ + what = #'application/x-zip-compressed' ifTrue:[ + fileNameSuffixOrNilIfUnknown = 'jar' ifTrue:[ + ^ MIMEType fromString: #'application/java-archive' + ]. + ]. ^ MIMEType fromString:what ] ]. @@ -1553,11 +1570,11 @@ !MIMETypes class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libview2/MIMETypes.st,v 1.137 2014-11-09 22:17:21 cg Exp $' + ^ '$Header: /cvs/stx/stx/libview2/MIMETypes.st,v 1.138 2014-11-23 15:48:09 cg Exp $' ! version_CVS - ^ '$Header: /cvs/stx/stx/libview2/MIMETypes.st,v 1.137 2014-11-09 22:17:21 cg Exp $' + ^ '$Header: /cvs/stx/stx/libview2/MIMETypes.st,v 1.138 2014-11-23 15:48:09 cg Exp $' ! !