cupertino-packages/swift-extras/swift-extras-base64
Mihaela Mihaljevic 717311488d data(packages): initial import, 2026-05-27
Per-owner per-repo Swift package source trees, extracted from
codeload.github.com tarballs by `cupertino fetch --source
packages --skip-metadata`. 12 owners covering 137 seed packages
plus transitive dependencies discovered via Package.swift walks
at raw.githubusercontent.com.

Lifted from cupertino-docs/packages/ subtree
(cupertino-docs@26fc51c92). The subtree is being removed from
cupertino-docs in a follow-up commit so per-source-corpus repos
stay separable.

326 MB total, 1 fetch error (logged at fetch time, not blocking
indexer).
2026-05-27 11:35:02 +02:00
..
scripts data(packages): initial import, 2026-05-27 2026-05-27 11:35:02 +02:00
Sources/ExtrasBase64 data(packages): initial import, 2026-05-27 2026-05-27 11:35:02 +02:00
Tests/ExtrasBase64Tests data(packages): initial import, 2026-05-27 2026-05-27 11:35:02 +02:00
.archive.tar.gz data(packages): initial import, 2026-05-27 2026-05-27 11:35:02 +02:00
.swiftformat data(packages): initial import, 2026-05-27 2026-05-27 11:35:02 +02:00
LICENSE data(packages): initial import, 2026-05-27 2026-05-27 11:35:02 +02:00
manifest.json data(packages): initial import, 2026-05-27 2026-05-27 11:35:02 +02:00
NOTICE data(packages): initial import, 2026-05-27 2026-05-27 11:35:02 +02:00
Package.swift data(packages): initial import, 2026-05-27 2026-05-27 11:35:02 +02:00
README.md data(packages): initial import, 2026-05-27 2026-05-27 11:35:02 +02:00

swift-extras-base64

Swift 5.1 github-actions codecov macOS tuxOS

This package provides a base64 encoder and decoder in Swift without the use of Foundation. The implementation is RFC4648 complient and is faster than the Foundation base64 implementation.

To achieve performance the implementation uses Chromium precomputed lookup tables and makes heavy use of unsafe swift API. When Swift has better support for SIMD instructions this might be an area worth exploring.

Status

  • support for base64 and base64url
  • faster than Foundation
  • padding can be omitted
  • decoding can ignore line breaks
  • encoding can insert line breaks

A former implementation of this package is used in swift-nio's websocket implementation.

Performance

Super simple performance test to ensure speediness of this implementation. Encoding and decoding 1m times the base64 string:

AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==

Tests were run on a MacBook Pro (16-inch, late 2019). Processor: 2.4 GHz 8-Core Intel Core i9.

macOS - swift 5.3

Encoding Decoding
Foundation 2.08s 2.15s
swift-extras-base64 0.66s 0.54s
Speedup 3x 4x

Linux - swift 5.3

Encoding Decoding
Foundation 1.01s 5.5s
swift-extras-base64 0.27s 0.41s
Speedup 3x ~10x

Literature for a faster algorithm

I would really like to speed up this project further to be way faster than it is today. Some food for thought of how this could be tackled can be found here:

Alternatives

As of today (2019-12-10), the author is aware of only one alternative that offers merely encoding.