Documentation ¶
Overview ¶
Package mimedata defines MIME data support used in clipboard and drag-and-drop functions in the Cogent Core GUI. mimedata.Data struct contains format and []byte data, and multiple representations of the same data are encoded in mimedata.Mimes which is just a []mimedata.Data slice -- it can be encoded / decoded from mime multipart.
See the fileinfo package for known mimetypes.
Index ¶
Constants ¶
const ( MIMEVersion1 = "MIME-Version: 1.0" ContentType = "Content-Type" ContentTransferEncoding = "Content-Transfer-Encoding" TextPlain = "text/plain" DataJson = "application/json" DataXml = "application/xml" )
Variables ¶
var ( MIMEVersion1B = ([]byte)(MIMEVersion1) ContentTypeB = ([]byte)(ContentType) ContentTransferEncodingB = ([]byte)(ContentTransferEncoding) )
Functions ¶
func IsMultipart ¶
IsMultipart examines data bytes to see if it has a MIME-Version: 1.0 ContentType: multipart/* header -- returns the actual multipart media type, body of the data string after the header (assumed to be a single \n terminated line at start of string, and the boundary separating multipart elements (all from mime.ParseMediaType) -- mediaType is the mediaType if it is another MIME type -- can check that for non-empty string
Types ¶
type Data ¶
type Data struct { // MIME Type string representing the data, e.g., text/plain, text/html, text/xml, text/uri-list, image/jpg, png etc Type string // Data for the item Data []byte }
Data represents one element of MIME data as a type string and byte slice
func NewTextData ¶
NewTextData returns a Data representation of the string -- good idea to always have a text/plain representation of everything on clipboard / drag-n-drop
func NewTextDataBytes ¶
NewTextDataBytes returns a Data representation of the bytes string
type Mimes ¶
type Mimes []*Data
Mimes is a slice of mime data, potentially encoding the same data in different formats -- this is used for all system APIs for maximum flexibility
func FromMultipart ¶
FromMultipart parses a MIME multipart representation of multiple data elements into corresponding mime data components
func NewTextBytes ¶
NewTextBytes returns a Mimes representation of the bytes string as a single text/plain Data
func NewTextPlus ¶
NewTextPlus returns a Mimes representation of an item as a text string plus a more specific type
func (Mimes) ToMultipart ¶
ToMultipart produces a MIME multipart representation of multiple data elements present in the stream -- this should be used in system.Clipboard whenever there are multiple elements to be pasted, because windows doesn't support multiple clip elements, and linux isn't very convenient either