Repository: gabriel-vasile/mimetype
Pull request #45 (2019-09-24 17:29:38)

Add support for 'text/calendar' MIME type
Refer:
https://en.wikipedia.org/wiki/ICalendar


Patch:
diff --git a/internal/matchers/text.go b/internal/matchers/text.go
index 9200b73..2775ef1 100644
--- a/internal/matchers/text.go
+++ b/internal/matchers/text.go
@@ -70,6 +70,9 @@ var (
 	vCardSigs = []sig{
 		ciSig("BEGIN:VCARD\n"),
 	}
+	iCalSigs = []sig{
+		ciSig("BEGIN:VCALENDAR\n"),
+	}
 	phpSigs = []sig{
 		ciSig("<?PHP"),
 		ciSig("<?\n"),
@@ -345,3 +348,8 @@ func X3d(in []byte) bool {
 func VCard(in []byte) bool {
 	return detect(in, vCardSigs)
 }
+
+// ICalendar matches a iCalendar file.
+func ICalendar(in []byte) bool {
+	return detect(in, iCalSigs)
+}
diff --git a/supported_mimes.md b/supported_mimes.md
index 12e880e..693bc6f 100644
--- a/supported_mimes.md
+++ b/supported_mimes.md
@@ -1,4 +1,4 @@
-## 115 Supported MIME types
+## 116 Supported MIME types
 This file is automatically generated when running tests. Do not edit manually.
 
 Extension | MIME type
@@ -98,6 +98,7 @@ Extension | MIME type
 **csv** | text/csv
 **tsv** | text/tab-separated-values
 **vcf** | text/vcard
+**ics** | text/calendar
 **gz** | application/gzip
 **class** | application/x-java-applet; charset=binary
 **swf** | application/x-shockwave-flash
diff --git a/tree.go b/tree.go
index 89d648a..4f49d5c 100644
--- a/tree.go
+++ b/tree.go
@@ -34,7 +34,7 @@ var (
 	psd       = newNode("application/x-photoshop", "psd", matchers.Psd)
 	fits      = newNode("application/fits", "fits", matchers.Fits)
 	ogg       = newNode("application/ogg", "ogg", matchers.Ogg)
-	txt       = newNode("text/plain", "txt", matchers.Txt, html, svg, xml, php, js, lua, perl, python, json, ndJson, rtf, tcl, csv, tsv, vCard)
+	txt       = newNode("text/plain", "txt", matchers.Txt, html, svg, xml, php, js, lua, perl, python, json, ndJson, rtf, tcl, csv, tsv, vCard, iCalendar)
 	xml       = newNode("text/xml; charset=utf-8", "xml", matchers.Xml, rss, atom, x3d, kml, xliff, collada, gml, gpx, tcx, amf, threemf)
 	json      = newNode("application/json", "json", matchers.Json, geoJson)
 	csv       = newNode("text/csv", "csv", matchers.Csv)
@@ -50,6 +50,7 @@ var (
 	python    = newNode("application/x-python", "py", matchers.Python)
 	tcl       = newNode("text/x-tcl", "tcl", matchers.Tcl)
 	vCard     = newNode("text/vcard", "vcf", matchers.VCard)
+	iCalendar = newNode("text/calendar", "ics", matchers.ICalendar)
 	svg       = newNode("image/svg+xml", "svg", matchers.Svg)
 	rss       = newNode("application/rss+xml", "rss", matchers.Rss)
 	atom      = newNode("application/atom+xml", "atom", matchers.Atom)


Test patch:
diff --git a/mime_test.go b/mime_test.go
index ea76f98..facd8a4 100644
--- a/mime_test.go
+++ b/mime_test.go
@@ -109,6 +109,7 @@ var files = map[string]*node{
 	"py.py":             python,
 	"tcl.tcl":           tcl,
 	"vCard.vCard":       vCard,
+	"ics.ics":           iCalendar,
 
 	// binary
 	"class.class": class,
diff --git a/testdata/ics.ics b/testdata/ics.ics
new file mode 100644
index 0000000..040382b
--- /dev/null
+++ b/testdata/ics.ics
@@ -0,0 +1,13 @@
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//hacksw/handcal//NONSGML v1.0//EN
+BEGIN:VEVENT
+UID:uid1@example.com
+DTSTAMP:19970714T170000Z
+ORGANIZER;CN=John Doe:MAILTO:john.doe@example.com
+DTSTART:19970714T170000Z
+DTEND:19970715T035959Z
+SUMMARY:Bastille Day Party
+GEO:48.85299;2.36885
+END:VEVENT
+END:VCALENDAR