<s>
liblzg	B-Application
is	O
a	O
compression	O
library	O
for	O
performing	O
lossless	B-Algorithm
data	I-Algorithm
compression	I-Algorithm
.	O
</s>
<s>
It	O
implements	O
an	O
algorithm	O
that	O
is	O
a	O
variation	O
of	O
the	O
LZ77	B-Algorithm
algorithm	O
,	O
called	O
the	O
LZG	O
algorithm	O
,	O
with	O
the	O
primary	O
focus	O
of	O
providing	O
a	O
very	O
simple	O
and	O
fast	O
decoding	O
method	O
.	O
</s>
<s>
The	O
software	O
library	O
is	O
free	B-Application
software	I-Application
,	O
distributed	O
under	O
the	O
zlib	B-License
license	I-License
.	O
</s>
<s>
If	O
a	O
duplicate	O
series	O
of	O
bytes	O
(	O
a	O
repeated	O
string	O
)	O
is	O
spotted	O
in	O
the	O
uncompressed	B-General_Concept
data	O
stream	O
,	O
then	O
a	O
back-reference	O
is	O
inserted	O
,	O
linking	O
to	O
the	O
previous	O
location	O
of	O
that	O
identical	O
string	O
instead	O
.	O
</s>
<s>
The	O
data	O
format	O
consists	O
of	O
a	O
header	O
,	O
followed	O
by	O
the	O
compressed	B-General_Concept
data	I-General_Concept
.	O
</s>
<s>
The	O
header	O
contains	O
an	O
identifier	O
and	O
house	O
keeping	O
information	O
,	O
such	O
as	O
compressed	O
and	O
decompressed	O
data	O
sizes	O
and	O
a	O
32-bit	O
checksum	O
(	O
a	O
variant	O
of	O
the	O
Fletcher	B-Algorithm
checksum	I-Algorithm
)	O
.	O
</s>
<s>
The	O
compressed	B-General_Concept
data	I-General_Concept
starts	O
with	O
four	O
bytes	O
,	O
identifying	O
four	O
unique	O
8-bit	O
marker	O
symbols	O
(	O
m1	O
,	O
m2	O
,	O
m3	O
and	O
m4	O
)	O
.	O
</s>
<s>
m1	O
represents	O
the	O
most	O
general	O
form	O
of	O
a	O
copy	O
operation	O
,	O
and	O
it	O
occupies	O
four	O
bytes	O
in	O
the	O
compressed	B-General_Concept
data	I-General_Concept
stream	O
:	O
</s>
<s>
m2	O
is	O
a	O
shorter	O
form	O
of	O
a	O
copy	O
operation	O
,	O
occupying	O
three	O
bytes	O
in	O
the	O
compressed	B-General_Concept
data	I-General_Concept
stream	O
:	O
</s>
<s>
m4	O
requires	O
only	O
two	O
bytes	O
,	O
and	O
is	O
used	O
for	O
nearby	O
copies	O
(	O
including	O
RLE	B-Algorithm
,	O
when	O
the	O
offset	O
is	O
1	O
)	O
:	O
</s>
<s>
As	O
the	O
marker	O
symbols	O
are	O
chosen	O
as	O
the	O
four	O
least	O
common	O
symbols	O
in	O
the	O
uncompressed	B-General_Concept
data	O
stream	O
(	O
with	O
a	O
probability	O
of	O
at	O
most	O
each	O
)	O
,	O
and	O
a	O
single	O
occurrence	O
of	O
a	O
marker	O
symbol	O
requires	O
two	O
bytes	O
to	O
encode	O
,	O
the	O
compressed	B-General_Concept
data	I-General_Concept
may	O
grow	O
by	O
at	O
most	O
<	O
1.6	O
%	O
compared	O
to	O
the	O
decompressed	O
data	O
(	O
worst	O
case	O
)	O
.	O
</s>
<s>
The	O
liblzg	B-Application
library	O
compensates	O
for	O
this	O
by	O
using	O
a	O
plain	O
1:1	O
copy	O
mode	O
if	O
the	O
encoder	O
identifies	O
that	O
the	O
compressed	B-General_Concept
data	I-General_Concept
will	O
be	O
larger	O
than	O
the	O
original	O
uncompressed	B-General_Concept
data	O
.	O
</s>
<s>
Both	O
the	O
compression	O
and	O
the	O
decompression	O
algorithms	O
are	O
implemented	O
in	O
an	O
open	O
source	O
library	O
,	O
written	O
in	O
the	O
C	B-Language
programming	I-Language
language	I-Language
.	O
</s>
<s>
There	O
are	O
also	O
several	O
alternate	O
implementations	O
of	O
the	O
decompression	O
algorithm	O
available	O
(	O
for	O
instance	O
in	O
JavaScript	B-Language
and	O
8-bit	O
assembly	B-Language
language	I-Language
)	O
.	O
</s>
