Repository: gabriel-vasile/mimetype
Pull request #50 (2019-10-01 11:50:03)

Added support for WARC file types
Added support for the WARC file type.

I did put the code in `archive.go` because it is a "Web ARChive" format; if you think that it should belong somewhere else, let me know.

coveralls: ## Pull Request Test Coverage Report for [Build 162](https://coveralls.io/builds/26037930)

* **3** of **3**   **(100.0%)**  changed or added relevant lines in **1** file are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage increased (+**0.02%**) to **93.998%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/26037930/badge)](https://coveralls.io/builds/26037930) |
| :-- | --: |
| Change from base [Build 161](https://coveralls.io/builds/25996334): |  0.02% |
| Covered Lines: | 1018 |
| Relevant Lines: | 1083 |

---
##### 💛  - [Coveralls](https://coveralls.io)

gabriel-vasile: Hi @ibraimgm 

Looks good, except for a small issue: It's safer if the detection function would match the string "WARC/".

I will merge this when you make this change.


Patch:
diff --git a/internal/matchers/archive.go b/internal/matchers/archive.go
index db3b215..fcf7932 100644
--- a/internal/matchers/archive.go
+++ b/internal/matchers/archive.go
@@ -76,3 +76,8 @@ func Rar(in []byte) bool {
 	}
 	return len(in) > 8 && (bytes.Equal(in[6:8], []byte{0x01, 0x00}) || in[6] == 0x00)
 }
+
+// Warc matches a Web ARChive file
+func Warc(in []byte) bool {
+	return bytes.HasPrefix(in, []byte("WARC/"))
+}
diff --git a/supported_mimes.md b/supported_mimes.md
index a99b97c..0cc6fea 100644
--- a/supported_mimes.md
+++ b/supported_mimes.md
@@ -1,4 +1,4 @@
-## 118 Supported MIME types
+## 119 Supported MIME types
 This file is automatically generated when running tests. Do not edit manually.
 
 Extension | MIME type
@@ -101,6 +101,7 @@ Extension | MIME type
 **tsv** | text/tab-separated-values
 **vcf** | text/vcard
 **ics** | text/calendar
+**warc** | application/warc
 **gz** | application/gzip
 **class** | application/x-java-applet; charset=binary
 **swf** | application/x-shockwave-flash
diff --git a/tree.go b/tree.go
index 7b58bf7..7bb3b22 100644
--- a/tree.go
+++ b/tree.go
@@ -36,7 +36,7 @@ var (
 	ogg       = newNode("application/ogg", "ogg", matchers.Ogg, oggAudio, oggVideo)
 	oggAudio  = newNode("audio/ogg", "oga", matchers.OggAudio)
 	oggVideo  = newNode("video/ogg", "ogv", matchers.OggVideo)
-	txt       = newNode("text/plain", "txt", matchers.Txt, html, svg, xml, php, js, lua, perl, python, json, ndJson, rtf, tcl, csv, tsv, vCard, iCalendar)
+	txt       = newNode("text/plain", "txt", matchers.Txt, html, svg, xml, php, js, lua, perl, python, json, ndJson, rtf, tcl, csv, tsv, vCard, iCalendar, warc)
 	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)
@@ -132,4 +132,5 @@ var (
 	lit       = newNode("application/x-ms-reader", "lit", matchers.Lit)
 	sqlite3   = newNode("application/x-sqlite3", "sqlite", matchers.Sqlite)
 	dwg       = newNode("image/vnd.dwg", "dwg", matchers.Dwg)
+	warc      = newNode("application/warc", "warc", matchers.Warc)
 )


Test patch:
diff --git a/mime_test.go b/mime_test.go
index ecf8094..36d0436 100644
--- a/mime_test.go
+++ b/mime_test.go
@@ -48,6 +48,7 @@ var files = map[string]*node{
 	"djvu.djvu":   djvu,
 	"mobi.mobi":   mobi,
 	"lit.lit":     lit,
+	"warc.warc":   warc,
 
 	// images
 	"png.png":   png,
diff --git a/testdata/warc.warc b/testdata/warc.warc
new file mode 100644
index 0000000..ad235e8
--- /dev/null
+++ b/testdata/warc.warc
@@ -0,0 +1,18 @@
+WARC/1.1
+WARC-Type: warcinfo
+WARC-Date: 2006-09-19T17:20:14Z
+WARC-Record-ID: <urn:uuid:d7ae5c10-e6b3-4d27-967d-34780c58ba39>
+Content-Type: application/warc-fields
+Content-Length: 381
+
+software: Heritrix 1.12.0 http://crawler.archive.org
+hostname: crawling017.archive.org
+ip: 207.241.227.234
+isPartOf: testcrawl-20050708
+description: testcrawl with WARC output
+operator: IA\_Admin
+http-header-user-agent:
+ Mozilla/5.0 (compatible; heritrix/1.4.0 +http://crawler.archive.org)
+format: WARC file version 1.1
+conformsTo:
+ http://iipc.github.io/warc-specifications/specifications/warc-format/warc-1.1/