mimetype

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2022 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Unspecified             = MIME_UNSPECIFIED
	Unknown                 = MIME_UNKNOWN
	TextPlain               = MIME_TEXT_PLAIN
	TextCSV                 = MIME_TEXT_CSV
	TextHTML                = MIME_TEXT_HTML
	TextCalendar            = MIME_TEXT_CALENDAR
	ApplicationOctetStream  = MIME_APPLICATION_OCTET_STREAM
	ApplicationJSON         = MIME_APPLICATION_JSON
	ApplicationJSONUTF8     = MIME_APPLICATION_JSON_UTF8
	ApplicationJSONLD       = MIME_APPLICATION_JSON_LD
	AppplicationJSONLines   = MIME_APPLICATION_JSON_LINES
	ApplicationUBJSON       = MIME_APPLICATION_UBJSON
	ApplicationBSON         = MIME_APPLICATION_BSON
	ApplicationXML          = MIME_APPLICATION_XML
	ApplicationAtom         = MIME_APPLICATION_ATOM
	ApplicationMsgPack      = MIME_APPLICATION_MSGPACK
	ApplicationParquet      = MIME_APPLICATION_PARQUET
	ApplicationAvro         = MIME_APPLICATION_AVRO
	ApplicationProtobuf     = MIME_APPLICATION_PROTOBUF
	ApplicationPDF          = MIME_APPLICATION_PDF
	ApplicationJavaArchive  = MIME_APPLICATION_JAVA_ARCHIVE
	ApplicationPythonPickle = MIME_APPLICATION_PYTHON_PICKLE
	UserSpecified0          = MIME_USER_SPECIFIED0
	UserSpecified1          = MIME_USER_SPECIFIED1
	UserSpecified2          = MIME_USER_SPECIFIED2
	UserSpecified3          = MIME_USER_SPECIFIED3
	UserSpecified4          = MIME_USER_SPECIFIED4
	UserSpecified5          = MIME_USER_SPECIFIED5
	UserSpecified6          = MIME_USER_SPECIFIED6
	UserSpecified7          = MIME_USER_SPECIFIED7
	UserSpecified8          = MIME_USER_SPECIFIED8
	UserSpecified9          = MIME_USER_SPECIFIED9
)

MimeType constant aliases for more readable Go code.

Variables

View Source
var (
	MIMEType_name = map[int32]string{
		0:    "application/octet-stream",
		1:    "text/plain",
		2:    "text/csv",
		3:    "text/html",
		4:    "text/calendar",
		50:   "application/json",
		51:   "application/ld+json",
		52:   "application/jsonlines",
		53:   "application/ubjson",
		54:   "application/bson",
		100:  "application/xml",
		101:  "application/atom+xml",
		252:  "application/msgpack",
		253:  "application/parquet",
		254:  "application/avro",
		255:  "application/protobuf",
		512:  "application/pdf",
		513:  "application/java-archive",
		514:  "application/python-pickle",
		1000: "user/format-0",
		1001: "user/format-1",
		1002: "user/format-2",
		1003: "user/format-3",
		1004: "user/format-4",
		1005: "user/format-5",
		1006: "user/format-6",
		1007: "user/format-7",
		1008: "user/format-8",
		1009: "user/format-9",
	}
	MIMEType_value = map[string]int32{
		"application/octet-stream":  0,
		"text/plain":                1,
		"text/csv":                  2,
		"text/html":                 3,
		"text/calendar":             4,
		"application/json":          50,
		"application/ld+json":       51,
		"application/jsonlines":     52,
		"application/ubjson":        53,
		"application/bson":          54,
		"application/xml":           100,
		"application/atom+xml":      101,
		"application/msgpack":       252,
		"application/parquet":       253,
		"application/avro":          254,
		"application/protobuf":      255,
		"application/pdf":           512,
		"application/java-archive":  513,
		"application/python-pickle": 514,
		"user/format-0":             1000,
		"user/format-1":             1001,
		"user/format-2":             1002,
		"user/format-3":             1003,
		"user/format-4":             1004,
		"user/format-5":             1005,
		"user/format-6":             1006,
		"user/format-7":             1007,
		"user/format-8":             1008,
		"user/format-9":             1009,
	}
	MIMERegExp = regexp.MustCompile(`^(?P<prefix>application|user|text)\/(?P<mime>[\w\-_\.]+)(\+(?P<ext>[\w-]+))?(?P<pairs>;(\s+([\w\.\-_]+=[\w\.\-_]+))+)?$`)
)

