unshrink

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: GPL-3.0 Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const Unshrink uint16 = 1 // Method 1: Shrink/Unshink

Variables

View Source
var ErrOverflow = errors.New("unshink: integer overflow")

ErrOverflow is returned when an integer cannot be safely wrapped to a new type.

Functions

func Register

func Register()

Register the Unshrink method globally for archive/zip.

Types

This section is empty.

Jump to

Keyboard shortcuts

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