Help us shape the future of Go! Take the 2026 Go Developer Survey

adc

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2026 License: BSD-3-Clause Imports: 1 Imported by: 0

README

go-compressions/adc

adc

Decodes Apple Data Compression (ADC) — pure Go, CGO_ENABLED=0, builds for every target Go builds for.

out, err := adc.Decompress(src)

ADC is what the UDCO flavour of a UDIF disk image (.dmg) stores its sectors in, and what classic Mac OS used for compressed resources. hdiutil names it plainly:

UDCO - compressed (ADC)

The format

There is no header, no checksum and no stored output length. A stream is a bare sequence of three opcodes and it ends when its bytes run out, so a caller that knows how long the output should be has to check that itself — this package returns what the stream encodes and does not second-guess it.

first byte meaning length offset
1xxxxxxx literal run, x+1 bytes follow 1..128 —
01xxxxxx hhhhhhhh llllllll match x+4, 4..67 hl+1, 1..65536
00xxxxyy yyyyyyyy match x+3, 3..18 y+1, 1..1024

An offset counts backwards from the end of the output written so far, so 1 is the byte just produced. A match may be longer than its offset, repeating what it has already copied; that is how a run of one byte is coded, and it is why the copy runs a byte at a time rather than as a slice.

Where the format came from

Off streams written by Apple. A raw image was converted with

hdiutil convert raw.img -format UDCO -o out.dmg

and the bytes of the ADC run lifted out of the resulting blkx table. The test fixture is that pair — Apple's compressed stream and the plaintext it has to give back — so nothing here is checked against an encoder of ours. There is no encoder of ours: nothing asks for one yet.

The fixture is worth nothing unless it reaches all three opcodes, so the test counts them before trusting the comparison (12 literal runs, 45 long matches, 4 short matches) and fails if any count is zero.

Errors

ErrTruncated an opcode's operands, or a literal run's bytes, reach past the end of the input
ErrOffset a match points further back than the output written so far

Who needs it

go-diskimages/dmg reads a UDCO image with it. Before this existed that package had 0x80000004 labelled LZFSE, which is in fact ADC, so a real UDCO image was handed to the LZFSE decoder and a real ULFO image refused as an unknown type.

Licence

BSD-3-Clause.

Documentation

Overview

Package adc decodes Apple Data Compression (ADC), the byte-oriented LZ77 variant Apple uses for the "UDCO" flavour of UDIF disk images and, before that, for resources in classic Mac OS.

The format has no header, no checksum and no stored output length: a stream is a bare sequence of three opcodes, and it ends when its bytes run out. A caller that knows how long the output should be must check that itself.

out, err := adc.Decompress(src)

CGO is not used, so this builds for every target Go builds for.

The opcodes

The first byte of each opcode says which one it is, and the format was read off streams written by Apple's own hdiutil rather than from any implementation of it:

1xxxxxxx                    literal run, (x+1) bytes follow, 1..128
01xxxxxx hhhhhhhh llllllll  match, length (x+4) 4..67,  offset (hl+1) 1..65536
00xxxxyy yyyyyyyy           match, length (x+3) 3..18,  offset (y+1)  1..1024

An offset counts backwards from the end of the output produced so far, so 1 is the byte just written. A match may be longer than its offset, in which case it repeats what it has already copied; that is the usual way a run of one byte is coded, and it is why the copy runs one byte at a time.

Index

Constants

This section is empty.

Variables

View Source
var ErrOffset = errors.New("adc: match offset reaches before the start of the output")

ErrOffset is returned when a match points further back than the output written so far, which no stream produced by a correct encoder ever does.

View Source
var ErrTruncated = errors.New("adc: truncated stream")

ErrTruncated is returned when an opcode's operands, or a literal run's bytes, reach past the end of the input.

Functions

func Decompress

func Decompress(src []byte) ([]byte, error)

Decompress returns the bytes the stream encodes. An empty input gives an empty output and no error: the format ends by exhaustion, so a stream of no opcodes is a stream of no bytes.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL