File: ogg.go

package info (click to toggle)
golang-github-gabriel-vasile-mimetype 1.4.1%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-backports
  • size: 9,720 kB
  • sloc: javascript: 3; makefile: 3; tcl: 1; php: 1; python: 1; perl: 1
file content (42 lines) | stat: -rw-r--r-- 1,458 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package magic

import (
	"bytes"
)

/*
 NOTE:

 In May 2003, two Internet RFCs were published relating to the format.
 The Ogg bitstream was defined in RFC 3533 (which is classified as
 'informative') and its Internet content type (application/ogg) in RFC
 3534 (which is, as of 2006, a proposed standard protocol). In
 September 2008, RFC 3534 was obsoleted by RFC 5334, which added
 content types video/ogg, audio/ogg and filename extensions .ogx, .ogv,
 .oga, .spx.

 See:
 https://tools.ietf.org/html/rfc3533
 https://developer.mozilla.org/en-US/docs/Web/HTTP/Configuring_servers_for_Ogg_media#Serve_media_with_the_correct_MIME_type
 https://github.com/file/file/blob/master/magic/Magdir/vorbis
*/

// Ogg matches an Ogg file.
func Ogg(raw []byte, limit uint32) bool {
	return bytes.HasPrefix(raw, []byte("\x4F\x67\x67\x53\x00"))
}

// OggAudio matches an audio ogg file.
func OggAudio(raw []byte, limit uint32) bool {
	return len(raw) >= 37 && (bytes.HasPrefix(raw[28:], []byte("\x7fFLAC")) ||
		bytes.HasPrefix(raw[28:], []byte("\x01vorbis")) ||
		bytes.HasPrefix(raw[28:], []byte("OpusHead")) ||
		bytes.HasPrefix(raw[28:], []byte("Speex\x20\x20\x20")))
}

// OggVideo matches a video ogg file.
func OggVideo(raw []byte, limit uint32) bool {
	return len(raw) >= 37 && (bytes.HasPrefix(raw[28:], []byte("\x80theora")) ||
		bytes.HasPrefix(raw[28:], []byte("fishead\x00")) ||
		bytes.HasPrefix(raw[28:], []byte("\x01video\x00\x00\x00"))) // OGM video
}