MoonBit base64: provide simple base64 operations.
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.$ moon version --all
moon 0.1.20260330 (c527f57 2026-03-30) ~/.moon/bin/moon
moonc v0.8.4+4d98d95d4 (2026-03-30) ~/.moon/bin/moonc
moonrun 0.1.20260330 (c527f57 2026-03-30) ~/.moon/bin/moonrun
moon-pilot 0.0.1-df92511 (2026-03-30) ~/.moon/bin/moon-pilotlet arr = b"+/ Hello, 世界! 🌍".to_array()
inspect(array2str(arr[:]), content="+/ Hello, 世界! 🌍")fn bytes2str(b : Bytes) -> Stringinspect(bytes2str("+/ Hello, 世界! 🌍"), content="+/ Hello, 世界! 🌍")let b = "+/ Hello, 世界! 🌍"
inspect(std_decode2bytes("Ky8gSGVsbG8sIOS4lueVjCEg8J+MjQ==") |> bytes2str(), content=b)
inspect(std_decode2bytes("Ky8gSGVsbG8sIOS4lueVjCEg8J+MjQ", no_padding=true) |> bytes2str(), content=b)let b = "+/ Hello, 世界! 🌍"
inspect(std_decode2str("Ky8gSGVsbG8sIOS4lueVjCEg8J+MjQ=="), content=b)
inspect(std_decode2str("Ky8gSGVsbG8sIOS4lueVjCEg8J+MjQ", no_padding=true), content=b)fn std_encode2bytes(src : FixedArray[Byte], no_padding? : Bool) -> Byteslet b : Bytes = "+/ Hello, 世界! 🌍"
inspect(std_encode2bytes(b.to_fixedarray()) |> bytes2str(), content="Ky8gSGVsbG8sIOS4lueVjCEg8J+MjQ==")
inspect(std_encode2bytes(b.to_fixedarray(), no_padding=true) |> bytes2str(), content="Ky8gSGVsbG8sIOS4lueVjCEg8J+MjQ")fn std_encode2str(src : FixedArray[Byte], no_padding? : Bool) -> Stringlet b : Bytes = "+/ Hello, 世界! 🌍"
inspect(std_encode2str(b.to_fixedarray()), content="Ky8gSGVsbG8sIOS4lueVjCEg8J+MjQ==")
inspect(std_encode2str(b.to_fixedarray(), no_padding=true), content="Ky8gSGVsbG8sIOS4lueVjCEg8J+MjQ")inspect(str2array("🌍"), content="[b'\\xF0', b'\\x9F', b'\\x8C', b'\\x8D']")fn str2bytes(s : String) -> Bytesinspect(str2bytes("+/ Hello, 世界! 🌍"), content=(
#|b"+/ Hello, \xe4\xb8\x96\xe7\x95\x8c! \xf0\x9f\x8c\x8d"
))let b = "+/ Hello, 世界! 🌍"
inspect(url_decode2bytes("Ky8gSGVsbG8sIOS4lueVjCEg8J-MjQ==") |> bytes2str(), content=b)
inspect(url_decode2bytes("Ky8gSGVsbG8sIOS4lueVjCEg8J-MjQ", no_padding=true) |> bytes2str(), content=b)let b = "+/ Hello, 世界! 🌍"
inspect(url_decode2str("Ky8gSGVsbG8sIOS4lueVjCEg8J-MjQ=="), content=b)
inspect(url_decode2str("Ky8gSGVsbG8sIOS4lueVjCEg8J-MjQ", no_padding=true), content=b)fn url_encode2bytes(src : FixedArray[Byte], no_padding? : Bool) -> Byteslet b : Bytes = "+/ Hello, 世界! 🌍"
inspect(url_encode2bytes(b.to_fixedarray()) |> bytes2str(), content="Ky8gSGVsbG8sIOS4lueVjCEg8J-MjQ==")
inspect(url_encode2bytes(b.to_fixedarray(), no_padding=true) |> bytes2str(), content="Ky8gSGVsbG8sIOS4lueVjCEg8J-MjQ")fn url_encode2str(src : FixedArray[Byte], no_padding? : Bool) -> Stringlet b : Bytes = "+/ Hello, 世界! 🌍"
inspect(url_encode2str(b.to_fixedarray()), content="Ky8gSGVsbG8sIOS4lueVjCEg8J-MjQ==")
inspect(url_encode2str(b.to_fixedarray(), no_padding=true), content="Ky8gSGVsbG8sIOS4lueVjCEg8J-MjQ")MoonBit base64: provide simple base64 operations.