Skip to content

Commit 02cce61

Browse files
bufr: add support (#754)
1 parent fe42f3e commit 02cce61

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

internal/magic/meteo.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@ func GRIB(raw []byte, _ uint32) bool {
1010
bytes.HasPrefix(raw, []byte("GRIB")) &&
1111
(raw[7] == 1 || raw[7] == 2)
1212
}
13+
14+
// BUFR matches meteorological data format for storing point or time series data.
15+
// https://confluence.ecmwf.int/download/attachments/31064617/ecCodes_BUFR_in_a_nutshell.pdf?version=1&modificationDate=1457000352419&api=v2
16+
func BUFR(raw []byte, _ uint32) bool {
17+
return len(raw) > 7 &&
18+
bytes.HasPrefix(raw, []byte("BUFR")) &&
19+
(raw[7] == 0x03 || raw[7] == 0x04)
20+
}

mimetype_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ var testcases = []testcase{
6161
{"bmp\x7C", "BM \x7C\x00\x00\x00", "image/bmp", none},
6262
{"bmp\x6C", "BM \x6C\x00\x00\x00", "image/bmp", none},
6363
{"bpg", "\x42\x50\x47\xFB", "image/bpg", one},
64+
{"bufr", "BUFR \x03", "application/bufr", one},
6465
{"bz2", "\x42\x5A\x68", "application/x-bzip2", one},
6566
{"cab", "MSCF\x00\x00\x00\x00", "application/vnd.ms-cab-compressed", one},
6667
{"cab.is", "ISc(\x00\x00\x00\x01", "application/x-installshield", one},

supported_mimes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 198 Supported MIME types
1+
## 199 Supported MIME types
22
This file is automatically generated when running tests. Do not edit manually.
33

44
Extension | MIME type <br> Aliases | Hierarchy
@@ -157,6 +157,7 @@ Extension | MIME type <br> Aliases | Hierarchy
157157
**.inf** | **application/x-os2-inf** | inf>root
158158
**.hlp** | **application/x-os2-hlp** | hlp>root
159159
**.fm** | **application/vnd.framemaker** | fm>root
160+
**.bufr** | **application/bufr** | bufr>root
160161
**.txt** | **text/plain** | txt>root
161162
**.svg** | **image/svg+xml** | svg>txt>root
162163
**.html** | **text/html** | html>txt>root

tree.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var root = newMIME("application/octet-stream", "",
2424
woff2, otf, ttc, eot, wasm, shx, dbf, dcm, rar, djvu, mobi, lit, bpg, cbor,
2525
sqlite3, dwg, nes, lnk, macho, qcp, icns, hdr, mrc, mdb, accdb, zstd, cab,
2626
rpm, xz, lzip, torrent, cpio, tzif, xcf, pat, gbr, glb, cabIS, jxr, parquet,
27-
oneNote, chm, wpd, dxf, grib, zlib, inf, hlp, fm,
27+
oneNote, chm, wpd, dxf, grib, zlib, inf, hlp, fm, bufr,
2828
// Keep text last because it is the slowest check.
2929
text,
3030
)
@@ -293,4 +293,5 @@ var (
293293
inf = newMIME("application/x-os2-inf", ".inf", magic.Inf)
294294
hlp = newMIME("application/x-os2-hlp", ".hlp", magic.Hlp)
295295
fm = newMIME("application/vnd.framemaker", ".fm", magic.FrameMaker)
296+
bufr = newMIME("application/bufr", ".bufr", magic.BUFR)
296297
)

0 commit comments

Comments
 (0)