...

Source file src/github.com/gabriel-vasile/mimetype/internal/magic/ogg.go

Documentation: github.com/gabriel-vasile/mimetype/internal/magic

     1  package magic
     2  
     3  import (
     4  	"bytes"
     5  )
     6  
     7  /*
     8   NOTE:
     9  
    10   In May 2003, two Internet RFCs were published relating to the format.
    11   The Ogg bitstream was defined in RFC 3533 (which is classified as
    12   'informative') and its Internet content type (application/ogg) in RFC
    13   3534 (which is, as of 2006, a proposed standard protocol). In
    14   September 2008, RFC 3534 was obsoleted by RFC 5334, which added
    15   content types video/ogg, audio/ogg and filename extensions .ogx, .ogv,
    16   .oga, .spx.
    17  
    18   See:
    19   https://tools.ietf.org/html/rfc3533
    20   https://developer.mozilla.org/en-US/docs/Web/HTTP/Configuring_servers_for_Ogg_media#Serve_media_with_the_correct_MIME_type
    21   https://github.com/file/file/blob/master/magic/Magdir/vorbis
    22  */
    23  
    24  // Ogg matches an Ogg file.
    25  func Ogg(raw []byte, limit uint32) bool {
    26  	return bytes.HasPrefix(raw, []byte("\x4F\x67\x67\x53\x00"))
    27  }
    28  
    29  // OggAudio matches an audio ogg file.
    30  func OggAudio(raw []byte, limit uint32) bool {
    31  	return len(raw) >= 37 && (bytes.HasPrefix(raw[28:], []byte("\x7fFLAC")) ||
    32  		bytes.HasPrefix(raw[28:], []byte("\x01vorbis")) ||
    33  		bytes.HasPrefix(raw[28:], []byte("OpusHead")) ||
    34  		bytes.HasPrefix(raw[28:], []byte("Speex\x20\x20\x20")))
    35  }
    36  
    37  // OggVideo matches a video ogg file.
    38  func OggVideo(raw []byte, limit uint32) bool {
    39  	return len(raw) >= 37 && (bytes.HasPrefix(raw[28:], []byte("\x80theora")) ||
    40  		bytes.HasPrefix(raw[28:], []byte("fishead\x00")) ||
    41  		bytes.HasPrefix(raw[28:], []byte("\x01video\x00\x00\x00"))) // OGM video
    42  }
    43  

View as plain text