mirror of
https://github.com/h2non/filetype.git
synced 2025-12-24 11:52:08 +08:00
detect wasm file type
This commit is contained in:
BIN
fixtures/sample.wasm
Normal file
BIN
fixtures/sample.wasm
Normal file
Binary file not shown.
@@ -47,6 +47,7 @@ func TestMatchFile(t *testing.T) {
|
||||
{"pptx"},
|
||||
{"xlsx"},
|
||||
{"mov"},
|
||||
{"wasm"},
|
||||
}
|
||||
|
||||
for _, test := range cases {
|
||||
|
||||
20
matchers/application.go
Normal file
20
matchers/application.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package matchers
|
||||
|
||||
var (
|
||||
TypeWasm = newType("wasm", "application/wasm")
|
||||
)
|
||||
|
||||
var Application = Map{
|
||||
TypeWasm: Wasm,
|
||||
}
|
||||
|
||||
// Wasm detects a Web Assembly 1.0 filetype.
|
||||
func Wasm(buf []byte) bool {
|
||||
// WASM has starts with `\0asm`, followed by the version.
|
||||
// http://webassembly.github.io/spec/core/binary/modules.html#binary-magic
|
||||
return len(buf) >= 8 &&
|
||||
buf[0] == 0x00 && buf[1] == 0x61 &&
|
||||
buf[2] == 0x73 && buf[3] == 0x6D &&
|
||||
buf[4] == 0x01 && buf[5] == 0x00 &&
|
||||
buf[6] == 0x00 && buf[7] == 0x00
|
||||
}
|
||||
@@ -47,5 +47,5 @@ func register(matchers ...Map) {
|
||||
func init() {
|
||||
// Arguments order is intentional
|
||||
// Archive files will be checked last due to prepend above in func NewMatcher
|
||||
register(Archive, Document, Font, Audio, Video, Image)
|
||||
register(Archive, Document, Font, Audio, Video, Image, Application)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user