Enum value maps for mimetype strings

View Source
var (
	MIME_name = map[int32]string{
		0: "UNSPECIFIED",

		1: "TEXT_PLAIN",
		2: "TEXT_CSV",
		3: "TEXT_HTML",
		4: "TEXT_CALENDAR",

		50: "APPLICATION_JSON",

		51:   "APPLICATION_JSON_LD",
		52:   "APPLICATION_JSON_LINES",
		53:   "APPLICATION_UBJSON",
		54:   "APPLICATION_BSON",
		100:  "APPLICATION_XML",
		101:  "APPLICATION_ATOM",
		252:  "APPLICATION_MSGPACK",
		253:  "APPLICATION_PARQUET",
		254:  "APPLICATION_AVRO",
		255:  "APPLICATION_PROTOBUF",
		512:  "APPLICATION_PDF",
		513:  "APPLICATION_JAVA_ARCHIVE",
		514:  "APPLICATION_PYTHON_PICKLE",
		1000: "USER_SPECIFIED0",
		1001: "USER_SPECIFIED1",
		1002: "USER_SPECIFIED2",
		1003: "USER_SPECIFIED3",
		1004: "USER_SPECIFIED4",
		1005: "USER_SPECIFIED5",
		1006: "USER_SPECIFIED6",
		1007: "USER_SPECIFIED7",
		1008: "USER_SPECIFIED8",
		1009: "USER_SPECIFIED9",
	}
	MIME_value = map[string]int32{
		"UNSPECIFIED":               0,
		"UNKNOWN":                   0,
		"TEXT_PLAIN":                1,
		"TEXT_CSV":                  2,
		"TEXT_HTML":                 3,
		"TEXT_CALENDAR":             4,
		"APPLICATION_OCTET_STREAM":  0,
		"APPLICATION_JSON":          50,
		"APPLICATION_JSON_UTF8":     50,
		"APPLICATION_JSON_LD":       51,
		"APPLICATION_JSON_LINES":    52,
		"APPLICATION_UBJSON":        53,
		"APPLICATION_BSON":          54,
		"APPLICATION_XML":           100,
		"APPLICATION_ATOM":          101,
		"APPLICATION_MSGPACK":       252,
		"APPLICATION_PARQUET":       253,
		"APPLICATION_AVRO":          254,
		"APPLICATION_PROTOBUF":      255,
		"APPLICATION_PDF":           512,
		"APPLICATION_JAVA_ARCHIVE":  513,
		"APPLICATION_PYTHON_PICKLE": 514,
		"USER_SPECIFIED0":           1000,
		"USER_SPECIFIED1":           1001,
		"USER_SPECIFIED2":           1002,
		"USER_SPECIFIED3":           1003,
		"USER_SPECIFIED4":           1004,
		"USER_SPECIFIED5":           1005,
		"USER_SPECIFIED6":           1006,
		"USER_SPECIFIED7":           1007,
		"USER_SPECIFIED8":           1008,
		"USER_SPECIFIED9":           1009,
	}
)

Enum value maps for MIME.

View Source
var File_mimetype_v1beta1_mimetype_proto protoreflect.FileDescriptor

Functions

func Components

func Components(s string) map[string]string

Components returns the mimetype parts in the following format: prefix/mime+ext; pairs Note that the pairs will include the leading ; and all spaces between key/values.

Types

type MIME

type MIME int32

MIME stands for multipurpose internet mail extensions and is a standardized method for defining the formatting of files and data of different types. In Ensign, the mimetype is used to identify and deserialize event data.

