class: MIMETypes
authorClaus Gittinger <cg@exept.de>
Sun, 23 Nov 2014 16:48:09 +0100
changeset 3400 7c44ae7a6d6b
parent 3399 5f9df070dfed
child 3401 4850b4d8d0fd
class: MIMETypes added: #mimeTypeOfData:suffix: changed: #fileInfoForMimeType: #mimeTypeOfData: #mimeTypeOfData:fileName:
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 $'
 ! !