Available
amalgame-encoding
Base64, Hex, percent-encoding.
Overview
Three static classes: Base64 (RFC 4648), Hex and Url (percent-encoding, RFC 3986). Bytes are a List<int>, one value from 0 to 255 per item.
Features
- ✓
Base64.Encode/Decode, and the URL-safeEncodeUrl/DecodeUrl: encoding adds=padding, decoding works with or without it - ✓
Hex.Encode(lowercase),Hex.EncodeUpper,Hex.Decode(either case) - ✓
Url.EncodeComponentfor one part of a URL,Url.Encodewhich keeps the separators (/ ? # & =…),Url.Decode - ✓
Base64.IsValidandHex.IsValidto check input - ✓Pure Amalgame, no C dependency
Limits
- –
Base64andHextake bytes, not a string. - –
Url.Decodedoes not turn+into a space: it is not an HTML form decoder.
Example
After amc package add encoding, put this code in main.am and run amc run main.am.
import Amalgame.Collections
import Amalgame.Encoding
public class Program {
public static void Main() {
let bytes: List<int> = Hex.Decode("deadbeef") // 4 bytes
Console.WriteLine(Base64.Encode(bytes)) // 3q2+7w==
Console.WriteLine(Base64.EncodeUrl(bytes)) // 3q2-7w==
Console.WriteLine(Hex.EncodeUpper(bytes)) // DEADBEEF
let back: List<int> = Base64.Decode("3q2+7w") // no padding: accepted
Console.WriteLine(Hex.Encode(back)) // deadbeef
Console.WriteLine(Url.EncodeComponent("a b&c")) // a%20b%26c
Console.WriteLine(Url.Decode("a%20b%26c")) // a b&c
}
}
At a glance
- License: Apache-2.0
- Install:
amc package add encoding - Source: amalgame-lang/amalgame-encoding
- Official index: amalgame-lang/packages-index