repo stringlengths 5 67 | path stringlengths 4 218 | func_name stringlengths 0 151 | original_string stringlengths 52 373k | language stringclasses 6
values | code stringlengths 52 373k | code_tokens listlengths 10 512 | docstring stringlengths 3 47.2k | docstring_tokens listlengths 3 234 | sha stringlengths 40 40 | url stringlengths 85 339 | partition stringclasses 3
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
jhillyerd/enmime | envelope.go | parseMultiPartBody | func parseMultiPartBody(root *Part, e *Envelope) error {
// Parse top-level multipart
ctype := root.Header.Get(hnContentType)
mediatype, params, _, err := parseMediaType(ctype)
if err != nil {
return fmt.Errorf("Unable to parse media type: %v", err)
}
if !strings.HasPrefix(mediatype, ctMultipartPrefix) {
retu... | go | func parseMultiPartBody(root *Part, e *Envelope) error {
// Parse top-level multipart
ctype := root.Header.Get(hnContentType)
mediatype, params, _, err := parseMediaType(ctype)
if err != nil {
return fmt.Errorf("Unable to parse media type: %v", err)
}
if !strings.HasPrefix(mediatype, ctMultipartPrefix) {
retu... | [
"func",
"parseMultiPartBody",
"(",
"root",
"*",
"Part",
",",
"e",
"*",
"Envelope",
")",
"error",
"{",
"ctype",
":=",
"root",
".",
"Header",
".",
"Get",
"(",
"hnContentType",
")",
"\n",
"mediatype",
",",
"params",
",",
"_",
",",
"err",
":=",
"parseMedia... | // parseMultiPartBody parses a multipart message in root. The result is placed in e. | [
"parseMultiPartBody",
"parses",
"a",
"multipart",
"message",
"in",
"root",
".",
"The",
"result",
"is",
"placed",
"in",
"e",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/envelope.go#L275-L342 | test |
jhillyerd/enmime | envelope.go | matchHTMLBodyPart | func matchHTMLBodyPart(p *Part) bool {
return p.ContentType == ctTextHTML && p.Disposition != cdAttachment
} | go | func matchHTMLBodyPart(p *Part) bool {
return p.ContentType == ctTextHTML && p.Disposition != cdAttachment
} | [
"func",
"matchHTMLBodyPart",
"(",
"p",
"*",
"Part",
")",
"bool",
"{",
"return",
"p",
".",
"ContentType",
"==",
"ctTextHTML",
"&&",
"p",
".",
"Disposition",
"!=",
"cdAttachment",
"\n",
"}"
] | // Used by Part matchers to locate the HTML body. Not inlined because it's used in multiple places. | [
"Used",
"by",
"Part",
"matchers",
"to",
"locate",
"the",
"HTML",
"body",
".",
"Not",
"inlined",
"because",
"it",
"s",
"used",
"in",
"multiple",
"places",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/envelope.go#L345-L347 | test |
jhillyerd/enmime | envelope.go | ensureCommaDelimitedAddresses | func ensureCommaDelimitedAddresses(s string) string {
// This normalizes the whitespace, but may interfere with CFWS (comments with folding whitespace)
// RFC-5322 3.4.0:
// because some legacy implementations interpret the comment,
// comments generally SHOULD NOT be used in address fields
// to av... | go | func ensureCommaDelimitedAddresses(s string) string {
// This normalizes the whitespace, but may interfere with CFWS (comments with folding whitespace)
// RFC-5322 3.4.0:
// because some legacy implementations interpret the comment,
// comments generally SHOULD NOT be used in address fields
// to av... | [
"func",
"ensureCommaDelimitedAddresses",
"(",
"s",
"string",
")",
"string",
"{",
"s",
"=",
"strings",
".",
"Join",
"(",
"strings",
".",
"Fields",
"(",
"s",
")",
",",
"\" \"",
")",
"\n",
"inQuotes",
":=",
"false",
"\n",
"inDomain",
":=",
"false",
"\n",
... | // Used by AddressList to ensure that address lists are properly delimited | [
"Used",
"by",
"AddressList",
"to",
"ensure",
"that",
"address",
"lists",
"are",
"properly",
"delimited"
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/envelope.go#L350-L406 | test |
jhillyerd/enmime | builder.go | Date | func (p MailBuilder) Date(date time.Time) MailBuilder {
p.date = date
return p
} | go | func (p MailBuilder) Date(date time.Time) MailBuilder {
p.date = date
return p
} | [
"func",
"(",
"p",
"MailBuilder",
")",
"Date",
"(",
"date",
"time",
".",
"Time",
")",
"MailBuilder",
"{",
"p",
".",
"date",
"=",
"date",
"\n",
"return",
"p",
"\n",
"}"
] | // Date returns a copy of MailBuilder with the specified Date header. | [
"Date",
"returns",
"a",
"copy",
"of",
"MailBuilder",
"with",
"the",
"specified",
"Date",
"header",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/builder.go#L46-L49 | test |
jhillyerd/enmime | builder.go | From | func (p MailBuilder) From(name, addr string) MailBuilder {
p.from = mail.Address{Name: name, Address: addr}
return p
} | go | func (p MailBuilder) From(name, addr string) MailBuilder {
p.from = mail.Address{Name: name, Address: addr}
return p
} | [
"func",
"(",
"p",
"MailBuilder",
")",
"From",
"(",
"name",
",",
"addr",
"string",
")",
"MailBuilder",
"{",
"p",
".",
"from",
"=",
"mail",
".",
"Address",
"{",
"Name",
":",
"name",
",",
"Address",
":",
"addr",
"}",
"\n",
"return",
"p",
"\n",
"}"
] | // From returns a copy of MailBuilder with the specified From header. | [
"From",
"returns",
"a",
"copy",
"of",
"MailBuilder",
"with",
"the",
"specified",
"From",
"header",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/builder.go#L52-L55 | test |
jhillyerd/enmime | builder.go | Subject | func (p MailBuilder) Subject(subject string) MailBuilder {
p.subject = subject
return p
} | go | func (p MailBuilder) Subject(subject string) MailBuilder {
p.subject = subject
return p
} | [
"func",
"(",
"p",
"MailBuilder",
")",
"Subject",
"(",
"subject",
"string",
")",
"MailBuilder",
"{",
"p",
".",
"subject",
"=",
"subject",
"\n",
"return",
"p",
"\n",
"}"
] | // Subject returns a copy of MailBuilder with the specified Subject header. | [
"Subject",
"returns",
"a",
"copy",
"of",
"MailBuilder",
"with",
"the",
"specified",
"Subject",
"header",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/builder.go#L58-L61 | test |
jhillyerd/enmime | builder.go | To | func (p MailBuilder) To(name, addr string) MailBuilder {
p.to = append(p.to, mail.Address{Name: name, Address: addr})
return p
} | go | func (p MailBuilder) To(name, addr string) MailBuilder {
p.to = append(p.to, mail.Address{Name: name, Address: addr})
return p
} | [
"func",
"(",
"p",
"MailBuilder",
")",
"To",
"(",
"name",
",",
"addr",
"string",
")",
"MailBuilder",
"{",
"p",
".",
"to",
"=",
"append",
"(",
"p",
".",
"to",
",",
"mail",
".",
"Address",
"{",
"Name",
":",
"name",
",",
"Address",
":",
"addr",
"}",
... | // To returns a copy of MailBuilder with this name & address appended to the To header. name may be
// empty. | [
"To",
"returns",
"a",
"copy",
"of",
"MailBuilder",
"with",
"this",
"name",
"&",
"address",
"appended",
"to",
"the",
"To",
"header",
".",
"name",
"may",
"be",
"empty",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/builder.go#L65-L68 | test |
jhillyerd/enmime | builder.go | ToAddrs | func (p MailBuilder) ToAddrs(to []mail.Address) MailBuilder {
p.to = to
return p
} | go | func (p MailBuilder) ToAddrs(to []mail.Address) MailBuilder {
p.to = to
return p
} | [
"func",
"(",
"p",
"MailBuilder",
")",
"ToAddrs",
"(",
"to",
"[",
"]",
"mail",
".",
"Address",
")",
"MailBuilder",
"{",
"p",
".",
"to",
"=",
"to",
"\n",
"return",
"p",
"\n",
"}"
] | // ToAddrs returns a copy of MailBuilder with the specified To addresses. | [
"ToAddrs",
"returns",
"a",
"copy",
"of",
"MailBuilder",
"with",
"the",
"specified",
"To",
"addresses",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/builder.go#L71-L74 | test |
jhillyerd/enmime | builder.go | CC | func (p MailBuilder) CC(name, addr string) MailBuilder {
p.cc = append(p.cc, mail.Address{Name: name, Address: addr})
return p
} | go | func (p MailBuilder) CC(name, addr string) MailBuilder {
p.cc = append(p.cc, mail.Address{Name: name, Address: addr})
return p
} | [
"func",
"(",
"p",
"MailBuilder",
")",
"CC",
"(",
"name",
",",
"addr",
"string",
")",
"MailBuilder",
"{",
"p",
".",
"cc",
"=",
"append",
"(",
"p",
".",
"cc",
",",
"mail",
".",
"Address",
"{",
"Name",
":",
"name",
",",
"Address",
":",
"addr",
"}",
... | // CC returns a copy of MailBuilder with this name & address appended to the CC header. name may be
// empty. | [
"CC",
"returns",
"a",
"copy",
"of",
"MailBuilder",
"with",
"this",
"name",
"&",
"address",
"appended",
"to",
"the",
"CC",
"header",
".",
"name",
"may",
"be",
"empty",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/builder.go#L78-L81 | test |
jhillyerd/enmime | builder.go | CCAddrs | func (p MailBuilder) CCAddrs(cc []mail.Address) MailBuilder {
p.cc = cc
return p
} | go | func (p MailBuilder) CCAddrs(cc []mail.Address) MailBuilder {
p.cc = cc
return p
} | [
"func",
"(",
"p",
"MailBuilder",
")",
"CCAddrs",
"(",
"cc",
"[",
"]",
"mail",
".",
"Address",
")",
"MailBuilder",
"{",
"p",
".",
"cc",
"=",
"cc",
"\n",
"return",
"p",
"\n",
"}"
] | // CCAddrs returns a copy of MailBuilder with the specified CC addresses. | [
"CCAddrs",
"returns",
"a",
"copy",
"of",
"MailBuilder",
"with",
"the",
"specified",
"CC",
"addresses",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/builder.go#L84-L87 | test |
jhillyerd/enmime | builder.go | ReplyTo | func (p MailBuilder) ReplyTo(name, addr string) MailBuilder {
p.replyTo = mail.Address{Name: name, Address: addr}
return p
} | go | func (p MailBuilder) ReplyTo(name, addr string) MailBuilder {
p.replyTo = mail.Address{Name: name, Address: addr}
return p
} | [
"func",
"(",
"p",
"MailBuilder",
")",
"ReplyTo",
"(",
"name",
",",
"addr",
"string",
")",
"MailBuilder",
"{",
"p",
".",
"replyTo",
"=",
"mail",
".",
"Address",
"{",
"Name",
":",
"name",
",",
"Address",
":",
"addr",
"}",
"\n",
"return",
"p",
"\n",
"... | // ReplyTo returns a copy of MailBuilder with this name & address appended to the To header. name
// may be empty. | [
"ReplyTo",
"returns",
"a",
"copy",
"of",
"MailBuilder",
"with",
"this",
"name",
"&",
"address",
"appended",
"to",
"the",
"To",
"header",
".",
"name",
"may",
"be",
"empty",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/builder.go#L107-L110 | test |
jhillyerd/enmime | builder.go | Header | func (p MailBuilder) Header(name, value string) MailBuilder {
// Copy existing header map
h := textproto.MIMEHeader{}
for k, v := range p.header {
h[k] = v
}
h.Add(name, value)
p.header = h
return p
} | go | func (p MailBuilder) Header(name, value string) MailBuilder {
// Copy existing header map
h := textproto.MIMEHeader{}
for k, v := range p.header {
h[k] = v
}
h.Add(name, value)
p.header = h
return p
} | [
"func",
"(",
"p",
"MailBuilder",
")",
"Header",
"(",
"name",
",",
"value",
"string",
")",
"MailBuilder",
"{",
"h",
":=",
"textproto",
".",
"MIMEHeader",
"{",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"p",
".",
"header",
"{",
"h",
"[",
"k",
... | // Header returns a copy of MailBuilder with the specified value added to the named header. | [
"Header",
"returns",
"a",
"copy",
"of",
"MailBuilder",
"with",
"the",
"specified",
"value",
"added",
"to",
"the",
"named",
"header",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/builder.go#L113-L122 | test |
jhillyerd/enmime | builder.go | AddAttachment | func (p MailBuilder) AddAttachment(b []byte, contentType string, fileName string) MailBuilder {
part := NewPart(contentType)
part.Content = b
part.FileName = fileName
part.Disposition = cdAttachment
p.attachments = append(p.attachments, part)
return p
} | go | func (p MailBuilder) AddAttachment(b []byte, contentType string, fileName string) MailBuilder {
part := NewPart(contentType)
part.Content = b
part.FileName = fileName
part.Disposition = cdAttachment
p.attachments = append(p.attachments, part)
return p
} | [
"func",
"(",
"p",
"MailBuilder",
")",
"AddAttachment",
"(",
"b",
"[",
"]",
"byte",
",",
"contentType",
"string",
",",
"fileName",
"string",
")",
"MailBuilder",
"{",
"part",
":=",
"NewPart",
"(",
"contentType",
")",
"\n",
"part",
".",
"Content",
"=",
"b",... | // AddAttachment returns a copy of MailBuilder that includes the specified attachment. | [
"AddAttachment",
"returns",
"a",
"copy",
"of",
"MailBuilder",
"that",
"includes",
"the",
"specified",
"attachment",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/builder.go#L137-L144 | test |
jhillyerd/enmime | builder.go | AddFileAttachment | func (p MailBuilder) AddFileAttachment(path string) MailBuilder {
// Only allow first p.err value
if p.err != nil {
return p
}
f, err := os.Open(path)
if err != nil {
p.err = err
return p
}
b, err := ioutil.ReadAll(f)
if err != nil {
p.err = err
return p
}
name := filepath.Base(path)
ctype := mime.... | go | func (p MailBuilder) AddFileAttachment(path string) MailBuilder {
// Only allow first p.err value
if p.err != nil {
return p
}
f, err := os.Open(path)
if err != nil {
p.err = err
return p
}
b, err := ioutil.ReadAll(f)
if err != nil {
p.err = err
return p
}
name := filepath.Base(path)
ctype := mime.... | [
"func",
"(",
"p",
"MailBuilder",
")",
"AddFileAttachment",
"(",
"path",
"string",
")",
"MailBuilder",
"{",
"if",
"p",
".",
"err",
"!=",
"nil",
"{",
"return",
"p",
"\n",
"}",
"\n",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
... | // AddFileAttachment returns a copy of MailBuilder that includes the specified attachment.
// fileName, will be populated from the base name of path. Content type will be detected from the
// path extension. | [
"AddFileAttachment",
"returns",
"a",
"copy",
"of",
"MailBuilder",
"that",
"includes",
"the",
"specified",
"attachment",
".",
"fileName",
"will",
"be",
"populated",
"from",
"the",
"base",
"name",
"of",
"path",
".",
"Content",
"type",
"will",
"be",
"detected",
"... | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/builder.go#L149-L167 | test |
jhillyerd/enmime | builder.go | AddInline | func (p MailBuilder) AddInline(
b []byte,
contentType string,
fileName string,
contentID string,
) MailBuilder {
part := NewPart(contentType)
part.Content = b
part.FileName = fileName
part.Disposition = cdInline
part.ContentID = contentID
p.inlines = append(p.inlines, part)
return p
} | go | func (p MailBuilder) AddInline(
b []byte,
contentType string,
fileName string,
contentID string,
) MailBuilder {
part := NewPart(contentType)
part.Content = b
part.FileName = fileName
part.Disposition = cdInline
part.ContentID = contentID
p.inlines = append(p.inlines, part)
return p
} | [
"func",
"(",
"p",
"MailBuilder",
")",
"AddInline",
"(",
"b",
"[",
"]",
"byte",
",",
"contentType",
"string",
",",
"fileName",
"string",
",",
"contentID",
"string",
",",
")",
"MailBuilder",
"{",
"part",
":=",
"NewPart",
"(",
"contentType",
")",
"\n",
"par... | // AddInline returns a copy of MailBuilder that includes the specified inline. fileName and
// contentID may be left empty. | [
"AddInline",
"returns",
"a",
"copy",
"of",
"MailBuilder",
"that",
"includes",
"the",
"specified",
"inline",
".",
"fileName",
"and",
"contentID",
"may",
"be",
"left",
"empty",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/builder.go#L171-L184 | test |
jhillyerd/enmime | builder.go | Equals | func (p MailBuilder) Equals(o MailBuilder) bool {
return reflect.DeepEqual(p, o)
} | go | func (p MailBuilder) Equals(o MailBuilder) bool {
return reflect.DeepEqual(p, o)
} | [
"func",
"(",
"p",
"MailBuilder",
")",
"Equals",
"(",
"o",
"MailBuilder",
")",
"bool",
"{",
"return",
"reflect",
".",
"DeepEqual",
"(",
"p",
",",
"o",
")",
"\n",
"}"
] | // Equals uses the reflect package to test two MailBuilder structs for equality, primarily for unit
// tests. | [
"Equals",
"uses",
"the",
"reflect",
"package",
"to",
"test",
"two",
"MailBuilder",
"structs",
"for",
"equality",
"primarily",
"for",
"unit",
"tests",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/builder.go#L337-L339 | test |
jhillyerd/enmime | encode.go | Encode | func (p *Part) Encode(writer io.Writer) error {
if p.Header == nil {
p.Header = make(textproto.MIMEHeader)
}
cte := p.setupMIMEHeaders()
// Encode this part.
b := bufio.NewWriter(writer)
p.encodeHeader(b)
if len(p.Content) > 0 {
b.Write(crnl)
if err := p.encodeContent(b, cte); err != nil {
return err
... | go | func (p *Part) Encode(writer io.Writer) error {
if p.Header == nil {
p.Header = make(textproto.MIMEHeader)
}
cte := p.setupMIMEHeaders()
// Encode this part.
b := bufio.NewWriter(writer)
p.encodeHeader(b)
if len(p.Content) > 0 {
b.Write(crnl)
if err := p.encodeContent(b, cte); err != nil {
return err
... | [
"func",
"(",
"p",
"*",
"Part",
")",
"Encode",
"(",
"writer",
"io",
".",
"Writer",
")",
"error",
"{",
"if",
"p",
".",
"Header",
"==",
"nil",
"{",
"p",
".",
"Header",
"=",
"make",
"(",
"textproto",
".",
"MIMEHeader",
")",
"\n",
"}",
"\n",
"cte",
... | // Encode writes this Part and all its children to the specified writer in MIME format. | [
"Encode",
"writes",
"this",
"Part",
"and",
"all",
"its",
"children",
"to",
"the",
"specified",
"writer",
"in",
"MIME",
"format",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/encode.go#L32-L64 | test |
jhillyerd/enmime | encode.go | encodeHeader | func (p *Part) encodeHeader(b *bufio.Writer) {
keys := make([]string, 0, len(p.Header))
for k := range p.Header {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
for _, v := range p.Header[k] {
encv := v
switch selectTransferEncoding([]byte(v), true) {
case teBase64:
encv = mi... | go | func (p *Part) encodeHeader(b *bufio.Writer) {
keys := make([]string, 0, len(p.Header))
for k := range p.Header {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
for _, v := range p.Header[k] {
encv := v
switch selectTransferEncoding([]byte(v), true) {
case teBase64:
encv = mi... | [
"func",
"(",
"p",
"*",
"Part",
")",
"encodeHeader",
"(",
"b",
"*",
"bufio",
".",
"Writer",
")",
"{",
"keys",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"p",
".",
"Header",
")",
")",
"\n",
"for",
"k",
":=",
"range",
"p",... | // encodeHeader writes out a sorted list of headers. | [
"encodeHeader",
"writes",
"out",
"a",
"sorted",
"list",
"of",
"headers",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/encode.go#L131-L152 | test |
jhillyerd/enmime | encode.go | encodeContent | func (p *Part) encodeContent(b *bufio.Writer, cte transferEncoding) (err error) {
switch cte {
case teBase64:
enc := base64.StdEncoding
text := make([]byte, enc.EncodedLen(len(p.Content)))
base64.StdEncoding.Encode(text, p.Content)
// Wrap lines.
lineLen := 76
for len(text) > 0 {
if lineLen > len(text)... | go | func (p *Part) encodeContent(b *bufio.Writer, cte transferEncoding) (err error) {
switch cte {
case teBase64:
enc := base64.StdEncoding
text := make([]byte, enc.EncodedLen(len(p.Content)))
base64.StdEncoding.Encode(text, p.Content)
// Wrap lines.
lineLen := 76
for len(text) > 0 {
if lineLen > len(text)... | [
"func",
"(",
"p",
"*",
"Part",
")",
"encodeContent",
"(",
"b",
"*",
"bufio",
".",
"Writer",
",",
"cte",
"transferEncoding",
")",
"(",
"err",
"error",
")",
"{",
"switch",
"cte",
"{",
"case",
"teBase64",
":",
"enc",
":=",
"base64",
".",
"StdEncoding",
... | // encodeContent writes out the content in the selected encoding. | [
"encodeContent",
"writes",
"out",
"the",
"content",
"in",
"the",
"selected",
"encoding",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/encode.go#L155-L183 | test |
jhillyerd/enmime | encode.go | selectTransferEncoding | func selectTransferEncoding(content []byte, quoteLineBreaks bool) transferEncoding {
if len(content) == 0 {
return te7Bit
}
// Binary chars remaining before we choose b64 encoding.
threshold := b64Percent * len(content) / 100
bincount := 0
for _, b := range content {
if (b < ' ' || '~' < b) && b != '\t' {
... | go | func selectTransferEncoding(content []byte, quoteLineBreaks bool) transferEncoding {
if len(content) == 0 {
return te7Bit
}
// Binary chars remaining before we choose b64 encoding.
threshold := b64Percent * len(content) / 100
bincount := 0
for _, b := range content {
if (b < ' ' || '~' < b) && b != '\t' {
... | [
"func",
"selectTransferEncoding",
"(",
"content",
"[",
"]",
"byte",
",",
"quoteLineBreaks",
"bool",
")",
"transferEncoding",
"{",
"if",
"len",
"(",
"content",
")",
"==",
"0",
"{",
"return",
"te7Bit",
"\n",
"}",
"\n",
"threshold",
":=",
"b64Percent",
"*",
"... | // selectTransferEncoding scans content for non-ASCII characters and selects 'b' or 'q' encoding. | [
"selectTransferEncoding",
"scans",
"content",
"for",
"non",
"-",
"ASCII",
"characters",
"and",
"selects",
"b",
"or",
"q",
"encoding",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/encode.go#L186-L208 | test |
jhillyerd/enmime | encode.go | setParamValue | func setParamValue(p map[string]string, k, v string) {
if v != "" {
p[k] = v
}
} | go | func setParamValue(p map[string]string, k, v string) {
if v != "" {
p[k] = v
}
} | [
"func",
"setParamValue",
"(",
"p",
"map",
"[",
"string",
"]",
"string",
",",
"k",
",",
"v",
"string",
")",
"{",
"if",
"v",
"!=",
"\"\"",
"{",
"p",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}"
] | // setParamValue will ignore empty values | [
"setParamValue",
"will",
"ignore",
"empty",
"values"
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/encode.go#L211-L215 | test |
jhillyerd/enmime | internal/coding/base64.go | NewBase64Cleaner | func NewBase64Cleaner(r io.Reader) *Base64Cleaner {
return &Base64Cleaner{
Errors: make([]error, 0),
r: r,
}
} | go | func NewBase64Cleaner(r io.Reader) *Base64Cleaner {
return &Base64Cleaner{
Errors: make([]error, 0),
r: r,
}
} | [
"func",
"NewBase64Cleaner",
"(",
"r",
"io",
".",
"Reader",
")",
"*",
"Base64Cleaner",
"{",
"return",
"&",
"Base64Cleaner",
"{",
"Errors",
":",
"make",
"(",
"[",
"]",
"error",
",",
"0",
")",
",",
"r",
":",
"r",
",",
"}",
"\n",
"}"
] | // NewBase64Cleaner returns a Base64Cleaner object for the specified reader. Base64Cleaner
// implements the io.Reader interface. | [
"NewBase64Cleaner",
"returns",
"a",
"Base64Cleaner",
"object",
"for",
"the",
"specified",
"reader",
".",
"Base64Cleaner",
"implements",
"the",
"io",
".",
"Reader",
"interface",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/internal/coding/base64.go#L35-L40 | test |
jhillyerd/enmime | header.go | decodeToUTF8Base64Header | func decodeToUTF8Base64Header(input string) string {
if !strings.Contains(input, "=?") {
// Don't scan if there is nothing to do here
return input
}
tokens := strings.FieldsFunc(input, whiteSpaceRune)
output := make([]string, len(tokens))
for i, token := range tokens {
if len(token) > 4 && strings.Contains(... | go | func decodeToUTF8Base64Header(input string) string {
if !strings.Contains(input, "=?") {
// Don't scan if there is nothing to do here
return input
}
tokens := strings.FieldsFunc(input, whiteSpaceRune)
output := make([]string, len(tokens))
for i, token := range tokens {
if len(token) > 4 && strings.Contains(... | [
"func",
"decodeToUTF8Base64Header",
"(",
"input",
"string",
")",
"string",
"{",
"if",
"!",
"strings",
".",
"Contains",
"(",
"input",
",",
"\"=?\"",
")",
"{",
"return",
"input",
"\n",
"}",
"\n",
"tokens",
":=",
"strings",
".",
"FieldsFunc",
"(",
"input",
... | // decodeToUTF8Base64Header decodes a MIME header per RFC 2047, reencoding to =?utf-8b? | [
"decodeToUTF8Base64Header",
"decodes",
"a",
"MIME",
"header",
"per",
"RFC",
"2047",
"reencoding",
"to",
"=",
"?utf",
"-",
"8b?"
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/header.go#L167-L197 | test |
jhillyerd/enmime | header.go | parseMediaType | func parseMediaType(ctype string) (mtype string, params map[string]string, invalidParams []string, err error) {
mtype, params, err = mime.ParseMediaType(ctype)
if err != nil {
// Small hack to remove harmless charset duplicate params.
mctype := fixMangledMediaType(ctype, ";")
mtype, params, err = mime.ParseMedi... | go | func parseMediaType(ctype string) (mtype string, params map[string]string, invalidParams []string, err error) {
mtype, params, err = mime.ParseMediaType(ctype)
if err != nil {
// Small hack to remove harmless charset duplicate params.
mctype := fixMangledMediaType(ctype, ";")
mtype, params, err = mime.ParseMedi... | [
"func",
"parseMediaType",
"(",
"ctype",
"string",
")",
"(",
"mtype",
"string",
",",
"params",
"map",
"[",
"string",
"]",
"string",
",",
"invalidParams",
"[",
"]",
"string",
",",
"err",
"error",
")",
"{",
"mtype",
",",
"params",
",",
"err",
"=",
"mime",... | // parseMediaType is a more tolerant implementation of Go's mime.ParseMediaType function. | [
"parseMediaType",
"is",
"a",
"more",
"tolerant",
"implementation",
"of",
"Go",
"s",
"mime",
".",
"ParseMediaType",
"function",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/header.go#L200-L233 | test |
jhillyerd/enmime | header.go | fixMangledMediaType | func fixMangledMediaType(mtype, sep string) string {
if mtype == "" {
return ""
}
parts := strings.Split(mtype, sep)
mtype = ""
for i, p := range parts {
switch i {
case 0:
if p == "" {
// The content type is completely missing. Put in a placeholder.
p = ctPlaceholder
}
default:
if !string... | go | func fixMangledMediaType(mtype, sep string) string {
if mtype == "" {
return ""
}
parts := strings.Split(mtype, sep)
mtype = ""
for i, p := range parts {
switch i {
case 0:
if p == "" {
// The content type is completely missing. Put in a placeholder.
p = ctPlaceholder
}
default:
if !string... | [
"func",
"fixMangledMediaType",
"(",
"mtype",
",",
"sep",
"string",
")",
"string",
"{",
"if",
"mtype",
"==",
"\"\"",
"{",
"return",
"\"\"",
"\n",
"}",
"\n",
"parts",
":=",
"strings",
".",
"Split",
"(",
"mtype",
",",
"sep",
")",
"\n",
"mtype",
"=",
"\"... | // fixMangledMediaType is used to insert ; separators into media type strings that lack them, and
// remove repeated parameters. | [
"fixMangledMediaType",
"is",
"used",
"to",
"insert",
";",
"separators",
"into",
"media",
"type",
"strings",
"that",
"lack",
"them",
"and",
"remove",
"repeated",
"parameters",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/header.go#L237-L283 | test |
jhillyerd/enmime | detect.go | detectMultipartMessage | func detectMultipartMessage(root *Part) bool {
// Parse top-level multipart
ctype := root.Header.Get(hnContentType)
mediatype, _, _, err := parseMediaType(ctype)
if err != nil {
return false
}
// According to rfc2046#section-5.1.7 all other multipart should
// be treated as multipart/mixed
return strings.HasP... | go | func detectMultipartMessage(root *Part) bool {
// Parse top-level multipart
ctype := root.Header.Get(hnContentType)
mediatype, _, _, err := parseMediaType(ctype)
if err != nil {
return false
}
// According to rfc2046#section-5.1.7 all other multipart should
// be treated as multipart/mixed
return strings.HasP... | [
"func",
"detectMultipartMessage",
"(",
"root",
"*",
"Part",
")",
"bool",
"{",
"ctype",
":=",
"root",
".",
"Header",
".",
"Get",
"(",
"hnContentType",
")",
"\n",
"mediatype",
",",
"_",
",",
"_",
",",
"err",
":=",
"parseMediaType",
"(",
"ctype",
")",
"\n... | // detectMultipartMessage returns true if the message has a recognized multipart Content-Type header | [
"detectMultipartMessage",
"returns",
"true",
"if",
"the",
"message",
"has",
"a",
"recognized",
"multipart",
"Content",
"-",
"Type",
"header"
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/detect.go#L9-L19 | test |
jhillyerd/enmime | detect.go | detectBinaryBody | func detectBinaryBody(root *Part) bool {
if detectTextHeader(root.Header, true) {
return false
}
isBin := detectAttachmentHeader(root.Header)
if !isBin {
// This must be an attachment, if the Content-Type is not
// 'text/plain' or 'text/html'.
// Example:
// Content-Type: application/pdf; name="doc.pdf"
... | go | func detectBinaryBody(root *Part) bool {
if detectTextHeader(root.Header, true) {
return false
}
isBin := detectAttachmentHeader(root.Header)
if !isBin {
// This must be an attachment, if the Content-Type is not
// 'text/plain' or 'text/html'.
// Example:
// Content-Type: application/pdf; name="doc.pdf"
... | [
"func",
"detectBinaryBody",
"(",
"root",
"*",
"Part",
")",
"bool",
"{",
"if",
"detectTextHeader",
"(",
"root",
".",
"Header",
",",
"true",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"isBin",
":=",
"detectAttachmentHeader",
"(",
"root",
".",
"Header",
... | // detectBinaryBody returns true if the mail header defines a binary body. | [
"detectBinaryBody",
"returns",
"true",
"if",
"the",
"mail",
"header",
"defines",
"a",
"binary",
"body",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/detect.go#L64-L83 | test |
jhillyerd/enmime | match.go | BreadthMatchFirst | func (p *Part) BreadthMatchFirst(matcher PartMatcher) *Part {
q := list.New()
q.PushBack(p)
// Push children onto queue and attempt to match in that order
for q.Len() > 0 {
e := q.Front()
p := e.Value.(*Part)
if matcher(p) {
return p
}
q.Remove(e)
c := p.FirstChild
for c != nil {
q.PushBack(c)
... | go | func (p *Part) BreadthMatchFirst(matcher PartMatcher) *Part {
q := list.New()
q.PushBack(p)
// Push children onto queue and attempt to match in that order
for q.Len() > 0 {
e := q.Front()
p := e.Value.(*Part)
if matcher(p) {
return p
}
q.Remove(e)
c := p.FirstChild
for c != nil {
q.PushBack(c)
... | [
"func",
"(",
"p",
"*",
"Part",
")",
"BreadthMatchFirst",
"(",
"matcher",
"PartMatcher",
")",
"*",
"Part",
"{",
"q",
":=",
"list",
".",
"New",
"(",
")",
"\n",
"q",
".",
"PushBack",
"(",
"p",
")",
"\n",
"for",
"q",
".",
"Len",
"(",
")",
">",
"0",... | // BreadthMatchFirst performs a breadth first search of the Part tree and returns the first part
// that causes the given matcher to return true | [
"BreadthMatchFirst",
"performs",
"a",
"breadth",
"first",
"search",
"of",
"the",
"Part",
"tree",
"and",
"returns",
"the",
"first",
"part",
"that",
"causes",
"the",
"given",
"matcher",
"to",
"return",
"true"
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/match.go#L14-L34 | test |
jhillyerd/enmime | match.go | BreadthMatchAll | func (p *Part) BreadthMatchAll(matcher PartMatcher) []*Part {
q := list.New()
q.PushBack(p)
matches := make([]*Part, 0, 10)
// Push children onto queue and attempt to match in that order
for q.Len() > 0 {
e := q.Front()
p := e.Value.(*Part)
if matcher(p) {
matches = append(matches, p)
}
q.Remove(e)
... | go | func (p *Part) BreadthMatchAll(matcher PartMatcher) []*Part {
q := list.New()
q.PushBack(p)
matches := make([]*Part, 0, 10)
// Push children onto queue and attempt to match in that order
for q.Len() > 0 {
e := q.Front()
p := e.Value.(*Part)
if matcher(p) {
matches = append(matches, p)
}
q.Remove(e)
... | [
"func",
"(",
"p",
"*",
"Part",
")",
"BreadthMatchAll",
"(",
"matcher",
"PartMatcher",
")",
"[",
"]",
"*",
"Part",
"{",
"q",
":=",
"list",
".",
"New",
"(",
")",
"\n",
"q",
".",
"PushBack",
"(",
"p",
")",
"\n",
"matches",
":=",
"make",
"(",
"[",
... | // BreadthMatchAll performs a breadth first search of the Part tree and returns all parts that cause
// the given matcher to return true | [
"BreadthMatchAll",
"performs",
"a",
"breadth",
"first",
"search",
"of",
"the",
"Part",
"tree",
"and",
"returns",
"all",
"parts",
"that",
"cause",
"the",
"given",
"matcher",
"to",
"return",
"true"
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/match.go#L38-L60 | test |
jhillyerd/enmime | match.go | DepthMatchFirst | func (p *Part) DepthMatchFirst(matcher PartMatcher) *Part {
root := p
for {
if matcher(p) {
return p
}
c := p.FirstChild
if c != nil {
p = c
} else {
for p.NextSibling == nil {
if p == root {
return nil
}
p = p.Parent
}
p = p.NextSibling
}
}
} | go | func (p *Part) DepthMatchFirst(matcher PartMatcher) *Part {
root := p
for {
if matcher(p) {
return p
}
c := p.FirstChild
if c != nil {
p = c
} else {
for p.NextSibling == nil {
if p == root {
return nil
}
p = p.Parent
}
p = p.NextSibling
}
}
} | [
"func",
"(",
"p",
"*",
"Part",
")",
"DepthMatchFirst",
"(",
"matcher",
"PartMatcher",
")",
"*",
"Part",
"{",
"root",
":=",
"p",
"\n",
"for",
"{",
"if",
"matcher",
"(",
"p",
")",
"{",
"return",
"p",
"\n",
"}",
"\n",
"c",
":=",
"p",
".",
"FirstChil... | // DepthMatchFirst performs a depth first search of the Part tree and returns the first part that
// causes the given matcher to return true | [
"DepthMatchFirst",
"performs",
"a",
"depth",
"first",
"search",
"of",
"the",
"Part",
"tree",
"and",
"returns",
"the",
"first",
"part",
"that",
"causes",
"the",
"given",
"matcher",
"to",
"return",
"true"
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/match.go#L64-L83 | test |
jhillyerd/enmime | match.go | DepthMatchAll | func (p *Part) DepthMatchAll(matcher PartMatcher) []*Part {
root := p
matches := make([]*Part, 0, 10)
for {
if matcher(p) {
matches = append(matches, p)
}
c := p.FirstChild
if c != nil {
p = c
} else {
for p.NextSibling == nil {
if p == root {
return matches
}
p = p.Parent
}
... | go | func (p *Part) DepthMatchAll(matcher PartMatcher) []*Part {
root := p
matches := make([]*Part, 0, 10)
for {
if matcher(p) {
matches = append(matches, p)
}
c := p.FirstChild
if c != nil {
p = c
} else {
for p.NextSibling == nil {
if p == root {
return matches
}
p = p.Parent
}
... | [
"func",
"(",
"p",
"*",
"Part",
")",
"DepthMatchAll",
"(",
"matcher",
"PartMatcher",
")",
"[",
"]",
"*",
"Part",
"{",
"root",
":=",
"p",
"\n",
"matches",
":=",
"make",
"(",
"[",
"]",
"*",
"Part",
",",
"0",
",",
"10",
")",
"\n",
"for",
"{",
"if",... | // DepthMatchAll performs a depth first search of the Part tree and returns all parts that causes
// the given matcher to return true | [
"DepthMatchAll",
"performs",
"a",
"depth",
"first",
"search",
"of",
"the",
"Part",
"tree",
"and",
"returns",
"all",
"parts",
"that",
"causes",
"the",
"given",
"matcher",
"to",
"return",
"true"
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/match.go#L87-L107 | test |
jhillyerd/enmime | internal/stringutil/unicode.go | ToASCII | func ToASCII(s string) string {
// unicode.Mn: nonspacing marks
tr := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), runes.Map(mapLatinSpecial),
norm.NFC)
r, _, _ := transform.String(tr, s)
return r
} | go | func ToASCII(s string) string {
// unicode.Mn: nonspacing marks
tr := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), runes.Map(mapLatinSpecial),
norm.NFC)
r, _, _ := transform.String(tr, s)
return r
} | [
"func",
"ToASCII",
"(",
"s",
"string",
")",
"string",
"{",
"tr",
":=",
"transform",
".",
"Chain",
"(",
"norm",
".",
"NFD",
",",
"runes",
".",
"Remove",
"(",
"runes",
".",
"In",
"(",
"unicode",
".",
"Mn",
")",
")",
",",
"runes",
".",
"Map",
"(",
... | // ToASCII converts unicode to ASCII by stripping accents and converting some special characters
// into their ASCII approximations. Anything else will be replaced with an underscore. | [
"ToASCII",
"converts",
"unicode",
"to",
"ASCII",
"by",
"stripping",
"accents",
"and",
"converting",
"some",
"special",
"characters",
"into",
"their",
"ASCII",
"approximations",
".",
"Anything",
"else",
"will",
"be",
"replaced",
"with",
"an",
"underscore",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/internal/stringutil/unicode.go#L47-L53 | test |
jhillyerd/enmime | part.go | NewPart | func NewPart(contentType string) *Part {
return &Part{
Header: make(textproto.MIMEHeader),
ContentType: contentType,
}
} | go | func NewPart(contentType string) *Part {
return &Part{
Header: make(textproto.MIMEHeader),
ContentType: contentType,
}
} | [
"func",
"NewPart",
"(",
"contentType",
"string",
")",
"*",
"Part",
"{",
"return",
"&",
"Part",
"{",
"Header",
":",
"make",
"(",
"textproto",
".",
"MIMEHeader",
")",
",",
"ContentType",
":",
"contentType",
",",
"}",
"\n",
"}"
] | // NewPart creates a new Part object. | [
"NewPart",
"creates",
"a",
"new",
"Part",
"object",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/part.go#L47-L52 | test |
jhillyerd/enmime | part.go | AddChild | func (p *Part) AddChild(child *Part) {
if p == child {
// Prevent paradox.
return
}
if p != nil {
if p.FirstChild == nil {
// Make it the first child.
p.FirstChild = child
} else {
// Append to sibling chain.
current := p.FirstChild
for current.NextSibling != nil {
current = current.NextSi... | go | func (p *Part) AddChild(child *Part) {
if p == child {
// Prevent paradox.
return
}
if p != nil {
if p.FirstChild == nil {
// Make it the first child.
p.FirstChild = child
} else {
// Append to sibling chain.
current := p.FirstChild
for current.NextSibling != nil {
current = current.NextSi... | [
"func",
"(",
"p",
"*",
"Part",
")",
"AddChild",
"(",
"child",
"*",
"Part",
")",
"{",
"if",
"p",
"==",
"child",
"{",
"return",
"\n",
"}",
"\n",
"if",
"p",
"!=",
"nil",
"{",
"if",
"p",
".",
"FirstChild",
"==",
"nil",
"{",
"p",
".",
"FirstChild",
... | // AddChild adds a child part to either FirstChild or the end of the children NextSibling chain.
// The child may have siblings and children attached. This method will set the Parent field on
// child and all its siblings. Safe to call on nil. | [
"AddChild",
"adds",
"a",
"child",
"part",
"to",
"either",
"FirstChild",
"or",
"the",
"end",
"of",
"the",
"children",
"NextSibling",
"chain",
".",
"The",
"child",
"may",
"have",
"siblings",
"and",
"children",
"attached",
".",
"This",
"method",
"will",
"set",
... | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/part.go#L57-L87 | test |
jhillyerd/enmime | part.go | TextContent | func (p *Part) TextContent() bool {
if p.ContentType == "" {
// RFC 2045: no CT is equivalent to "text/plain; charset=us-ascii"
return true
}
return strings.HasPrefix(p.ContentType, "text/") ||
strings.HasPrefix(p.ContentType, ctMultipartPrefix)
} | go | func (p *Part) TextContent() bool {
if p.ContentType == "" {
// RFC 2045: no CT is equivalent to "text/plain; charset=us-ascii"
return true
}
return strings.HasPrefix(p.ContentType, "text/") ||
strings.HasPrefix(p.ContentType, ctMultipartPrefix)
} | [
"func",
"(",
"p",
"*",
"Part",
")",
"TextContent",
"(",
")",
"bool",
"{",
"if",
"p",
".",
"ContentType",
"==",
"\"\"",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"strings",
".",
"HasPrefix",
"(",
"p",
".",
"ContentType",
",",
"\"text/\"",
")",... | // TextContent indicates whether the content is text based on its content type. This value
// determines what content transfer encoding scheme to use. | [
"TextContent",
"indicates",
"whether",
"the",
"content",
"is",
"text",
"based",
"on",
"its",
"content",
"type",
".",
"This",
"value",
"determines",
"what",
"content",
"transfer",
"encoding",
"scheme",
"to",
"use",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/part.go#L91-L98 | test |
jhillyerd/enmime | part.go | setupHeaders | func (p *Part) setupHeaders(r *bufio.Reader, defaultContentType string) error {
header, err := readHeader(r, p)
if err != nil {
return err
}
p.Header = header
ctype := header.Get(hnContentType)
if ctype == "" {
if defaultContentType == "" {
p.addWarning(ErrorMissingContentType, "MIME parts should have a Co... | go | func (p *Part) setupHeaders(r *bufio.Reader, defaultContentType string) error {
header, err := readHeader(r, p)
if err != nil {
return err
}
p.Header = header
ctype := header.Get(hnContentType)
if ctype == "" {
if defaultContentType == "" {
p.addWarning(ErrorMissingContentType, "MIME parts should have a Co... | [
"func",
"(",
"p",
"*",
"Part",
")",
"setupHeaders",
"(",
"r",
"*",
"bufio",
".",
"Reader",
",",
"defaultContentType",
"string",
")",
"error",
"{",
"header",
",",
"err",
":=",
"readHeader",
"(",
"r",
",",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{... | // setupHeaders reads the header, then populates the MIME header values for this Part. | [
"setupHeaders",
"reads",
"the",
"header",
"then",
"populates",
"the",
"MIME",
"header",
"values",
"for",
"this",
"Part",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/part.go#L101-L137 | test |
jhillyerd/enmime | part.go | setupContentHeaders | func (p *Part) setupContentHeaders(mediaParams map[string]string) {
// Determine content disposition, filename, character set.
disposition, dparams, _, err := parseMediaType(p.Header.Get(hnContentDisposition))
if err == nil {
// Disposition is optional
p.Disposition = disposition
p.FileName = decodeHeader(dpar... | go | func (p *Part) setupContentHeaders(mediaParams map[string]string) {
// Determine content disposition, filename, character set.
disposition, dparams, _, err := parseMediaType(p.Header.Get(hnContentDisposition))
if err == nil {
// Disposition is optional
p.Disposition = disposition
p.FileName = decodeHeader(dpar... | [
"func",
"(",
"p",
"*",
"Part",
")",
"setupContentHeaders",
"(",
"mediaParams",
"map",
"[",
"string",
"]",
"string",
")",
"{",
"disposition",
",",
"dparams",
",",
"_",
",",
"err",
":=",
"parseMediaType",
"(",
"p",
".",
"Header",
".",
"Get",
"(",
"hnCont... | // setupContentHeaders uses Content-Type media params and Content-Disposition headers to populate
// the disposition, filename, and charset fields. | [
"setupContentHeaders",
"uses",
"Content",
"-",
"Type",
"media",
"params",
"and",
"Content",
"-",
"Disposition",
"headers",
"to",
"populate",
"the",
"disposition",
"filename",
"and",
"charset",
"fields",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/part.go#L141-L161 | test |
jhillyerd/enmime | part.go | convertFromDetectedCharset | func (p *Part) convertFromDetectedCharset(r io.Reader) (io.Reader, error) {
// Attempt to detect character set from part content.
var cd *chardet.Detector
switch p.ContentType {
case "text/html":
cd = chardet.NewHtmlDetector()
default:
cd = chardet.NewTextDetector()
}
buf, err := ioutil.ReadAll(r)
if err !... | go | func (p *Part) convertFromDetectedCharset(r io.Reader) (io.Reader, error) {
// Attempt to detect character set from part content.
var cd *chardet.Detector
switch p.ContentType {
case "text/html":
cd = chardet.NewHtmlDetector()
default:
cd = chardet.NewTextDetector()
}
buf, err := ioutil.ReadAll(r)
if err !... | [
"func",
"(",
"p",
"*",
"Part",
")",
"convertFromDetectedCharset",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"io",
".",
"Reader",
",",
"error",
")",
"{",
"var",
"cd",
"*",
"chardet",
".",
"Detector",
"\n",
"switch",
"p",
".",
"ContentType",
"{",
"case"... | // convertFromDetectedCharset attempts to detect the character set for the given part, and returns
// an io.Reader that will convert from that charset to UTF-8. If the charset cannot be detected,
// this method adds a warning to the part and automatically falls back to using
// `convertFromStatedCharset` and returns th... | [
"convertFromDetectedCharset",
"attempts",
"to",
"detect",
"the",
"character",
"set",
"for",
"the",
"given",
"part",
"and",
"returns",
"an",
"io",
".",
"Reader",
"that",
"will",
"convert",
"from",
"that",
"charset",
"to",
"UTF",
"-",
"8",
".",
"If",
"the",
... | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/part.go#L167-L218 | test |
jhillyerd/enmime | part.go | Clone | func (p *Part) Clone(parent *Part) *Part {
if p == nil {
return nil
}
newPart := &Part{
PartID: p.PartID,
Header: p.Header,
Parent: parent,
Boundary: p.Boundary,
ContentID: p.ContentID,
ContentType: p.ContentType,
Disposition: p.Disposition,
FileName: p.FileName,
Charset: ... | go | func (p *Part) Clone(parent *Part) *Part {
if p == nil {
return nil
}
newPart := &Part{
PartID: p.PartID,
Header: p.Header,
Parent: parent,
Boundary: p.Boundary,
ContentID: p.ContentID,
ContentType: p.ContentType,
Disposition: p.Disposition,
FileName: p.FileName,
Charset: ... | [
"func",
"(",
"p",
"*",
"Part",
")",
"Clone",
"(",
"parent",
"*",
"Part",
")",
"*",
"Part",
"{",
"if",
"p",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"newPart",
":=",
"&",
"Part",
"{",
"PartID",
":",
"p",
".",
"PartID",
",",
"Header",
... | // Clone returns a clone of the current Part. | [
"Clone",
"returns",
"a",
"clone",
"of",
"the",
"current",
"Part",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/part.go#L310-L333 | test |
jhillyerd/enmime | part.go | ReadParts | func ReadParts(r io.Reader) (*Part, error) {
br := bufio.NewReader(r)
root := &Part{PartID: "0"}
// Read header; top-level default CT is text/plain us-ascii according to RFC 822.
err := root.setupHeaders(br, `text/plain; charset="us-ascii"`)
if err != nil {
return nil, err
}
if strings.HasPrefix(root.ContentTy... | go | func ReadParts(r io.Reader) (*Part, error) {
br := bufio.NewReader(r)
root := &Part{PartID: "0"}
// Read header; top-level default CT is text/plain us-ascii according to RFC 822.
err := root.setupHeaders(br, `text/plain; charset="us-ascii"`)
if err != nil {
return nil, err
}
if strings.HasPrefix(root.ContentTy... | [
"func",
"ReadParts",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"*",
"Part",
",",
"error",
")",
"{",
"br",
":=",
"bufio",
".",
"NewReader",
"(",
"r",
")",
"\n",
"root",
":=",
"&",
"Part",
"{",
"PartID",
":",
"\"0\"",
"}",
"\n",
"err",
":=",
"root... | // ReadParts reads a MIME document from the provided reader and parses it into tree of Part objects. | [
"ReadParts",
"reads",
"a",
"MIME",
"document",
"from",
"the",
"provided",
"reader",
"and",
"parses",
"it",
"into",
"tree",
"of",
"Part",
"objects",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/part.go#L336-L357 | test |
jhillyerd/enmime | part.go | parseParts | func parseParts(parent *Part, reader *bufio.Reader) error {
firstRecursion := parent.Parent == nil
// Loop over MIME boundaries.
br := newBoundaryReader(reader, parent.Boundary)
for indexPartID := 1; true; indexPartID++ {
next, err := br.Next()
if err != nil && errors.Cause(err) != io.EOF {
return err
}
... | go | func parseParts(parent *Part, reader *bufio.Reader) error {
firstRecursion := parent.Parent == nil
// Loop over MIME boundaries.
br := newBoundaryReader(reader, parent.Boundary)
for indexPartID := 1; true; indexPartID++ {
next, err := br.Next()
if err != nil && errors.Cause(err) != io.EOF {
return err
}
... | [
"func",
"parseParts",
"(",
"parent",
"*",
"Part",
",",
"reader",
"*",
"bufio",
".",
"Reader",
")",
"error",
"{",
"firstRecursion",
":=",
"parent",
".",
"Parent",
"==",
"nil",
"\n",
"br",
":=",
"newBoundaryReader",
"(",
"reader",
",",
"parent",
".",
"Boun... | // parseParts recursively parses a MIME multipart document and sets each Parts PartID. | [
"parseParts",
"recursively",
"parses",
"a",
"MIME",
"multipart",
"document",
"and",
"sets",
"each",
"Parts",
"PartID",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/part.go#L360-L427 | test |
jhillyerd/enmime | internal/stringutil/uuid.go | UUID | func UUID() string {
uuid := make([]byte, 16)
uuidMutex.Lock()
_, _ = uuidRand.Read(uuid)
uuidMutex.Unlock()
// variant bits; see section 4.1.1
uuid[8] = uuid[8]&^0xc0 | 0x80
// version 4 (pseudo-random); see section 4.1.3
uuid[6] = uuid[6]&^0xf0 | 0x40
return fmt.Sprintf("%x-%x-%x-%x-%x", uuid[0:4], uuid[4:6]... | go | func UUID() string {
uuid := make([]byte, 16)
uuidMutex.Lock()
_, _ = uuidRand.Read(uuid)
uuidMutex.Unlock()
// variant bits; see section 4.1.1
uuid[8] = uuid[8]&^0xc0 | 0x80
// version 4 (pseudo-random); see section 4.1.3
uuid[6] = uuid[6]&^0xf0 | 0x40
return fmt.Sprintf("%x-%x-%x-%x-%x", uuid[0:4], uuid[4:6]... | [
"func",
"UUID",
"(",
")",
"string",
"{",
"uuid",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"16",
")",
"\n",
"uuidMutex",
".",
"Lock",
"(",
")",
"\n",
"_",
",",
"_",
"=",
"uuidRand",
".",
"Read",
"(",
"uuid",
")",
"\n",
"uuidMutex",
".",
"Unlock... | // UUID generates a random UUID according to RFC 4122. | [
"UUID",
"generates",
"a",
"random",
"UUID",
"according",
"to",
"RFC",
"4122",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/internal/stringutil/uuid.go#L14-L24 | test |
jhillyerd/enmime | internal/coding/quotedprint.go | NewQPCleaner | func NewQPCleaner(r io.Reader) *QPCleaner {
return &QPCleaner{
in: bufio.NewReader(r),
}
} | go | func NewQPCleaner(r io.Reader) *QPCleaner {
return &QPCleaner{
in: bufio.NewReader(r),
}
} | [
"func",
"NewQPCleaner",
"(",
"r",
"io",
".",
"Reader",
")",
"*",
"QPCleaner",
"{",
"return",
"&",
"QPCleaner",
"{",
"in",
":",
"bufio",
".",
"NewReader",
"(",
"r",
")",
",",
"}",
"\n",
"}"
] | // NewQPCleaner returns a QPCleaner for the specified reader. | [
"NewQPCleaner",
"returns",
"a",
"QPCleaner",
"for",
"the",
"specified",
"reader",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/internal/coding/quotedprint.go#L19-L23 | test |
jhillyerd/enmime | error.go | Error | func (e *Error) Error() string {
sev := "W"
if e.Severe {
sev = "E"
}
return fmt.Sprintf("[%s] %s: %s", sev, e.Name, e.Detail)
} | go | func (e *Error) Error() string {
sev := "W"
if e.Severe {
sev = "E"
}
return fmt.Sprintf("[%s] %s: %s", sev, e.Name, e.Detail)
} | [
"func",
"(",
"e",
"*",
"Error",
")",
"Error",
"(",
")",
"string",
"{",
"sev",
":=",
"\"W\"",
"\n",
"if",
"e",
".",
"Severe",
"{",
"sev",
"=",
"\"E\"",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"[%s] %s: %s\"",
",",
"sev",
",",
"e",... | // Error formats the enmime.Error as a string. | [
"Error",
"formats",
"the",
"enmime",
".",
"Error",
"as",
"a",
"string",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/error.go#L34-L40 | test |
jhillyerd/enmime | error.go | addError | func (p *Part) addError(name string, detailFmt string, args ...interface{}) {
p.Errors = append(
p.Errors,
&Error{
name,
fmt.Sprintf(detailFmt, args...),
true,
})
} | go | func (p *Part) addError(name string, detailFmt string, args ...interface{}) {
p.Errors = append(
p.Errors,
&Error{
name,
fmt.Sprintf(detailFmt, args...),
true,
})
} | [
"func",
"(",
"p",
"*",
"Part",
")",
"addError",
"(",
"name",
"string",
",",
"detailFmt",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"p",
".",
"Errors",
"=",
"append",
"(",
"p",
".",
"Errors",
",",
"&",
"Error",
"{",
"name",
",... | // addWarning builds a severe Error and appends to the Part error slice. | [
"addWarning",
"builds",
"a",
"severe",
"Error",
"and",
"appends",
"to",
"the",
"Part",
"error",
"slice",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/error.go#L48-L56 | test |
jhillyerd/enmime | error.go | addWarning | func (p *Part) addWarning(name string, detailFmt string, args ...interface{}) {
p.Errors = append(
p.Errors,
&Error{
name,
fmt.Sprintf(detailFmt, args...),
false,
})
} | go | func (p *Part) addWarning(name string, detailFmt string, args ...interface{}) {
p.Errors = append(
p.Errors,
&Error{
name,
fmt.Sprintf(detailFmt, args...),
false,
})
} | [
"func",
"(",
"p",
"*",
"Part",
")",
"addWarning",
"(",
"name",
"string",
",",
"detailFmt",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"p",
".",
"Errors",
"=",
"append",
"(",
"p",
".",
"Errors",
",",
"&",
"Error",
"{",
"name",
... | // addWarning builds a non-severe Error and appends to the Part error slice. | [
"addWarning",
"builds",
"a",
"non",
"-",
"severe",
"Error",
"and",
"appends",
"to",
"the",
"Part",
"error",
"slice",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/error.go#L59-L67 | test |
jhillyerd/enmime | internal/stringutil/wrap.go | Wrap | func Wrap(max int, strs ...string) []byte {
input := make([]byte, 0)
output := make([]byte, 0)
for _, s := range strs {
input = append(input, []byte(s)...)
}
if len(input) < max {
// Doesn't need to be wrapped
return input
}
ls := -1 // Last seen space index
lw := -1 // Last written byte index
ll := 0 /... | go | func Wrap(max int, strs ...string) []byte {
input := make([]byte, 0)
output := make([]byte, 0)
for _, s := range strs {
input = append(input, []byte(s)...)
}
if len(input) < max {
// Doesn't need to be wrapped
return input
}
ls := -1 // Last seen space index
lw := -1 // Last written byte index
ll := 0 /... | [
"func",
"Wrap",
"(",
"max",
"int",
",",
"strs",
"...",
"string",
")",
"[",
"]",
"byte",
"{",
"input",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
")",
"\n",
"output",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
")",
"\n",
"for",
"_",
... | // Wrap builds a byte slice from strs, wrapping on word boundaries before max chars | [
"Wrap",
"builds",
"a",
"byte",
"slice",
"from",
"strs",
"wrapping",
"on",
"word",
"boundaries",
"before",
"max",
"chars"
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/internal/stringutil/wrap.go#L4-L36 | test |
jhillyerd/enmime | internal/coding/charsets.go | ConvertToUTF8String | func ConvertToUTF8String(charset string, textBytes []byte) (string, error) {
if strings.ToLower(charset) == utf8 {
return string(textBytes), nil
}
csentry, ok := encodings[strings.ToLower(charset)]
if !ok {
return "", fmt.Errorf("Unsupported charset %q", charset)
}
input := bytes.NewReader(textBytes)
reader ... | go | func ConvertToUTF8String(charset string, textBytes []byte) (string, error) {
if strings.ToLower(charset) == utf8 {
return string(textBytes), nil
}
csentry, ok := encodings[strings.ToLower(charset)]
if !ok {
return "", fmt.Errorf("Unsupported charset %q", charset)
}
input := bytes.NewReader(textBytes)
reader ... | [
"func",
"ConvertToUTF8String",
"(",
"charset",
"string",
",",
"textBytes",
"[",
"]",
"byte",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"strings",
".",
"ToLower",
"(",
"charset",
")",
"==",
"utf8",
"{",
"return",
"string",
"(",
"textBytes",
")",
... | // ConvertToUTF8String uses the provided charset to decode a slice of bytes into a normal
// UTF-8 string. | [
"ConvertToUTF8String",
"uses",
"the",
"provided",
"charset",
"to",
"decode",
"a",
"slice",
"of",
"bytes",
"into",
"a",
"normal",
"UTF",
"-",
"8",
"string",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/internal/coding/charsets.go#L272-L287 | test |
jhillyerd/enmime | internal/stringutil/addr.go | JoinAddress | func JoinAddress(addrs []mail.Address) string {
if len(addrs) == 0 {
return ""
}
buf := &bytes.Buffer{}
for i, a := range addrs {
if i > 0 {
_, _ = buf.WriteString(", ")
}
_, _ = buf.WriteString(a.String())
}
return buf.String()
} | go | func JoinAddress(addrs []mail.Address) string {
if len(addrs) == 0 {
return ""
}
buf := &bytes.Buffer{}
for i, a := range addrs {
if i > 0 {
_, _ = buf.WriteString(", ")
}
_, _ = buf.WriteString(a.String())
}
return buf.String()
} | [
"func",
"JoinAddress",
"(",
"addrs",
"[",
"]",
"mail",
".",
"Address",
")",
"string",
"{",
"if",
"len",
"(",
"addrs",
")",
"==",
"0",
"{",
"return",
"\"\"",
"\n",
"}",
"\n",
"buf",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"for",
"i",
... | // JoinAddress formats a slice of Address structs such that they can be used in a To or Cc header. | [
"JoinAddress",
"formats",
"a",
"slice",
"of",
"Address",
"structs",
"such",
"that",
"they",
"can",
"be",
"used",
"in",
"a",
"To",
"or",
"Cc",
"header",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/internal/stringutil/addr.go#L9-L21 | test |
jhillyerd/enmime | cmd/utils.go | Printf | func (md *markdown) Printf(format string, args ...interface{}) {
fmt.Fprintf(md, format, args...)
} | go | func (md *markdown) Printf(format string, args ...interface{}) {
fmt.Fprintf(md, format, args...)
} | [
"func",
"(",
"md",
"*",
"markdown",
")",
"Printf",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"md",
",",
"format",
",",
"args",
"...",
")",
"\n",
"}"
] | // Printf implements fmt.Printf for markdown | [
"Printf",
"implements",
"fmt",
".",
"Printf",
"for",
"markdown"
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/cmd/utils.go#L36-L38 | test |
jhillyerd/enmime | cmd/utils.go | EnvelopeToMarkdown | func EnvelopeToMarkdown(w io.Writer, e *enmime.Envelope, name string) error {
md := &markdown{bufio.NewWriter(w)}
md.H1(name)
// Output a sorted list of headers, minus the ones displayed later
md.H2("Header")
if e.Root != nil && e.Root.Header != nil {
keys := make([]string, 0, len(e.Root.Header))
for k := ra... | go | func EnvelopeToMarkdown(w io.Writer, e *enmime.Envelope, name string) error {
md := &markdown{bufio.NewWriter(w)}
md.H1(name)
// Output a sorted list of headers, minus the ones displayed later
md.H2("Header")
if e.Root != nil && e.Root.Header != nil {
keys := make([]string, 0, len(e.Root.Header))
for k := ra... | [
"func",
"EnvelopeToMarkdown",
"(",
"w",
"io",
".",
"Writer",
",",
"e",
"*",
"enmime",
".",
"Envelope",
",",
"name",
"string",
")",
"error",
"{",
"md",
":=",
"&",
"markdown",
"{",
"bufio",
".",
"NewWriter",
"(",
"w",
")",
"}",
"\n",
"md",
".",
"H1",... | // EnvelopeToMarkdown renders the contents of an enmime.Envelope in Markdown format. Used by
// mime-dump and mime-extractor commands. | [
"EnvelopeToMarkdown",
"renders",
"the",
"contents",
"of",
"an",
"enmime",
".",
"Envelope",
"in",
"Markdown",
"format",
".",
"Used",
"by",
"mime",
"-",
"dump",
"and",
"mime",
"-",
"extractor",
"commands",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/cmd/utils.go#L47-L140 | test |
jhillyerd/enmime | cmd/utils.go | FormatPart | func FormatPart(w io.Writer, p *enmime.Part, indent string) {
if p == nil {
return
}
sibling := p.NextSibling
child := p.FirstChild
// Compute indent strings
myindent := indent + "`-- "
childindent := indent + " "
if sibling != nil {
myindent = indent + "|-- "
childindent = indent + "| "
}
if p.P... | go | func FormatPart(w io.Writer, p *enmime.Part, indent string) {
if p == nil {
return
}
sibling := p.NextSibling
child := p.FirstChild
// Compute indent strings
myindent := indent + "`-- "
childindent := indent + " "
if sibling != nil {
myindent = indent + "|-- "
childindent = indent + "| "
}
if p.P... | [
"func",
"FormatPart",
"(",
"w",
"io",
".",
"Writer",
",",
"p",
"*",
"enmime",
".",
"Part",
",",
"indent",
"string",
")",
"{",
"if",
"p",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"sibling",
":=",
"p",
".",
"NextSibling",
"\n",
"child",
":=",
"... | // FormatPart pretty prints the Part tree | [
"FormatPart",
"pretty",
"prints",
"the",
"Part",
"tree"
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/cmd/utils.go#L143-L186 | test |
jhillyerd/enmime | boundary.go | newBoundaryReader | func newBoundaryReader(reader *bufio.Reader, boundary string) *boundaryReader {
fullBoundary := []byte("\n--" + boundary + "--")
return &boundaryReader{
r: reader,
nlPrefix: fullBoundary[:len(fullBoundary)-2],
prefix: fullBoundary[1 : len(fullBoundary)-2],
final: fullBoundary[1:],
buffer: new(... | go | func newBoundaryReader(reader *bufio.Reader, boundary string) *boundaryReader {
fullBoundary := []byte("\n--" + boundary + "--")
return &boundaryReader{
r: reader,
nlPrefix: fullBoundary[:len(fullBoundary)-2],
prefix: fullBoundary[1 : len(fullBoundary)-2],
final: fullBoundary[1:],
buffer: new(... | [
"func",
"newBoundaryReader",
"(",
"reader",
"*",
"bufio",
".",
"Reader",
",",
"boundary",
"string",
")",
"*",
"boundaryReader",
"{",
"fullBoundary",
":=",
"[",
"]",
"byte",
"(",
"\"\\n--\"",
"+",
"\\n",
"+",
"boundary",
")",
"\n",
"\"--\"",
"\n",
"}"
] | // newBoundaryReader returns an initialized boundaryReader | [
"newBoundaryReader",
"returns",
"an",
"initialized",
"boundaryReader"
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/boundary.go#L28-L37 | test |
jhillyerd/enmime | boundary.go | Read | func (b *boundaryReader) Read(dest []byte) (n int, err error) {
if b.buffer.Len() >= len(dest) {
// This read request can be satisfied entirely by the buffer
return b.buffer.Read(dest)
}
peek, err := b.r.Peek(peekBufferSize)
peekEOF := (err == io.EOF)
if err != nil && !peekEOF && err != bufio.ErrBufferFull {
... | go | func (b *boundaryReader) Read(dest []byte) (n int, err error) {
if b.buffer.Len() >= len(dest) {
// This read request can be satisfied entirely by the buffer
return b.buffer.Read(dest)
}
peek, err := b.r.Peek(peekBufferSize)
peekEOF := (err == io.EOF)
if err != nil && !peekEOF && err != bufio.ErrBufferFull {
... | [
"func",
"(",
"b",
"*",
"boundaryReader",
")",
"Read",
"(",
"dest",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"if",
"b",
".",
"buffer",
".",
"Len",
"(",
")",
">=",
"len",
"(",
"dest",
")",
"{",
"return",
"b",
".",
... | // Read returns a buffer containing the content up until boundary | [
"Read",
"returns",
"a",
"buffer",
"containing",
"the",
"content",
"up",
"until",
"boundary"
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/boundary.go#L40-L83 | test |
jhillyerd/enmime | boundary.go | Next | func (b *boundaryReader) Next() (bool, error) {
if b.finished {
return false, nil
}
if b.partsRead > 0 {
// Exhaust the current part to prevent errors when moving to the next part
_, _ = io.Copy(ioutil.Discard, b)
}
for {
line, err := b.r.ReadSlice('\n')
if err != nil && err != io.EOF {
return false, ... | go | func (b *boundaryReader) Next() (bool, error) {
if b.finished {
return false, nil
}
if b.partsRead > 0 {
// Exhaust the current part to prevent errors when moving to the next part
_, _ = io.Copy(ioutil.Discard, b)
}
for {
line, err := b.r.ReadSlice('\n')
if err != nil && err != io.EOF {
return false, ... | [
"func",
"(",
"b",
"*",
"boundaryReader",
")",
"Next",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"b",
".",
"finished",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"if",
"b",
".",
"partsRead",
">",
"0",
"{",
"_",
",",
"_",
"... | // Next moves over the boundary to the next part, returns true if there is another part to be read. | [
"Next",
"moves",
"over",
"the",
"boundary",
"to",
"the",
"next",
"part",
"returns",
"true",
"if",
"there",
"is",
"another",
"part",
"to",
"be",
"read",
"."
] | 874cc30e023f36bd1df525716196887b0f04851b | https://github.com/jhillyerd/enmime/blob/874cc30e023f36bd1df525716196887b0f04851b/boundary.go#L86-L124 | test |
senseyeio/roger | sexp/factory.go | Parse | func Parse(buf []byte, offset int) (interface{}, error) {
obj, _, err := parseReturningOffset(buf, offset)
return obj, err
} | go | func Parse(buf []byte, offset int) (interface{}, error) {
obj, _, err := parseReturningOffset(buf, offset)
return obj, err
} | [
"func",
"Parse",
"(",
"buf",
"[",
"]",
"byte",
",",
"offset",
"int",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"obj",
",",
"_",
",",
"err",
":=",
"parseReturningOffset",
"(",
"buf",
",",
"offset",
")",
"\n",
"return",
"obj",
",",
"... | // Parse converts a byte array containing R SEXP to a golang object.
// This can be converted to native golang types. | [
"Parse",
"converts",
"a",
"byte",
"array",
"containing",
"R",
"SEXP",
"to",
"a",
"golang",
"object",
".",
"This",
"can",
"be",
"converted",
"to",
"native",
"golang",
"types",
"."
] | 5a944f2c5ceb5139f926c5ae134202ec2abba71a | https://github.com/senseyeio/roger/blob/5a944f2c5ceb5139f926c5ae134202ec2abba71a/sexp/factory.go#L15-L18 | test |
senseyeio/roger | assign/factory.go | Assign | func Assign(symbol string, value interface{}) ([]byte, error) {
switch value.(type) {
case []float64:
return assignDoubleArray(symbol, value.([]float64))
case []int32:
return assignIntArray(symbol, value.([]int32))
case []string:
return assignStrArray(symbol, value.([]string))
case []byte:
return assignByt... | go | func Assign(symbol string, value interface{}) ([]byte, error) {
switch value.(type) {
case []float64:
return assignDoubleArray(symbol, value.([]float64))
case []int32:
return assignIntArray(symbol, value.([]int32))
case []string:
return assignStrArray(symbol, value.([]string))
case []byte:
return assignByt... | [
"func",
"Assign",
"(",
"symbol",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"switch",
"value",
".",
"(",
"type",
")",
"{",
"case",
"[",
"]",
"float64",
":",
"return",
"assignDoubleArray",
"(",
... | // Assign produces a command to assign a value to a variable within a go session | [
"Assign",
"produces",
"a",
"command",
"to",
"assign",
"a",
"value",
"to",
"a",
"variable",
"within",
"a",
"go",
"session"
] | 5a944f2c5ceb5139f926c5ae134202ec2abba71a | https://github.com/senseyeio/roger/blob/5a944f2c5ceb5139f926c5ae134202ec2abba71a/assign/factory.go#L6-L25 | test |
senseyeio/roger | client.go | NewRClient | func NewRClient(host string, port int64) (RClient, error) {
return NewRClientWithAuth(host, port, "", "")
} | go | func NewRClient(host string, port int64) (RClient, error) {
return NewRClientWithAuth(host, port, "", "")
} | [
"func",
"NewRClient",
"(",
"host",
"string",
",",
"port",
"int64",
")",
"(",
"RClient",
",",
"error",
")",
"{",
"return",
"NewRClientWithAuth",
"(",
"host",
",",
"port",
",",
"\"\"",
",",
"\"\"",
")",
"\n",
"}"
] | // NewRClient creates a RClient which will run commands on the RServe server located at the provided host and port | [
"NewRClient",
"creates",
"a",
"RClient",
"which",
"will",
"run",
"commands",
"on",
"the",
"RServe",
"server",
"located",
"at",
"the",
"provided",
"host",
"and",
"port"
] | 5a944f2c5ceb5139f926c5ae134202ec2abba71a | https://github.com/senseyeio/roger/blob/5a944f2c5ceb5139f926c5ae134202ec2abba71a/client.go#L32-L34 | test |
senseyeio/roger | client.go | NewRClientWithAuth | func NewRClientWithAuth(host string, port int64, user, password string) (RClient, error) {
addr, err := net.ResolveTCPAddr("tcp", host+":"+strconv.FormatInt(port, 10))
if err != nil {
return nil, err
}
rClient := &roger{
address: addr,
user: user,
password: password,
}
if _, err = rClient.Eval("'Te... | go | func NewRClientWithAuth(host string, port int64, user, password string) (RClient, error) {
addr, err := net.ResolveTCPAddr("tcp", host+":"+strconv.FormatInt(port, 10))
if err != nil {
return nil, err
}
rClient := &roger{
address: addr,
user: user,
password: password,
}
if _, err = rClient.Eval("'Te... | [
"func",
"NewRClientWithAuth",
"(",
"host",
"string",
",",
"port",
"int64",
",",
"user",
",",
"password",
"string",
")",
"(",
"RClient",
",",
"error",
")",
"{",
"addr",
",",
"err",
":=",
"net",
".",
"ResolveTCPAddr",
"(",
"\"tcp\"",
",",
"host",
"+",
"\... | // NewRClientWithAuth creates a RClient with the specified credentials and RServe server details | [
"NewRClientWithAuth",
"creates",
"a",
"RClient",
"with",
"the",
"specified",
"credentials",
"and",
"RServe",
"server",
"details"
] | 5a944f2c5ceb5139f926c5ae134202ec2abba71a | https://github.com/senseyeio/roger/blob/5a944f2c5ceb5139f926c5ae134202ec2abba71a/client.go#L37-L53 | test |
wawandco/fako | fakers.go | Register | func Register(identifier string, generator func() string) {
fakeType := inflect.Camelize(identifier)
customGenerators[fakeType] = generator
} | go | func Register(identifier string, generator func() string) {
fakeType := inflect.Camelize(identifier)
customGenerators[fakeType] = generator
} | [
"func",
"Register",
"(",
"identifier",
"string",
",",
"generator",
"func",
"(",
")",
"string",
")",
"{",
"fakeType",
":=",
"inflect",
".",
"Camelize",
"(",
"identifier",
")",
"\n",
"customGenerators",
"[",
"fakeType",
"]",
"=",
"generator",
"\n",
"}"
] | // Register allows user to add his own data generators for special cases
// that we could not cover with the generators that fako includes by default. | [
"Register",
"allows",
"user",
"to",
"add",
"his",
"own",
"data",
"generators",
"for",
"special",
"cases",
"that",
"we",
"could",
"not",
"cover",
"with",
"the",
"generators",
"that",
"fako",
"includes",
"by",
"default",
"."
] | c36a0bc97398c9100daa83ebef1c4e7af32c7654 | https://github.com/wawandco/fako/blob/c36a0bc97398c9100daa83ebef1c4e7af32c7654/fakers.go#L86-L89 | test |
wawandco/fako | fakers.go | Fuzz | func Fuzz(e interface{}) {
ty := reflect.TypeOf(e)
if ty.Kind() == reflect.Ptr {
ty = ty.Elem()
}
if ty.Kind() == reflect.Struct {
value := reflect.ValueOf(e).Elem()
for i := 0; i < ty.NumField(); i++ {
field := value.Field(i)
if field.CanSet() {
field.Set(fuzzValueFor(field.Kind()))
}
}
}... | go | func Fuzz(e interface{}) {
ty := reflect.TypeOf(e)
if ty.Kind() == reflect.Ptr {
ty = ty.Elem()
}
if ty.Kind() == reflect.Struct {
value := reflect.ValueOf(e).Elem()
for i := 0; i < ty.NumField(); i++ {
field := value.Field(i)
if field.CanSet() {
field.Set(fuzzValueFor(field.Kind()))
}
}
}... | [
"func",
"Fuzz",
"(",
"e",
"interface",
"{",
"}",
")",
"{",
"ty",
":=",
"reflect",
".",
"TypeOf",
"(",
"e",
")",
"\n",
"if",
"ty",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"{",
"ty",
"=",
"ty",
".",
"Elem",
"(",
")",
"\n",
"}",
"\... | // Fuzz Fills passed interface with random data based on the struct field type,
// take a look at fuzzValueFor for details on supported data types. | [
"Fuzz",
"Fills",
"passed",
"interface",
"with",
"random",
"data",
"based",
"on",
"the",
"struct",
"field",
"type",
"take",
"a",
"look",
"at",
"fuzzValueFor",
"for",
"details",
"on",
"supported",
"data",
"types",
"."
] | c36a0bc97398c9100daa83ebef1c4e7af32c7654 | https://github.com/wawandco/fako/blob/c36a0bc97398c9100daa83ebef1c4e7af32c7654/fakers.go#L93-L111 | test |
wawandco/fako | fakers.go | findFakeFunctionFor | func findFakeFunctionFor(fako string) func() string {
result := func() string { return "" }
for kind, function := range allGenerators() {
if fako == kind {
result = function
break
}
}
return result
} | go | func findFakeFunctionFor(fako string) func() string {
result := func() string { return "" }
for kind, function := range allGenerators() {
if fako == kind {
result = function
break
}
}
return result
} | [
"func",
"findFakeFunctionFor",
"(",
"fako",
"string",
")",
"func",
"(",
")",
"string",
"{",
"result",
":=",
"func",
"(",
")",
"string",
"{",
"return",
"\"\"",
"}",
"\n",
"for",
"kind",
",",
"function",
":=",
"range",
"allGenerators",
"(",
")",
"{",
"if... | //findFakeFunctionFor returns a faker function for a fako identifier | [
"findFakeFunctionFor",
"returns",
"a",
"faker",
"function",
"for",
"a",
"fako",
"identifier"
] | c36a0bc97398c9100daa83ebef1c4e7af32c7654 | https://github.com/wawandco/fako/blob/c36a0bc97398c9100daa83ebef1c4e7af32c7654/fakers.go#L123-L134 | test |
libp2p/go-libp2p-routing | options/options.go | Apply | func (opts *Options) Apply(options ...Option) error {
for _, o := range options {
if err := o(opts); err != nil {
return err
}
}
return nil
} | go | func (opts *Options) Apply(options ...Option) error {
for _, o := range options {
if err := o(opts); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"opts",
"*",
"Options",
")",
"Apply",
"(",
"options",
"...",
"Option",
")",
"error",
"{",
"for",
"_",
",",
"o",
":=",
"range",
"options",
"{",
"if",
"err",
":=",
"o",
"(",
"opts",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
... | // Apply applies the given options to this Options | [
"Apply",
"applies",
"the",
"given",
"options",
"to",
"this",
"Options"
] | 15c28e7faa25921fd1160412003fecdc70e09a5c | https://github.com/libp2p/go-libp2p-routing/blob/15c28e7faa25921fd1160412003fecdc70e09a5c/options/options.go#L16-L23 | test |
libp2p/go-libp2p-routing | options/options.go | ToOption | func (opts *Options) ToOption() Option {
return func(nopts *Options) error {
*nopts = *opts
if opts.Other != nil {
nopts.Other = make(map[interface{}]interface{}, len(opts.Other))
for k, v := range opts.Other {
nopts.Other[k] = v
}
}
return nil
}
} | go | func (opts *Options) ToOption() Option {
return func(nopts *Options) error {
*nopts = *opts
if opts.Other != nil {
nopts.Other = make(map[interface{}]interface{}, len(opts.Other))
for k, v := range opts.Other {
nopts.Other[k] = v
}
}
return nil
}
} | [
"func",
"(",
"opts",
"*",
"Options",
")",
"ToOption",
"(",
")",
"Option",
"{",
"return",
"func",
"(",
"nopts",
"*",
"Options",
")",
"error",
"{",
"*",
"nopts",
"=",
"*",
"opts",
"\n",
"if",
"opts",
".",
"Other",
"!=",
"nil",
"{",
"nopts",
".",
"O... | // ToOption converts this Options to a single Option. | [
"ToOption",
"converts",
"this",
"Options",
"to",
"a",
"single",
"Option",
"."
] | 15c28e7faa25921fd1160412003fecdc70e09a5c | https://github.com/libp2p/go-libp2p-routing/blob/15c28e7faa25921fd1160412003fecdc70e09a5c/options/options.go#L26-L37 | test |
libp2p/go-libp2p-routing | notifications/query.go | waitThenClose | func (e *eventChannel) waitThenClose() {
<-e.ctx.Done()
e.mu.Lock()
close(e.ch)
// 1. Signals that we're done.
// 2. Frees memory (in case we end up hanging on to this for a while).
e.ch = nil
e.mu.Unlock()
} | go | func (e *eventChannel) waitThenClose() {
<-e.ctx.Done()
e.mu.Lock()
close(e.ch)
// 1. Signals that we're done.
// 2. Frees memory (in case we end up hanging on to this for a while).
e.ch = nil
e.mu.Unlock()
} | [
"func",
"(",
"e",
"*",
"eventChannel",
")",
"waitThenClose",
"(",
")",
"{",
"<-",
"e",
".",
"ctx",
".",
"Done",
"(",
")",
"\n",
"e",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"close",
"(",
"e",
".",
"ch",
")",
"\n",
"e",
".",
"ch",
"=",
"nil"... | // waitThenClose is spawned in a goroutine when the channel is registered. This
// safely cleans up the channel when the context has been canceled. | [
"waitThenClose",
"is",
"spawned",
"in",
"a",
"goroutine",
"when",
"the",
"channel",
"is",
"registered",
".",
"This",
"safely",
"cleans",
"up",
"the",
"channel",
"when",
"the",
"context",
"has",
"been",
"canceled",
"."
] | 15c28e7faa25921fd1160412003fecdc70e09a5c | https://github.com/libp2p/go-libp2p-routing/blob/15c28e7faa25921fd1160412003fecdc70e09a5c/notifications/query.go#L44-L52 | test |
libp2p/go-libp2p-routing | notifications/query.go | send | func (e *eventChannel) send(ctx context.Context, ev *QueryEvent) {
e.mu.Lock()
// Closed.
if e.ch == nil {
e.mu.Unlock()
return
}
// in case the passed context is unrelated, wait on both.
select {
case e.ch <- ev:
case <-e.ctx.Done():
case <-ctx.Done():
}
e.mu.Unlock()
} | go | func (e *eventChannel) send(ctx context.Context, ev *QueryEvent) {
e.mu.Lock()
// Closed.
if e.ch == nil {
e.mu.Unlock()
return
}
// in case the passed context is unrelated, wait on both.
select {
case e.ch <- ev:
case <-e.ctx.Done():
case <-ctx.Done():
}
e.mu.Unlock()
} | [
"func",
"(",
"e",
"*",
"eventChannel",
")",
"send",
"(",
"ctx",
"context",
".",
"Context",
",",
"ev",
"*",
"QueryEvent",
")",
"{",
"e",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"e",
".",
"ch",
"==",
"nil",
"{",
"e",
".",
"mu",
".",
"Unlo... | // send sends an event on the event channel, aborting if either the passed or
// the internal context expire. | [
"send",
"sends",
"an",
"event",
"on",
"the",
"event",
"channel",
"aborting",
"if",
"either",
"the",
"passed",
"or",
"the",
"internal",
"context",
"expire",
"."
] | 15c28e7faa25921fd1160412003fecdc70e09a5c | https://github.com/libp2p/go-libp2p-routing/blob/15c28e7faa25921fd1160412003fecdc70e09a5c/notifications/query.go#L56-L70 | test |
VividCortex/ewma | ewma.go | NewMovingAverage | func NewMovingAverage(age ...float64) MovingAverage {
if len(age) == 0 || age[0] == AVG_METRIC_AGE {
return new(SimpleEWMA)
}
return &VariableEWMA{
decay: 2 / (age[0] + 1),
}
} | go | func NewMovingAverage(age ...float64) MovingAverage {
if len(age) == 0 || age[0] == AVG_METRIC_AGE {
return new(SimpleEWMA)
}
return &VariableEWMA{
decay: 2 / (age[0] + 1),
}
} | [
"func",
"NewMovingAverage",
"(",
"age",
"...",
"float64",
")",
"MovingAverage",
"{",
"if",
"len",
"(",
"age",
")",
"==",
"0",
"||",
"age",
"[",
"0",
"]",
"==",
"AVG_METRIC_AGE",
"{",
"return",
"new",
"(",
"SimpleEWMA",
")",
"\n",
"}",
"\n",
"return",
... | // NewMovingAverage constructs a MovingAverage that computes an average with the
// desired characteristics in the moving window or exponential decay. If no
// age is given, it constructs a default exponentially weighted implementation
// that consumes minimal memory. The age is related to the decay factor alpha
// by ... | [
"NewMovingAverage",
"constructs",
"a",
"MovingAverage",
"that",
"computes",
"an",
"average",
"with",
"the",
"desired",
"characteristics",
"in",
"the",
"moving",
"window",
"or",
"exponential",
"decay",
".",
"If",
"no",
"age",
"is",
"given",
"it",
"constructs",
"a... | 43880d236f695d39c62cf7aa4ebd4508c258e6c0 | https://github.com/VividCortex/ewma/blob/43880d236f695d39c62cf7aa4ebd4508c258e6c0/ewma.go#L40-L47 | test |
VividCortex/ewma | ewma.go | Set | func (e *VariableEWMA) Set(value float64) {
e.value = value
if e.count <= WARMUP_SAMPLES {
e.count = WARMUP_SAMPLES + 1
}
} | go | func (e *VariableEWMA) Set(value float64) {
e.value = value
if e.count <= WARMUP_SAMPLES {
e.count = WARMUP_SAMPLES + 1
}
} | [
"func",
"(",
"e",
"*",
"VariableEWMA",
")",
"Set",
"(",
"value",
"float64",
")",
"{",
"e",
".",
"value",
"=",
"value",
"\n",
"if",
"e",
".",
"count",
"<=",
"WARMUP_SAMPLES",
"{",
"e",
".",
"count",
"=",
"WARMUP_SAMPLES",
"+",
"1",
"\n",
"}",
"\n",
... | // Set sets the EWMA's value. | [
"Set",
"sets",
"the",
"EWMA",
"s",
"value",
"."
] | 43880d236f695d39c62cf7aa4ebd4508c258e6c0 | https://github.com/VividCortex/ewma/blob/43880d236f695d39c62cf7aa4ebd4508c258e6c0/ewma.go#L121-L126 | test |
nwaples/rardecode | archive50.go | calcKeys50 | func calcKeys50(pass, salt []byte, kdfCount int) [][]byte {
if len(salt) > maxPbkdf2Salt {
salt = salt[:maxPbkdf2Salt]
}
keys := make([][]byte, 3)
if len(keys) == 0 {
return keys
}
prf := hmac.New(sha256.New, pass)
prf.Write(salt)
prf.Write([]byte{0, 0, 0, 1})
t := prf.Sum(nil)
u := append([]byte(nil), ... | go | func calcKeys50(pass, salt []byte, kdfCount int) [][]byte {
if len(salt) > maxPbkdf2Salt {
salt = salt[:maxPbkdf2Salt]
}
keys := make([][]byte, 3)
if len(keys) == 0 {
return keys
}
prf := hmac.New(sha256.New, pass)
prf.Write(salt)
prf.Write([]byte{0, 0, 0, 1})
t := prf.Sum(nil)
u := append([]byte(nil), ... | [
"func",
"calcKeys50",
"(",
"pass",
",",
"salt",
"[",
"]",
"byte",
",",
"kdfCount",
"int",
")",
"[",
"]",
"[",
"]",
"byte",
"{",
"if",
"len",
"(",
"salt",
")",
">",
"maxPbkdf2Salt",
"{",
"salt",
"=",
"salt",
"[",
":",
"maxPbkdf2Salt",
"]",
"\n",
"... | // calcKeys50 calculates the keys used in RAR 5 archive processing.
// The returned slice of byte slices contains 3 keys.
// Key 0 is used for block or file decryption.
// Key 1 is optionally used for file checksum calculation.
// Key 2 is optionally used for password checking. | [
"calcKeys50",
"calculates",
"the",
"keys",
"used",
"in",
"RAR",
"5",
"archive",
"processing",
".",
"The",
"returned",
"slice",
"of",
"byte",
"slices",
"contains",
"3",
"keys",
".",
"Key",
"0",
"is",
"used",
"for",
"block",
"or",
"file",
"decryption",
".",
... | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/archive50.go#L139-L177 | test |
nwaples/rardecode | archive50.go | getKeys | func (a *archive50) getKeys(b *readBuf) (keys [][]byte, err error) {
if len(*b) < 17 {
return nil, errCorruptEncrypt
}
// read kdf count and salt
kdfCount := int(b.byte())
if kdfCount > maxKdfCount {
return nil, errCorruptEncrypt
}
kdfCount = 1 << uint(kdfCount)
salt := b.bytes(16)
// check cache of keys ... | go | func (a *archive50) getKeys(b *readBuf) (keys [][]byte, err error) {
if len(*b) < 17 {
return nil, errCorruptEncrypt
}
// read kdf count and salt
kdfCount := int(b.byte())
if kdfCount > maxKdfCount {
return nil, errCorruptEncrypt
}
kdfCount = 1 << uint(kdfCount)
salt := b.bytes(16)
// check cache of keys ... | [
"func",
"(",
"a",
"*",
"archive50",
")",
"getKeys",
"(",
"b",
"*",
"readBuf",
")",
"(",
"keys",
"[",
"]",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"*",
"b",
")",
"<",
"17",
"{",
"return",
"nil",
",",
"errCorruptEncrypt... | // getKeys reads kdfcount and salt from b and returns the corresponding encryption keys. | [
"getKeys",
"reads",
"kdfcount",
"and",
"salt",
"from",
"b",
"and",
"returns",
"the",
"corresponding",
"encryption",
"keys",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/archive50.go#L180-L208 | test |
nwaples/rardecode | archive50.go | checkPassword | func checkPassword(b *readBuf, keys [][]byte) error {
if len(*b) < 12 {
return nil // not enough bytes, ignore for the moment
}
pwcheck := b.bytes(8)
sum := b.bytes(4)
csum := sha256.Sum256(pwcheck)
if bytes.Equal(sum, csum[:len(sum)]) && !bytes.Equal(pwcheck, keys[2]) {
return errBadPassword
}
return nil
} | go | func checkPassword(b *readBuf, keys [][]byte) error {
if len(*b) < 12 {
return nil // not enough bytes, ignore for the moment
}
pwcheck := b.bytes(8)
sum := b.bytes(4)
csum := sha256.Sum256(pwcheck)
if bytes.Equal(sum, csum[:len(sum)]) && !bytes.Equal(pwcheck, keys[2]) {
return errBadPassword
}
return nil
} | [
"func",
"checkPassword",
"(",
"b",
"*",
"readBuf",
",",
"keys",
"[",
"]",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"*",
"b",
")",
"<",
"12",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"pwcheck",
":=",
"b",
".",
"bytes",
"(",
"8",
")... | // checkPassword calculates if a password is correct given password check data and keys. | [
"checkPassword",
"calculates",
"if",
"a",
"password",
"is",
"correct",
"given",
"password",
"check",
"data",
"and",
"keys",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/archive50.go#L211-L222 | test |
nwaples/rardecode | archive50.go | parseFileEncryptionRecord | func (a *archive50) parseFileEncryptionRecord(b readBuf, f *fileBlockHeader) error {
if ver := b.uvarint(); ver != 0 {
return errUnknownEncMethod
}
flags := b.uvarint()
keys, err := a.getKeys(&b)
if err != nil {
return err
}
f.key = keys[0]
if len(b) < 16 {
return errCorruptEncrypt
}
f.iv = b.bytes(16... | go | func (a *archive50) parseFileEncryptionRecord(b readBuf, f *fileBlockHeader) error {
if ver := b.uvarint(); ver != 0 {
return errUnknownEncMethod
}
flags := b.uvarint()
keys, err := a.getKeys(&b)
if err != nil {
return err
}
f.key = keys[0]
if len(b) < 16 {
return errCorruptEncrypt
}
f.iv = b.bytes(16... | [
"func",
"(",
"a",
"*",
"archive50",
")",
"parseFileEncryptionRecord",
"(",
"b",
"readBuf",
",",
"f",
"*",
"fileBlockHeader",
")",
"error",
"{",
"if",
"ver",
":=",
"b",
".",
"uvarint",
"(",
")",
";",
"ver",
"!=",
"0",
"{",
"return",
"errUnknownEncMethod",... | // parseFileEncryptionRecord processes the optional file encryption record from a file header. | [
"parseFileEncryptionRecord",
"processes",
"the",
"optional",
"file",
"encryption",
"record",
"from",
"a",
"file",
"header",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/archive50.go#L225-L251 | test |
nwaples/rardecode | archive50.go | parseEncryptionBlock | func (a *archive50) parseEncryptionBlock(b readBuf) error {
if ver := b.uvarint(); ver != 0 {
return errUnknownEncMethod
}
flags := b.uvarint()
keys, err := a.getKeys(&b)
if err != nil {
return err
}
if flags&enc5CheckPresent > 0 {
if err := checkPassword(&b, keys); err != nil {
return err
}
}
a.blo... | go | func (a *archive50) parseEncryptionBlock(b readBuf) error {
if ver := b.uvarint(); ver != 0 {
return errUnknownEncMethod
}
flags := b.uvarint()
keys, err := a.getKeys(&b)
if err != nil {
return err
}
if flags&enc5CheckPresent > 0 {
if err := checkPassword(&b, keys); err != nil {
return err
}
}
a.blo... | [
"func",
"(",
"a",
"*",
"archive50",
")",
"parseEncryptionBlock",
"(",
"b",
"readBuf",
")",
"error",
"{",
"if",
"ver",
":=",
"b",
".",
"uvarint",
"(",
")",
";",
"ver",
"!=",
"0",
"{",
"return",
"errUnknownEncMethod",
"\n",
"}",
"\n",
"flags",
":=",
"b... | // parseEncryptionBlock calculates the key for block encryption. | [
"parseEncryptionBlock",
"calculates",
"the",
"key",
"for",
"block",
"encryption",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/archive50.go#L339-L355 | test |
nwaples/rardecode | archive50.go | newArchive50 | func newArchive50(r *bufio.Reader, password string) fileBlockReader {
a := new(archive50)
a.v = r
a.pass = []byte(password)
a.buf = make([]byte, 100)
return a
} | go | func newArchive50(r *bufio.Reader, password string) fileBlockReader {
a := new(archive50)
a.v = r
a.pass = []byte(password)
a.buf = make([]byte, 100)
return a
} | [
"func",
"newArchive50",
"(",
"r",
"*",
"bufio",
".",
"Reader",
",",
"password",
"string",
")",
"fileBlockReader",
"{",
"a",
":=",
"new",
"(",
"archive50",
")",
"\n",
"a",
".",
"v",
"=",
"r",
"\n",
"a",
".",
"pass",
"=",
"[",
"]",
"byte",
"(",
"pa... | // newArchive50 creates a new fileBlockReader for a Version 5 archive. | [
"newArchive50",
"creates",
"a",
"new",
"fileBlockReader",
"for",
"a",
"Version",
"5",
"archive",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/archive50.go#L469-L475 | test |
nwaples/rardecode | decrypt_reader.go | Read | func (cr *cipherBlockReader) Read(p []byte) (n int, err error) {
for {
if cr.n < len(cr.outbuf) {
// return buffered output
n = copy(p, cr.outbuf[cr.n:])
cr.n += n
return n, nil
}
if cr.err != nil {
err = cr.err
cr.err = nil
return 0, err
}
if len(p) >= cap(cr.outbuf) {
break
}
//... | go | func (cr *cipherBlockReader) Read(p []byte) (n int, err error) {
for {
if cr.n < len(cr.outbuf) {
// return buffered output
n = copy(p, cr.outbuf[cr.n:])
cr.n += n
return n, nil
}
if cr.err != nil {
err = cr.err
cr.err = nil
return 0, err
}
if len(p) >= cap(cr.outbuf) {
break
}
//... | [
"func",
"(",
"cr",
"*",
"cipherBlockReader",
")",
"Read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"for",
"{",
"if",
"cr",
".",
"n",
"<",
"len",
"(",
"cr",
".",
"outbuf",
")",
"{",
"n",
"=",
"copy",
"... | // Read reads and decrypts data into p.
// If the input is not a multiple of the cipher block size,
// the trailing bytes will be ignored. | [
"Read",
"reads",
"and",
"decrypts",
"data",
"into",
"p",
".",
"If",
"the",
"input",
"is",
"not",
"a",
"multiple",
"of",
"the",
"cipher",
"block",
"size",
"the",
"trailing",
"bytes",
"will",
"be",
"ignored",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/decrypt_reader.go#L61-L84 | test |
nwaples/rardecode | decrypt_reader.go | ReadByte | func (cr *cipherBlockReader) ReadByte() (byte, error) {
for {
if cr.n < len(cr.outbuf) {
c := cr.outbuf[cr.n]
cr.n++
return c, nil
}
if cr.err != nil {
err := cr.err
cr.err = nil
return 0, err
}
// refill outbuf
var n int
n, cr.err = cr.read(cr.outbuf[:cap(cr.outbuf)])
cr.outbuf = cr.... | go | func (cr *cipherBlockReader) ReadByte() (byte, error) {
for {
if cr.n < len(cr.outbuf) {
c := cr.outbuf[cr.n]
cr.n++
return c, nil
}
if cr.err != nil {
err := cr.err
cr.err = nil
return 0, err
}
// refill outbuf
var n int
n, cr.err = cr.read(cr.outbuf[:cap(cr.outbuf)])
cr.outbuf = cr.... | [
"func",
"(",
"cr",
"*",
"cipherBlockReader",
")",
"ReadByte",
"(",
")",
"(",
"byte",
",",
"error",
")",
"{",
"for",
"{",
"if",
"cr",
".",
"n",
"<",
"len",
"(",
"cr",
".",
"outbuf",
")",
"{",
"c",
":=",
"cr",
".",
"outbuf",
"[",
"cr",
".",
"n"... | // ReadByte returns the next decrypted byte. | [
"ReadByte",
"returns",
"the",
"next",
"decrypted",
"byte",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/decrypt_reader.go#L87-L105 | test |
nwaples/rardecode | decrypt_reader.go | newCipherBlockReader | func newCipherBlockReader(r io.Reader, mode cipher.BlockMode) *cipherBlockReader {
cr := &cipherBlockReader{r: r, mode: mode}
cr.outbuf = make([]byte, 0, mode.BlockSize())
cr.inbuf = make([]byte, 0, mode.BlockSize())
return cr
} | go | func newCipherBlockReader(r io.Reader, mode cipher.BlockMode) *cipherBlockReader {
cr := &cipherBlockReader{r: r, mode: mode}
cr.outbuf = make([]byte, 0, mode.BlockSize())
cr.inbuf = make([]byte, 0, mode.BlockSize())
return cr
} | [
"func",
"newCipherBlockReader",
"(",
"r",
"io",
".",
"Reader",
",",
"mode",
"cipher",
".",
"BlockMode",
")",
"*",
"cipherBlockReader",
"{",
"cr",
":=",
"&",
"cipherBlockReader",
"{",
"r",
":",
"r",
",",
"mode",
":",
"mode",
"}",
"\n",
"cr",
".",
"outbu... | // newCipherBlockReader returns a cipherBlockReader that decrypts the given io.Reader using
// the provided block mode cipher. | [
"newCipherBlockReader",
"returns",
"a",
"cipherBlockReader",
"that",
"decrypts",
"the",
"given",
"io",
".",
"Reader",
"using",
"the",
"provided",
"block",
"mode",
"cipher",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/decrypt_reader.go#L109-L114 | test |
nwaples/rardecode | decrypt_reader.go | newAesDecryptReader | func newAesDecryptReader(r io.Reader, key, iv []byte) *cipherBlockReader {
block, err := aes.NewCipher(key)
if err != nil {
panic(err)
}
mode := cipher.NewCBCDecrypter(block, iv)
return newCipherBlockReader(r, mode)
} | go | func newAesDecryptReader(r io.Reader, key, iv []byte) *cipherBlockReader {
block, err := aes.NewCipher(key)
if err != nil {
panic(err)
}
mode := cipher.NewCBCDecrypter(block, iv)
return newCipherBlockReader(r, mode)
} | [
"func",
"newAesDecryptReader",
"(",
"r",
"io",
".",
"Reader",
",",
"key",
",",
"iv",
"[",
"]",
"byte",
")",
"*",
"cipherBlockReader",
"{",
"block",
",",
"err",
":=",
"aes",
".",
"NewCipher",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"pa... | // newAesDecryptReader returns a cipherBlockReader that decrypts input from a given io.Reader using AES.
// It will panic if the provided key is invalid. | [
"newAesDecryptReader",
"returns",
"a",
"cipherBlockReader",
"that",
"decrypts",
"input",
"from",
"a",
"given",
"io",
".",
"Reader",
"using",
"AES",
".",
"It",
"will",
"panic",
"if",
"the",
"provided",
"key",
"is",
"invalid",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/decrypt_reader.go#L118-L126 | test |
nwaples/rardecode | reader.go | limitByteReader | func limitByteReader(r byteReader, n int64) *limitedByteReader {
return &limitedByteReader{limitedReader{r, n, io.ErrUnexpectedEOF}, r}
} | go | func limitByteReader(r byteReader, n int64) *limitedByteReader {
return &limitedByteReader{limitedReader{r, n, io.ErrUnexpectedEOF}, r}
} | [
"func",
"limitByteReader",
"(",
"r",
"byteReader",
",",
"n",
"int64",
")",
"*",
"limitedByteReader",
"{",
"return",
"&",
"limitedByteReader",
"{",
"limitedReader",
"{",
"r",
",",
"n",
",",
"io",
".",
"ErrUnexpectedEOF",
"}",
",",
"r",
"}",
"\n",
"}"
] | // limitByteReader returns a limitedByteReader that reads from r and stops with
// io.EOF after n bytes.
// If r returns an io.EOF before reading n bytes, io.ErrUnexpectedEOF is returned. | [
"limitByteReader",
"returns",
"a",
"limitedByteReader",
"that",
"reads",
"from",
"r",
"and",
"stops",
"with",
"io",
".",
"EOF",
"after",
"n",
"bytes",
".",
"If",
"r",
"returns",
"an",
"io",
".",
"EOF",
"before",
"reading",
"n",
"bytes",
"io",
".",
"ErrUn... | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/reader.go#L82-L84 | test |
nwaples/rardecode | reader.go | Mode | func (f *FileHeader) Mode() os.FileMode {
var m os.FileMode
if f.IsDir {
m = os.ModeDir
}
if f.HostOS == HostOSWindows {
if f.IsDir {
m |= 0777
} else if f.Attributes&1 > 0 {
m |= 0444 // readonly
} else {
m |= 0666
}
return m
}
// assume unix perms for all remaining os types
m |= os.FileMo... | go | func (f *FileHeader) Mode() os.FileMode {
var m os.FileMode
if f.IsDir {
m = os.ModeDir
}
if f.HostOS == HostOSWindows {
if f.IsDir {
m |= 0777
} else if f.Attributes&1 > 0 {
m |= 0444 // readonly
} else {
m |= 0666
}
return m
}
// assume unix perms for all remaining os types
m |= os.FileMo... | [
"func",
"(",
"f",
"*",
"FileHeader",
")",
"Mode",
"(",
")",
"os",
".",
"FileMode",
"{",
"var",
"m",
"os",
".",
"FileMode",
"\n",
"if",
"f",
".",
"IsDir",
"{",
"m",
"=",
"os",
".",
"ModeDir",
"\n",
"}",
"\n",
"if",
"f",
".",
"HostOS",
"==",
"H... | // Mode returns an os.FileMode for the file, calculated from the Attributes field. | [
"Mode",
"returns",
"an",
"os",
".",
"FileMode",
"for",
"the",
"file",
"calculated",
"from",
"the",
"Attributes",
"field",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/reader.go#L111-L150 | test |
nwaples/rardecode | reader.go | nextBlockInFile | func (f *packedFileReader) nextBlockInFile() error {
h, err := f.r.next()
if err != nil {
if err == io.EOF {
// archive ended, but file hasn't
return errUnexpectedArcEnd
}
return err
}
if h.first || h.Name != f.h.Name {
return errInvalidFileBlock
}
f.h = h
return nil
} | go | func (f *packedFileReader) nextBlockInFile() error {
h, err := f.r.next()
if err != nil {
if err == io.EOF {
// archive ended, but file hasn't
return errUnexpectedArcEnd
}
return err
}
if h.first || h.Name != f.h.Name {
return errInvalidFileBlock
}
f.h = h
return nil
} | [
"func",
"(",
"f",
"*",
"packedFileReader",
")",
"nextBlockInFile",
"(",
")",
"error",
"{",
"h",
",",
"err",
":=",
"f",
".",
"r",
".",
"next",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"return",
"er... | // nextBlockInFile reads the next file block in the current file at the current
// archive file position, or returns an error if there is a problem.
// It is invalid to call this when already at the last block in the current file. | [
"nextBlockInFile",
"reads",
"the",
"next",
"file",
"block",
"in",
"the",
"current",
"file",
"at",
"the",
"current",
"archive",
"file",
"position",
"or",
"returns",
"an",
"error",
"if",
"there",
"is",
"a",
"problem",
".",
"It",
"is",
"invalid",
"to",
"call"... | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/reader.go#L186-L200 | test |
nwaples/rardecode | reader.go | next | func (f *packedFileReader) next() (*fileBlockHeader, error) {
if f.h != nil {
// skip to last block in current file
for !f.h.last {
// discard remaining block data
if _, err := io.Copy(ioutil.Discard, f.r); err != nil {
return nil, err
}
if err := f.nextBlockInFile(); err != nil {
return nil, e... | go | func (f *packedFileReader) next() (*fileBlockHeader, error) {
if f.h != nil {
// skip to last block in current file
for !f.h.last {
// discard remaining block data
if _, err := io.Copy(ioutil.Discard, f.r); err != nil {
return nil, err
}
if err := f.nextBlockInFile(); err != nil {
return nil, e... | [
"func",
"(",
"f",
"*",
"packedFileReader",
")",
"next",
"(",
")",
"(",
"*",
"fileBlockHeader",
",",
"error",
")",
"{",
"if",
"f",
".",
"h",
"!=",
"nil",
"{",
"for",
"!",
"f",
".",
"h",
".",
"last",
"{",
"if",
"_",
",",
"err",
":=",
"io",
".",... | // next advances to the next packed file in the RAR archive. | [
"next",
"advances",
"to",
"the",
"next",
"packed",
"file",
"in",
"the",
"RAR",
"archive",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/reader.go#L203-L232 | test |
nwaples/rardecode | reader.go | Read | func (f *packedFileReader) Read(p []byte) (int, error) {
n, err := f.r.Read(p) // read current block data
for err == io.EOF { // current block empty
if n > 0 {
return n, nil
}
if f.h == nil || f.h.last {
return 0, io.EOF // last block so end of file
}
if err := f.nextBlockInFile(); err != nil {
r... | go | func (f *packedFileReader) Read(p []byte) (int, error) {
n, err := f.r.Read(p) // read current block data
for err == io.EOF { // current block empty
if n > 0 {
return n, nil
}
if f.h == nil || f.h.last {
return 0, io.EOF // last block so end of file
}
if err := f.nextBlockInFile(); err != nil {
r... | [
"func",
"(",
"f",
"*",
"packedFileReader",
")",
"Read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"n",
",",
"err",
":=",
"f",
".",
"r",
".",
"Read",
"(",
"p",
")",
"\n",
"for",
"err",
"==",
"io",
".",
"EOF",
"{",
... | // Read reads the packed data for the current file into p. | [
"Read",
"reads",
"the",
"packed",
"data",
"for",
"the",
"current",
"file",
"into",
"p",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/reader.go#L235-L250 | test |
nwaples/rardecode | reader.go | Read | func (r *Reader) Read(p []byte) (int, error) {
n, err := r.r.Read(p)
if err == io.EOF && r.cksum != nil && !r.cksum.valid() {
return n, errBadFileChecksum
}
return n, err
} | go | func (r *Reader) Read(p []byte) (int, error) {
n, err := r.r.Read(p)
if err == io.EOF && r.cksum != nil && !r.cksum.valid() {
return n, errBadFileChecksum
}
return n, err
} | [
"func",
"(",
"r",
"*",
"Reader",
")",
"Read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"n",
",",
"err",
":=",
"r",
".",
"r",
".",
"Read",
"(",
"p",
")",
"\n",
"if",
"err",
"==",
"io",
".",
"EOF",
"&&",
"r",
"... | // Read reads from the current file in the RAR archive. | [
"Read",
"reads",
"from",
"the",
"current",
"file",
"in",
"the",
"RAR",
"archive",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/reader.go#L273-L279 | test |
nwaples/rardecode | reader.go | Next | func (r *Reader) Next() (*FileHeader, error) {
if r.solidr != nil {
// solid files must be read fully to update decoder information
if _, err := io.Copy(ioutil.Discard, r.solidr); err != nil {
return nil, err
}
}
h, err := r.pr.next() // skip to next file
if err != nil {
return nil, err
}
r.solidr = n... | go | func (r *Reader) Next() (*FileHeader, error) {
if r.solidr != nil {
// solid files must be read fully to update decoder information
if _, err := io.Copy(ioutil.Discard, r.solidr); err != nil {
return nil, err
}
}
h, err := r.pr.next() // skip to next file
if err != nil {
return nil, err
}
r.solidr = n... | [
"func",
"(",
"r",
"*",
"Reader",
")",
"Next",
"(",
")",
"(",
"*",
"FileHeader",
",",
"error",
")",
"{",
"if",
"r",
".",
"solidr",
"!=",
"nil",
"{",
"if",
"_",
",",
"err",
":=",
"io",
".",
"Copy",
"(",
"ioutil",
".",
"Discard",
",",
"r",
".",
... | // Next advances to the next file in the archive. | [
"Next",
"advances",
"to",
"the",
"next",
"file",
"in",
"the",
"archive",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/reader.go#L282-L325 | test |
nwaples/rardecode | reader.go | NewReader | func NewReader(r io.Reader, password string) (*Reader, error) {
br, ok := r.(*bufio.Reader)
if !ok {
br = bufio.NewReader(r)
}
fbr, err := newFileBlockReader(br, password)
if err != nil {
return nil, err
}
rr := new(Reader)
rr.init(fbr)
return rr, nil
} | go | func NewReader(r io.Reader, password string) (*Reader, error) {
br, ok := r.(*bufio.Reader)
if !ok {
br = bufio.NewReader(r)
}
fbr, err := newFileBlockReader(br, password)
if err != nil {
return nil, err
}
rr := new(Reader)
rr.init(fbr)
return rr, nil
} | [
"func",
"NewReader",
"(",
"r",
"io",
".",
"Reader",
",",
"password",
"string",
")",
"(",
"*",
"Reader",
",",
"error",
")",
"{",
"br",
",",
"ok",
":=",
"r",
".",
"(",
"*",
"bufio",
".",
"Reader",
")",
"\n",
"if",
"!",
"ok",
"{",
"br",
"=",
"bu... | // NewReader creates a Reader reading from r.
// NewReader only supports single volume archives.
// Multi-volume archives must use OpenReader. | [
"NewReader",
"creates",
"a",
"Reader",
"reading",
"from",
"r",
".",
"NewReader",
"only",
"supports",
"single",
"volume",
"archives",
".",
"Multi",
"-",
"volume",
"archives",
"must",
"use",
"OpenReader",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/reader.go#L335-L347 | test |
nwaples/rardecode | reader.go | OpenReader | func OpenReader(name, password string) (*ReadCloser, error) {
v, err := openVolume(name, password)
if err != nil {
return nil, err
}
rc := new(ReadCloser)
rc.v = v
rc.Reader.init(v)
return rc, nil
} | go | func OpenReader(name, password string) (*ReadCloser, error) {
v, err := openVolume(name, password)
if err != nil {
return nil, err
}
rc := new(ReadCloser)
rc.v = v
rc.Reader.init(v)
return rc, nil
} | [
"func",
"OpenReader",
"(",
"name",
",",
"password",
"string",
")",
"(",
"*",
"ReadCloser",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"openVolume",
"(",
"name",
",",
"password",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"e... | // OpenReader opens a RAR archive specified by the name and returns a ReadCloser. | [
"OpenReader",
"opens",
"a",
"RAR",
"archive",
"specified",
"by",
"the",
"name",
"and",
"returns",
"a",
"ReadCloser",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/reader.go#L367-L376 | test |
nwaples/rardecode | filters.go | getV3Filter | func getV3Filter(code []byte) (v3Filter, error) {
// check if filter is a known standard filter
c := crc32.ChecksumIEEE(code)
for _, f := range standardV3Filters {
if f.crc == c && f.len == len(code) {
return f.f, nil
}
}
// create new vm filter
f := new(vmFilter)
r := newRarBitReader(bytes.NewReader(cod... | go | func getV3Filter(code []byte) (v3Filter, error) {
// check if filter is a known standard filter
c := crc32.ChecksumIEEE(code)
for _, f := range standardV3Filters {
if f.crc == c && f.len == len(code) {
return f.f, nil
}
}
// create new vm filter
f := new(vmFilter)
r := newRarBitReader(bytes.NewReader(cod... | [
"func",
"getV3Filter",
"(",
"code",
"[",
"]",
"byte",
")",
"(",
"v3Filter",
",",
"error",
")",
"{",
"c",
":=",
"crc32",
".",
"ChecksumIEEE",
"(",
"code",
")",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"standardV3Filters",
"{",
"if",
"f",
".",
"crc... | // getV3Filter returns a V3 filter function from a code byte slice. | [
"getV3Filter",
"returns",
"a",
"V3",
"filter",
"function",
"from",
"a",
"code",
"byte",
"slice",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/filters.go#L380-L416 | test |
nwaples/rardecode | decode29.go | init | func (d *decoder29) init(r io.ByteReader, reset bool) error {
if d.br == nil {
d.br = newRarBitReader(r)
} else {
d.br.reset(r)
}
d.eof = false
if reset {
d.initFilters()
d.lz.reset()
d.ppm.reset()
d.decode = nil
}
if d.decode == nil {
return d.readBlockHeader()
}
return nil
} | go | func (d *decoder29) init(r io.ByteReader, reset bool) error {
if d.br == nil {
d.br = newRarBitReader(r)
} else {
d.br.reset(r)
}
d.eof = false
if reset {
d.initFilters()
d.lz.reset()
d.ppm.reset()
d.decode = nil
}
if d.decode == nil {
return d.readBlockHeader()
}
return nil
} | [
"func",
"(",
"d",
"*",
"decoder29",
")",
"init",
"(",
"r",
"io",
".",
"ByteReader",
",",
"reset",
"bool",
")",
"error",
"{",
"if",
"d",
".",
"br",
"==",
"nil",
"{",
"d",
".",
"br",
"=",
"newRarBitReader",
"(",
"r",
")",
"\n",
"}",
"else",
"{",
... | // init intializes the decoder for decoding a new file. | [
"init",
"intializes",
"the",
"decoder",
"for",
"decoding",
"a",
"new",
"file",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/decode29.go#L43-L60 | test |
nwaples/rardecode | decode29.go | readBlockHeader | func (d *decoder29) readBlockHeader() error {
d.br.alignByte()
n, err := d.br.readBits(1)
if err == nil {
if n > 0 {
d.decode = d.ppm.decode
err = d.ppm.init(d.br)
} else {
d.decode = d.lz.decode
err = d.lz.init(d.br)
}
}
if err == io.EOF {
err = errDecoderOutOfData
}
return err
} | go | func (d *decoder29) readBlockHeader() error {
d.br.alignByte()
n, err := d.br.readBits(1)
if err == nil {
if n > 0 {
d.decode = d.ppm.decode
err = d.ppm.init(d.br)
} else {
d.decode = d.lz.decode
err = d.lz.init(d.br)
}
}
if err == io.EOF {
err = errDecoderOutOfData
}
return err
} | [
"func",
"(",
"d",
"*",
"decoder29",
")",
"readBlockHeader",
"(",
")",
"error",
"{",
"d",
".",
"br",
".",
"alignByte",
"(",
")",
"\n",
"n",
",",
"err",
":=",
"d",
".",
"br",
".",
"readBits",
"(",
"1",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
... | // readBlockHeader determines and initializes the current decoder for a new decode block. | [
"readBlockHeader",
"determines",
"and",
"initializes",
"the",
"current",
"decoder",
"for",
"a",
"new",
"decode",
"block",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/decode29.go#L203-L220 | test |
nwaples/rardecode | huffman.go | readCodeLengthTable | func readCodeLengthTable(br bitReader, codeLength []byte, addOld bool) error {
var bitlength [20]byte
for i := 0; i < len(bitlength); i++ {
n, err := br.readBits(4)
if err != nil {
return err
}
if n == 0xf {
cnt, err := br.readBits(4)
if err != nil {
return err
}
if cnt > 0 {
// array a... | go | func readCodeLengthTable(br bitReader, codeLength []byte, addOld bool) error {
var bitlength [20]byte
for i := 0; i < len(bitlength); i++ {
n, err := br.readBits(4)
if err != nil {
return err
}
if n == 0xf {
cnt, err := br.readBits(4)
if err != nil {
return err
}
if cnt > 0 {
// array a... | [
"func",
"readCodeLengthTable",
"(",
"br",
"bitReader",
",",
"codeLength",
"[",
"]",
"byte",
",",
"addOld",
"bool",
")",
"error",
"{",
"var",
"bitlength",
"[",
"20",
"]",
"byte",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"bitlength",
")"... | // readCodeLengthTable reads a new code length table into codeLength from br.
// If addOld is set the old table is added to the new one. | [
"readCodeLengthTable",
"reads",
"a",
"new",
"code",
"length",
"table",
"into",
"codeLength",
"from",
"br",
".",
"If",
"addOld",
"is",
"set",
"the",
"old",
"table",
"is",
"added",
"to",
"the",
"new",
"one",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/huffman.go#L142-L208 | test |
nwaples/rardecode | ppm_model.go | shrinkStates | func (c *context) shrinkStates(states []state, size int) []state {
i1 := units2Index[(len(states)+1)>>1]
i2 := units2Index[(size+1)>>1]
if size == 1 {
// store state in context, and free states block
n := c.statesIndex()
c.s[1] = states[0]
states = c.s[1:]
c.a.addFreeBlock(n, i1)
} else if i1 != i2 {
i... | go | func (c *context) shrinkStates(states []state, size int) []state {
i1 := units2Index[(len(states)+1)>>1]
i2 := units2Index[(size+1)>>1]
if size == 1 {
// store state in context, and free states block
n := c.statesIndex()
c.s[1] = states[0]
states = c.s[1:]
c.a.addFreeBlock(n, i1)
} else if i1 != i2 {
i... | [
"func",
"(",
"c",
"*",
"context",
")",
"shrinkStates",
"(",
"states",
"[",
"]",
"state",
",",
"size",
"int",
")",
"[",
"]",
"state",
"{",
"i1",
":=",
"units2Index",
"[",
"(",
"len",
"(",
"states",
")",
"+",
"1",
")",
">>",
"1",
"]",
"\n",
"i2",... | // shrinkStates shrinks the state list down to size states | [
"shrinkStates",
"shrinks",
"the",
"state",
"list",
"down",
"to",
"size",
"states"
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/ppm_model.go#L232-L259 | test |
nwaples/rardecode | ppm_model.go | expandStates | func (c *context) expandStates() []state {
states := c.states()
ns := len(states)
if ns == 1 {
s := states[0]
n := c.a.allocUnits(1)
if n == 0 {
return nil
}
c.setStatesIndex(n)
states = c.a.states[n:]
states[0] = s
} else if ns&0x1 == 0 {
u := ns >> 1
i1 := units2Index[u]
i2 := units2Index[u... | go | func (c *context) expandStates() []state {
states := c.states()
ns := len(states)
if ns == 1 {
s := states[0]
n := c.a.allocUnits(1)
if n == 0 {
return nil
}
c.setStatesIndex(n)
states = c.a.states[n:]
states[0] = s
} else if ns&0x1 == 0 {
u := ns >> 1
i1 := units2Index[u]
i2 := units2Index[u... | [
"func",
"(",
"c",
"*",
"context",
")",
"expandStates",
"(",
")",
"[",
"]",
"state",
"{",
"states",
":=",
"c",
".",
"states",
"(",
")",
"\n",
"ns",
":=",
"len",
"(",
"states",
")",
"\n",
"if",
"ns",
"==",
"1",
"{",
"s",
":=",
"states",
"[",
"0... | // expandStates expands the states list by one | [
"expandStates",
"expands",
"the",
"states",
"list",
"by",
"one"
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/ppm_model.go#L262-L291 | test |
nwaples/rardecode | ppm_model.go | pushByte | func (a *subAllocator) pushByte(c byte) int32 {
si := a.heap1Lo / 6 // state index
oi := a.heap1Lo % 6 // byte position in state
switch oi {
case 0:
a.states[si].sym = c
case 1:
a.states[si].freq = c
default:
n := (uint(oi) - 2) * 8
mask := ^(uint32(0xFF) << n)
succ := uint32(a.states[si].succ) & mask
... | go | func (a *subAllocator) pushByte(c byte) int32 {
si := a.heap1Lo / 6 // state index
oi := a.heap1Lo % 6 // byte position in state
switch oi {
case 0:
a.states[si].sym = c
case 1:
a.states[si].freq = c
default:
n := (uint(oi) - 2) * 8
mask := ^(uint32(0xFF) << n)
succ := uint32(a.states[si].succ) & mask
... | [
"func",
"(",
"a",
"*",
"subAllocator",
")",
"pushByte",
"(",
"c",
"byte",
")",
"int32",
"{",
"si",
":=",
"a",
".",
"heap1Lo",
"/",
"6",
"\n",
"oi",
":=",
"a",
".",
"heap1Lo",
"%",
"6",
"\n",
"switch",
"oi",
"{",
"case",
"0",
":",
"a",
".",
"s... | // pushByte puts a byte on the heap and returns a state.succ index that
// can be used to retrieve it. | [
"pushByte",
"puts",
"a",
"byte",
"on",
"the",
"heap",
"and",
"returns",
"a",
"state",
".",
"succ",
"index",
"that",
"can",
"be",
"used",
"to",
"retrieve",
"it",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/ppm_model.go#L350-L370 | test |
nwaples/rardecode | ppm_model.go | succByte | func (a *subAllocator) succByte(i int32) byte {
i = -i
si := i / 6
oi := i % 6
switch oi {
case 0:
return a.states[si].sym
case 1:
return a.states[si].freq
default:
n := (uint(oi) - 2) * 8
succ := uint32(a.states[si].succ) >> n
return byte(succ & 0xff)
}
} | go | func (a *subAllocator) succByte(i int32) byte {
i = -i
si := i / 6
oi := i % 6
switch oi {
case 0:
return a.states[si].sym
case 1:
return a.states[si].freq
default:
n := (uint(oi) - 2) * 8
succ := uint32(a.states[si].succ) >> n
return byte(succ & 0xff)
}
} | [
"func",
"(",
"a",
"*",
"subAllocator",
")",
"succByte",
"(",
"i",
"int32",
")",
"byte",
"{",
"i",
"=",
"-",
"i",
"\n",
"si",
":=",
"i",
"/",
"6",
"\n",
"oi",
":=",
"i",
"%",
"6",
"\n",
"switch",
"oi",
"{",
"case",
"0",
":",
"return",
"a",
"... | // succByte returns a byte from the heap given a state.succ index | [
"succByte",
"returns",
"a",
"byte",
"from",
"the",
"heap",
"given",
"a",
"state",
".",
"succ",
"index"
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/ppm_model.go#L376-L390 | test |
nwaples/rardecode | ppm_model.go | succContext | func (a *subAllocator) succContext(i int32) *context {
if i <= 0 {
return nil
}
return &context{i: i, s: a.states[i : i+2 : i+2], a: a}
} | go | func (a *subAllocator) succContext(i int32) *context {
if i <= 0 {
return nil
}
return &context{i: i, s: a.states[i : i+2 : i+2], a: a}
} | [
"func",
"(",
"a",
"*",
"subAllocator",
")",
"succContext",
"(",
"i",
"int32",
")",
"*",
"context",
"{",
"if",
"i",
"<=",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"&",
"context",
"{",
"i",
":",
"i",
",",
"s",
":",
"a",
".",
"states"... | // succContext returns a context given a state.succ index | [
"succContext",
"returns",
"a",
"context",
"given",
"a",
"state",
".",
"succ",
"index"
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/ppm_model.go#L393-L398 | test |
nwaples/rardecode | archive15.go | calcAes30Params | func calcAes30Params(pass []uint16, salt []byte) (key, iv []byte) {
p := make([]byte, 0, len(pass)*2+len(salt))
for _, v := range pass {
p = append(p, byte(v), byte(v>>8))
}
p = append(p, salt...)
hash := sha1.New()
iv = make([]byte, 16)
s := make([]byte, 0, hash.Size())
for i := 0; i < hashRounds; i++ {
h... | go | func calcAes30Params(pass []uint16, salt []byte) (key, iv []byte) {
p := make([]byte, 0, len(pass)*2+len(salt))
for _, v := range pass {
p = append(p, byte(v), byte(v>>8))
}
p = append(p, salt...)
hash := sha1.New()
iv = make([]byte, 16)
s := make([]byte, 0, hash.Size())
for i := 0; i < hashRounds; i++ {
h... | [
"func",
"calcAes30Params",
"(",
"pass",
"[",
"]",
"uint16",
",",
"salt",
"[",
"]",
"byte",
")",
"(",
"key",
",",
"iv",
"[",
"]",
"byte",
")",
"{",
"p",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"len",
"(",
"pass",
")",
"*",
"2",
"... | // Calculates the key and iv for AES decryption given a password and salt. | [
"Calculates",
"the",
"key",
"and",
"iv",
"for",
"AES",
"decryption",
"given",
"a",
"password",
"and",
"salt",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/archive15.go#L96-L121 | test |
nwaples/rardecode | archive15.go | parseDosTime | func parseDosTime(t uint32) time.Time {
n := int(t)
sec := n & 0x1f << 1
min := n >> 5 & 0x3f
hr := n >> 11 & 0x1f
day := n >> 16 & 0x1f
mon := time.Month(n >> 21 & 0x0f)
yr := n>>25&0x7f + 1980
return time.Date(yr, mon, day, hr, min, sec, 0, time.Local)
} | go | func parseDosTime(t uint32) time.Time {
n := int(t)
sec := n & 0x1f << 1
min := n >> 5 & 0x3f
hr := n >> 11 & 0x1f
day := n >> 16 & 0x1f
mon := time.Month(n >> 21 & 0x0f)
yr := n>>25&0x7f + 1980
return time.Date(yr, mon, day, hr, min, sec, 0, time.Local)
} | [
"func",
"parseDosTime",
"(",
"t",
"uint32",
")",
"time",
".",
"Time",
"{",
"n",
":=",
"int",
"(",
"t",
")",
"\n",
"sec",
":=",
"n",
"&",
"0x1f",
"<<",
"1",
"\n",
"min",
":=",
"n",
">>",
"5",
"&",
"0x3f",
"\n",
"hr",
":=",
"n",
">>",
"11",
"... | // parseDosTime converts a 32bit DOS time value to time.Time | [
"parseDosTime",
"converts",
"a",
"32bit",
"DOS",
"time",
"value",
"to",
"time",
".",
"Time"
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/archive15.go#L124-L133 | test |
nwaples/rardecode | archive15.go | decodeName | func decodeName(buf []byte) string {
i := bytes.IndexByte(buf, 0)
if i < 0 {
return string(buf) // filename is UTF-8
}
name := buf[:i]
encName := readBuf(buf[i+1:])
if len(encName) < 2 {
return "" // invalid encoding
}
highByte := uint16(encName.byte()) << 8
flags := encName.byte()
flagBits := 8
var wch... | go | func decodeName(buf []byte) string {
i := bytes.IndexByte(buf, 0)
if i < 0 {
return string(buf) // filename is UTF-8
}
name := buf[:i]
encName := readBuf(buf[i+1:])
if len(encName) < 2 {
return "" // invalid encoding
}
highByte := uint16(encName.byte()) << 8
flags := encName.byte()
flagBits := 8
var wch... | [
"func",
"decodeName",
"(",
"buf",
"[",
"]",
"byte",
")",
"string",
"{",
"i",
":=",
"bytes",
".",
"IndexByte",
"(",
"buf",
",",
"0",
")",
"\n",
"if",
"i",
"<",
"0",
"{",
"return",
"string",
"(",
"buf",
")",
"\n",
"}",
"\n",
"name",
":=",
"buf",
... | // decodeName decodes a non-unicode filename from a file header. | [
"decodeName",
"decodes",
"a",
"non",
"-",
"unicode",
"filename",
"from",
"a",
"file",
"header",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/archive15.go#L136-L193 | test |
nwaples/rardecode | archive15.go | readExtTimes | func readExtTimes(f *fileBlockHeader, b *readBuf) {
if len(*b) < 2 {
return // invalid, not enough data
}
flags := b.uint16()
ts := []*time.Time{&f.ModificationTime, &f.CreationTime, &f.AccessTime}
for i, t := range ts {
n := flags >> uint((3-i)*4)
if n&0x8 == 0 {
continue
}
if i != 0 { // Modificat... | go | func readExtTimes(f *fileBlockHeader, b *readBuf) {
if len(*b) < 2 {
return // invalid, not enough data
}
flags := b.uint16()
ts := []*time.Time{&f.ModificationTime, &f.CreationTime, &f.AccessTime}
for i, t := range ts {
n := flags >> uint((3-i)*4)
if n&0x8 == 0 {
continue
}
if i != 0 { // Modificat... | [
"func",
"readExtTimes",
"(",
"f",
"*",
"fileBlockHeader",
",",
"b",
"*",
"readBuf",
")",
"{",
"if",
"len",
"(",
"*",
"b",
")",
"<",
"2",
"{",
"return",
"\n",
"}",
"\n",
"flags",
":=",
"b",
".",
"uint16",
"(",
")",
"\n",
"ts",
":=",
"[",
"]",
... | // readExtTimes reads and parses the optional extra time field from the file header. | [
"readExtTimes",
"reads",
"and",
"parses",
"the",
"optional",
"extra",
"time",
"field",
"from",
"the",
"file",
"header",
"."
] | 197ef08ef68c4454ae5970a9c2692d6056ceb8d7 | https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/archive15.go#L196-L233 | test |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.