From d0d1ed8c1d0882e0cc9354bbef85774d263e6547 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 12 Aug 2006 01:41:48 +0000 Subject: [PATCH] Scholar.File -- some methods to help with MIME type detection of local files (might be abstracted into MIME class later) Methods: getExtension(ext) isExternalTextExtension(ext) getSample(nsIFile) sniffForMIMEType(nsIFile) sniffForBinary(nsIFile) getMIMETypeFromFile(nsIFile) hasInternalHandler(nsIFile) --- .../chromeFiles/content/scholar/xpcom/file.js | 176 ++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 chrome/chromeFiles/content/scholar/xpcom/file.js diff --git a/chrome/chromeFiles/content/scholar/xpcom/file.js b/chrome/chromeFiles/content/scholar/xpcom/file.js new file mode 100644 index 000000000..038743d36 --- /dev/null +++ b/chrome/chromeFiles/content/scholar/xpcom/file.js @@ -0,0 +1,176 @@ +Scholar.File = new function(){ + this.getExtension = getExtension; + this.isExternalTextExtension = isExternalTextExtension; + this.getSample = getSample; + this.sniffForMIMEType = sniffForMIMEType; + this.sniffForBinary = sniffForBinary; + this.getMIMETypeFromFile = getMIMETypeFromFile; + this.hasInternalHandler = hasInternalHandler; + + // Magic numbers + var _snifferEntries = [ + ["%PDF-", "application/pdf"], + ["%!PS-Adobe-", 'application/postscript'], + ["%! PS-Adobe-", 'application/postscript'], + ["From", 'text/plain'], + [">From", 'text/plain'], + ["#!", 'text/plain'], + [" 31 || (9 <= chr && chr <=13 ) || chr == 27; + } +}