PHPackages                             sycho/codecs-base64vlq - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sycho/codecs-base64vlq

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sycho/codecs-base64vlq
======================

Codec for VLQ (variable-length quantity) Base64 algorithm

2.0.0(4y ago)01.1M↓20.9%1MITPHPPHP &gt;=7.3

Since Feb 22Pushed 4y agoCompare

[ Source](https://github.com/SychO9/codecs-base64vlq)[ Packagist](https://packagist.org/packages/sycho/codecs-base64vlq)[ Docs](https://github.com/sycho9/codecs-base64vlq)[ RSS](/packages/sycho-codecs-base64vlq/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (5)Used By (1)

axy\\codecs\\base64vlq
======================

[](#axycodecsbase64vlq)

Codec for VLQ (variable-length quantity) Base64 algorithm (PHP).

[![Latest Stable Version](https://camo.githubusercontent.com/188a22efdbe4b7d84f078a7869d219ff8496190b857640329d6311ca6a1941e0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6178792f636f646563732d626173653634766c712e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/axy/codecs-base64vlq)[![Minimum PHP Version](https://camo.githubusercontent.com/b52c83f3d45755ebcb1e6863ebb202ab192aaf773424369ffdeedae107f027ef/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230352e342d3838393242462e7376673f7374796c653d666c61742d737175617265)](https://php.net/)[![Build Status](https://camo.githubusercontent.com/db1c7747af1ebc40c0be35c584261bc10a37001d0af6e087549c3f2d93e1c532/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f61787970726f2f636f646563732d626173653634766c712f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/axypro/codecs-base64vlq)[![Coverage Status](https://camo.githubusercontent.com/7178b883340220c7f883e795fdbf01dc658fd211156542b51e17c1b35db35a20/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f61787970726f2f636f646563732d626173653634766c712f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/axypro/codecs-base64vlq?branch=master)[![License](https://camo.githubusercontent.com/94991f4fbfca69e856d203fdb4012b9e474e3a73465b0ccb286f9cabc2b2f2a2/68747470733a2f2f706f7365722e707567782e6f72672f6178792f636f646563732d626173653634766c712f6c6963656e7365)](LICENSE)

- The library does not require any dependencies (except composer packages).
- Tested on PHP 5.4+, PHP 7, HHVM (on Linux), PHP 5.5 (on Windows).
- Install: `composer require axy/codecs-base64vlq`.
- License: [MIT](LICENSE).

### Documentation

[](#documentation)

#### VQL + Base64

[](#vql--base64)

Base64 allows us to represent a sequence of numbers in a text string that can be stored and transmit in text formats (JSON, XML, etc).

VLQ allows us to represent an integer in a sequence numbers with little digit capacity. For example 6 bit is the limit for Base64. The resulting numbers are called "VLQ digits". Small input number is represented by fewer VLQ-digits than big number. Thus VLQ is most effective if the input sequence is contains mainly the small numbers.

VLQ+Base64 allows us effectively represented a sequence of integers (dominated by a small number of) in the text format.

For example, it used in [JavaScript/CSS source map](https://www.google.ru/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&sqi=2&ved=0CBwQFjAA&url=https%3A%2F%2Fdocs.google.com%2Fdocument%2Fd%2F1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k%2Fedit&ei=abnpVKTZKeaHygPs0oK4BA&usg=AFQjCNFpOFA_dC_8cB50KJ1dXbOH7pvJnA&bvm=bv.86475890,d.bGQ).

#### The Algorithm

[](#the-algorithm)

For example, we have a block of numbers: `[12345, -12345, 0]`.

(1). VLQ only works with unsigned integers. Transfer the sign bit to the end of the integer.

`12345` in binary is `11000000111001`. Added `0` (positive) to the end: `110000001110010`.

For `-12345` take a positive form and add `1` (negative) to the end: `110000001110011`.

Result is `[110000001110010, 110000001110011, 0]`.

(2). Transform to the VLQ-sequence. For Base64 we need a block of 6-bit numbers. Most significant bit is reserved - it is "continuation".

Split numbers to groups of 5 bits: `[11000 00011 10010, 11000 00011 10011, 00000]`. Output starting from the least significant bits. If the group is not the last in the current number then set the continuation bit.

Result: `[110010 100011 011000 110011 100011 011000 000000]`. Or decimal `[50, 35, 24, 51, 35, 24, 0]`. These are VLQ digits.

(3). Replace the numbers on the letters of the Base64-alphabet. The standard alphabet is `A..Za..z0..9+/`.

Result is `yjYzjYA`.

#### How to use the library

[](#how-to-use-the-library)

```
use axy\codecs\base64vlq\Encoder;

$encoder = new Encoder();

$encoder->encode([12345, -12345, 0]); // yjYzjYA
$encoder->decode('yjYzjYA'); //  [12345, 012345, 9]

$encoder->decode('Variable+Length+QuantitY'); // [-10, 13, -13349, -13 ... -12797139]
```

Or default encoder can be obtained as follow:

```
$encoder = Encoder::getStandardInstance();
```

In this case, the object creation and preliminary calculations are performed only once.

#### Custom options

[](#custom-options)

The standard encoder uses standard options:

1. Transfer the sign bit.
2. 6-bit VLQ digits.
3. Standard alphabet: `A..Za..z0..9+/`.

You can apply your settings:

```
Encoder::__construct([array|string $alphabet, int $bits, bool $signed = true])
```

```
/* Custom alphabet, 4 bits, no sign transfer */
$encoder = new Encoder('My Alphabet', 3, false);

$encoder->encode([12345, 6789]); // phalllApplhhhy
```

Custom alphabet can be specified as a string (`My Alphabet`) or as an array (`[1 => 'A', 10 => 'B', 15 => 'C', 20 => 'D']`).

#### Exceptions

[](#exceptions)

The error classes are located in the namespace `axy\codecs\base64vlq\Encoder\Errors`.

- Error
    - VLQ
        - InvalidVLQSequence
    - Base64
        - InvalidBase64
        - InvalidBase64Input

##### InvalidVLQSequence

[](#invalidvlqsequence)

```
$encoder->decode('Az'); // VLQ sequence is invalid: [0,51]
```

`z` is 51 (the continuation bit = 1). The last digit must have 0 in continuation bit.

##### InvalidBase64

[](#invalidbase64)

```
$encoder->decode('A*A'); // Base-64 string is invalid: "A*A"
```

`*` are not in the standard Base64 alphabet.

##### InvalidBase64Input

[](#invalidbase64input)

For the standard encoder this exception should not occur.

Can occur for incorrect custom options:

```
$encoder = new Encoder('qwe', 10);
$encoder->encode([10, 20, 30]); // Number 20 is not found in Base64 alphabet
```

10 bits is 1024 variants, but the alphabet contains only 3 letter.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 85% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1301 days

Total

3

Last Release

1500d ago

Major Versions

1.0.1 → 2.0.02022-04-09

PHP version history (2 changes)1.0.0PHP &gt;=5.4.0

2.0.0PHP &gt;=7.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3653255?v=4)[SychO](/maintainers/SychO)[@Sycho](https://github.com/Sycho)

---

Top Contributors

[![vasa-c](https://avatars.githubusercontent.com/u/557081?v=4)](https://github.com/vasa-c "vasa-c (17 commits)")[![SychO9](https://avatars.githubusercontent.com/u/20267363?v=4)](https://github.com/SychO9 "SychO9 (3 commits)")

---

Tags

base64Source mapcodecVLQVariable length quantity

### Embed Badge

![Health badge](/badges/sycho-codecs-base64vlq/health.svg)

```
[![Health](https://phpackages.com/badges/sycho-codecs-base64vlq/health.svg)](https://phpackages.com/packages/sycho-codecs-base64vlq)
```

###  Alternatives

[paragonie/constant_time_encoding

Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16)

901329.7M148](/packages/paragonie-constant-time-encoding)[spomky-labs/base64url

Base 64 URL Safe Encoding/Decoding PHP Library

15439.5M49](/packages/spomky-labs-base64url)[elfsundae/laravel-hashid

A simple, elegant way to obfuscate your data by generating reversible, non-sequential, URL-safe identifiers.

415246.3k2](/packages/elfsundae-laravel-hashid)[axy/sourcemap

Work with JavaScript/CSS Source Map

24734.1k5](/packages/axy-sourcemap)[delight-im/base64

Simple and convenient Base64 encoding and decoding for PHP

15158.1k6](/packages/delight-im-base64)[efficiently/larasset

Larasset is a library for Laravel 5 which manage assets in an easy way.

684.8k](/packages/efficiently-larasset)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
