Documentation
¶
Index ¶
- Variables
- func BuildBytesObject(data []byte, contentType string) cty.Value
- func GetBytesFunctions() map[string]function.Function
- func MakeBase64DecodeFunc() function.Function
- func MakeBase64EncodeFunc() function.Function
- func MakeBytesFunc() function.Function
- func NewBytesCapsule(data []byte, contentType string) cty.Value
- type Bytes
Constants ¶
This section is empty.
Variables ¶
var BytesCapsuleType = cty.CapsuleWithOps("bytes", reflect.TypeOf(Bytes{}), &cty.CapsuleOps{ GoString: func(val interface{}) string { b := val.(*Bytes) return fmt.Sprintf("bytes(%d bytes)", len(b.Data)) }, TypeGoString: func(_ reflect.Type) string { return "Bytes" }, })
BytesCapsuleType is the cty capsule type for Bytes values.
var BytesObjectType = cty.Object(map[string]cty.Type{ "content_type": cty.String, "_capsule": BytesCapsuleType, })
BytesObjectType is the cty object type returned by bytes-producing functions. It exposes content_type as a direct attribute and carries the underlying capsule in the _capsule attribute for interface dispatch (richcty.Stringable, richcty.Lengthable, etc.).
Functions ¶
func BuildBytesObject ¶
BuildBytesObject returns a cty object with content_type and _capsule attributes.
func GetBytesFunctions ¶
GetBytesFunctions returns bytes-related cty functions for registration in an eval context.
func MakeBase64DecodeFunc ¶
MakeBase64DecodeFunc returns a base64decode function.
When called with one argument it returns a string, preserving backward compatibility with the stdlib version. When a second (content_type) argument is present — even if it is the empty string — it returns a bytes object.
base64decode(str) - returns string (backward compatible) base64decode(str, "") - returns bytes object, no content type base64decode(str, "image/png") - returns bytes object with content type
func MakeBase64EncodeFunc ¶
MakeBase64EncodeFunc returns a base64encode function that accepts either a string or bytes value.
func MakeBytesFunc ¶
MakeBytesFunc returns a function that creates a bytes object from a UTF-8 string or re-wraps an existing bytes value with a different content type.
bytes(str) - bytes from UTF-8 string, no content type bytes(str, content_type) - bytes from UTF-8 string with content type bytes(b) - copy of bytes value (preserves content type) bytes(b, content_type) - copy of bytes value with overridden content type
Types ¶
type Bytes ¶
Bytes is an immutable byte slice with an optional content/MIME type.
func GetBytesFromCapsule ¶
GetBytesFromCapsule extracts a *Bytes from a cty capsule value.
func GetBytesFromValue ¶
GetBytesFromValue extracts a *Bytes from a bytes object, capsule, or anything accepted by GetCapsuleFromValue.