Documentation
¶
Overview ¶
Package unshrink is for use with the archive/zip package.
Unshrink was a decompression method authored in 1989 by Phil Katz and used in his MS-DOS compression tool, PKZip v0.80 and v0.90.
It is retroactively referred to as ZIP Shrink/Unshrink method 1 and is based on the LZW algorithm.
This package was first prompted using Gemini in August 2026 and manually cleaned to be idiomatic and readable.
In 2020, Jason Summers authored a collection of public domain libraries named oldunzip. In-depth information on Shrink was authored by Hans Wennborg in 2021, who programmed the public domain shrink.c.
Example ¶
Example demonstrates the basic usage of the package.
package main
import (
"archive/zip"
"fmt"
"hash/crc32"
"io"
"path/filepath"
"github.com/Defacto2/archive/unshrink"
)
func main() {
const testdata = "testdata"
const testFile = "example-s.zip"
// Register the Unshrink decompressor with the archive zip package.
unshrink.Register()
name := filepath.Join(testdata, testFile)
rc, _ := zip.OpenReader(name)
defer rc.Close()
for n, f := range rc.File {
fr, _ := f.Open()
hasher := crc32.NewIEEE()
size := int64(f.UncompressedSize64) //nolint:gosec
_, _ = io.CopyN(hasher, fr, size)
fmt.Printf("%d. Decompressed method %d: %s, %dB\n"+
"Stored zip crc32 %x, and copied to buffer: %x\n",
n+1, f.Method, f.Name, f.UncompressedSize64, f.CRC32, hasher.Sum32())
fr.Close()
}
}
Output: 1. Decompressed method 1: S.BIN, 2048B Stored zip crc32 8314ddd9, and copied to buffer: 8314ddd9
Index ¶
Examples ¶
Constants ¶
const Unshrink uint16 = 1 // Method 1: Shrink/Unshink
Variables ¶
var ErrOverflow = errors.New("unshink: integer overflow")
ErrOverflow is returned when an integer cannot be safely wrapped to a new type.
Functions ¶
Types ¶
This section is empty.