Typically, mimetypes are strings, e.g. "application/json" and can even flexibly define encodings such as "application/json; charset=utf-8"; these ensure that mimetypes are flexible and can be extended without changing protocols. However, using string encoding for events results in a lot of duplication and data size should be as small as possible when there are numerous events in the system.

To reduce the size of event messages, this package defines mimetypes as an enum. This ensures that only 4 bytes maximum are used for the mimetype, but also means that the mimetypes are not as flexible and adding new mimetypes requires adding enum values to this package. If your mimetype is not listed here, please submit a pull request to ensign to get it added!

const (
	MIME_UNSPECIFIED MIME = 0
	MIME_UNKNOWN     MIME = 0
	// Default value for textual files that are human-readable and do not contain binary data.
	MIME_TEXT_PLAIN MIME = 1
	// Plain text data-containing types
	MIME_TEXT_CSV      MIME = 2
	MIME_TEXT_HTML     MIME = 3
	MIME_TEXT_CALENDAR MIME = 4
	// Default value for all non-text data types (alias for UNSPECIFIED)
	MIME_APPLICATION_OCTET_STREAM MIME = 0
	// Application data-containing types
	MIME_APPLICATION_JSON       MIME = 50
	MIME_APPLICATION_JSON_UTF8  MIME = 50
	MIME_APPLICATION_JSON_LD    MIME = 51
	MIME_APPLICATION_JSON_LINES MIME = 52
	MIME_APPLICATION_UBJSON     MIME = 53
	MIME_APPLICATION_BSON       MIME = 54
	MIME_APPLICATION_XML        MIME = 100
	MIME_APPLICATION_ATOM       MIME = 101
	// Binary application data-containing types
	MIME_APPLICATION_MSGPACK  MIME = 252
	MIME_APPLICATION_PARQUET  MIME = 253
	MIME_APPLICATION_AVRO     MIME = 254
	MIME_APPLICATION_PROTOBUF MIME = 255
	// Other miscellaneous application types
	MIME_APPLICATION_PDF           MIME = 512
	MIME_APPLICATION_JAVA_ARCHIVE  MIME = 513
	MIME_APPLICATION_PYTHON_PICKLE MIME = 514
	// User-specified mimetypes allow the user to distinguish mimetypes in their
	// applications without specifically setting a mimetype.
	MIME_USER_SPECIFIED0 MIME = 1000
	MIME_USER_SPECIFIED1 MIME = 1001
	MIME_USER_SPECIFIED2 MIME = 1002
	MIME_USER_SPECIFIED3 MIME = 1003
	MIME_USER_SPECIFIED4 MIME = 1004
	MIME_USER_SPECIFIED5 MIME = 1005
	MIME_USER_SPECIFIED6 MIME = 1006
	MIME_USER_SPECIFIED7 MIME = 1007
	MIME_USER_SPECIFIED8 MIME = 1008
	MIME_USER_SPECIFIED9 MIME = 1009
)

func MustParse

func MustParse(s string) MIME

MustParse does not return an error but returns a default mimetype; text/plain if the mimetype prefix is text otherwise application/octet-stream.

func Parse

func Parse(s string) (MIME, error)

Parse a string mimetype into a mimetype constant. If the given mimetype is unknown then an error is returned. Parse returns best effort mimetypes. For example if the mimetype is application/vnd.myapp.type+xml then application/xml is returned. This method is case and whitespace insensitive.

func (MIME) Descriptor

func (MIME) Descriptor() protoreflect.EnumDescriptor

func (MIME) Enum

func (x MIME) Enum() *MIME

func (MIME) EnumDescriptor deprecated

func (MIME) EnumDescriptor() ([]byte, []int)

Deprecated: Use MIME.Descriptor instead.

func (MIME) MimeType

func (x MIME) MimeType() string

Returns the MimeType name as defined by the IETF specification.

func (MIME) Number

func (x MIME) Number() protoreflect.EnumNumber

func (MIME) String

func (x MIME) String() string

func (MIME) Type

func (MIME) Type() protoreflect.EnumType

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL