Transformation<Uint8Array<ArrayBufferLike>, string, never, never>Decodes a Base64-encoded string into a Uint8Array and encodes a
Uint8Array back to a Base64 string.
When to use
Use when you need a schema transformation for binary data transmitted as Base64 strings (e.g. file uploads, API payloads).
Details
Decoding parses the Base64 string into bytes. Encoding writes the byte array as a Base64 string.
Example (Converting Base64 to a Uint8Array)
import { Schema, SchemaTransformation } from "effect"
const schema = Schema.String.pipe(
Schema.decodeTo(Schema.Uint8Array, SchemaTransformation.uint8ArrayFromBase64String)
)export const const uint8ArrayFromBase64String: Transformation<
Uint8Array<ArrayBufferLike>,
string
>
const uint8ArrayFromBase64String: {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => Transformation<string, Uint8Array<ArrayBufferLike>, never, never>;
compose: (other: Transformation<T2, Uint8Array<ArrayBufferLike>, RD2, RE2>) => Transformation<T2, string, RD2, RE2>;
}
Decodes a Base64-encoded string into a Uint8Array and encodes a
Uint8Array back to a Base64 string.
When to use
Use when you need a schema transformation for binary data transmitted as
Base64 strings (e.g. file uploads, API payloads).
Details
Decoding parses the Base64 string into bytes. Encoding writes the byte array
as a Base64 string.
Example (Converting Base64 to a Uint8Array)
import { Schema, SchemaTransformation } from "effect"
const schema = Schema.String.pipe(
Schema.decodeTo(Schema.Uint8Array, SchemaTransformation.uint8ArrayFromBase64String)
)
uint8ArrayFromBase64String: class Transformation<in out T, in out E, RD = never, RE = never>class Transformation {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => Transformation<E, T, RE, RD>;
compose: <T2, RD2, RE2>(other: Transformation<T2, T, RD2, RE2>) => Transformation<T2, E, RD | RD2, RE | RE2>;
}
Represents a bidirectional transformation between a decoded type T and an encoded
type E, built from a pair of Getters.
When to use
Use when you need a schema transformation that defines how a schema converts
between two representations.
- You want to compose multiple transformations into a pipeline.
- You want to flip a transformation to swap decode/encode.
Details
This is the primary building block for Schema.decodeTo, Schema.encodeTo,
Schema.decode, Schema.encode, and Schema.link. Each direction is a
SchemaGetter.Getter that handles optionality, failure, and Effect services.
- Immutable —
flip() and compose() return new instances.
flip() swaps the decode and encode getters.
compose(other) chains: this.decode then other.decode for decoding,
other.encode then this.encode for encoding.
Example (Composing two transformations)
import { SchemaTransformation } from "effect"
const trimAndLower = SchemaTransformation.trim().compose(
SchemaTransformation.toLowerCase()
)
// decode: trim then lowercase
// encode: passthrough (both directions)
Transformation<interface Uint8Array<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the
requested number of bytes could not be allocated an exception is raised.
Uint8Array<type ArrayBufferLike =
| ArrayBuffer
| SharedArrayBuffer
ArrayBufferLike>, string> = new constructor Transformation<Uint8Array<ArrayBufferLike>, string, never, never>(decode: SchemaGetter.Getter<Uint8Array<ArrayBufferLike>, string, never>, encode: SchemaGetter.Getter<string, Uint8Array<ArrayBufferLike>, never>): Transformation<Uint8Array<ArrayBufferLike>, string, never, never>Represents a bidirectional transformation between a decoded type T and an encoded
type E, built from a pair of Getters.
When to use
Use when you need a schema transformation that defines how a schema converts
between two representations.
- You want to compose multiple transformations into a pipeline.
- You want to flip a transformation to swap decode/encode.
Details
This is the primary building block for Schema.decodeTo, Schema.encodeTo,
Schema.decode, Schema.encode, and Schema.link. Each direction is a
SchemaGetter.Getter that handles optionality, failure, and Effect services.
- Immutable —
flip() and compose() return new instances.
flip() swaps the decode and encode getters.
compose(other) chains: this.decode then other.decode for decoding,
other.encode then this.encode for encoding.
Example (Composing two transformations)
import { SchemaTransformation } from "effect"
const trimAndLower = SchemaTransformation.trim().compose(
SchemaTransformation.toLowerCase()
)
// decode: trim then lowercase
// encode: passthrough (both directions)
Transformation(
import SchemaGetterSchemaGetter.decodeBase64(),
import SchemaGetterSchemaGetter.encodeBase64()
)