lzss

package module
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2025 License: MIT Imports: 1 Imported by: 5

README

lzss

GoDoc License

LZSS compression package for Go.


Install

As a Go package
go get github.com/blacktop/lzss
As a CLI tool
go install github.com/blacktop/lzss/cmd@latest

CLI Usage

# Compress a file
lzss -c input.txt                    # creates input.txt.lzss

# Decompress a file  
lzss -d input.txt.lzss               # creates input.txt

# Custom output file
lzss -c -o compressed.lzss input.txt
lzss -d -o output.txt input.lzss

# Show help
lzss -h

Examples

Compression
import (
    "io/ioutil"
    "log"

    "github.com/blacktop/lzss"
    "github.com/pkg/errors"
)

func main() {
    // Compress data
    data, err := ioutil.ReadFile("input.txt")
    if err != nil {
        log.Fatal(errors.Wrap(err, "failed to read input file"))
    }

    compressed := lzss.Compress(data)
    err = ioutil.WriteFile("compressed.bin", compressed, 0644)
    if err != nil {
        log.Fatal(errors.Wrap(err, "failed to write compressed file"))
    }
}
Decompression
import (
    "io/ioutil"
    "log"

    "github.com/blacktop/lzss"
    "github.com/pkg/errors"
)

func main() {
    dat, err := ioutil.ReadFile("compressed.bin")
    if err != nil {
        log.Fatal(errors.Wrap(err, "failed to read compressed file"))
    }

    decompressed := lzss.Decompress(dat)
    err = ioutil.WriteFile("compressed.bin.decompressed", decompressed, 0644)
    if err != nil {
        log.Fatal(errors.Wrap(err, "failed to decompress file"))
    }
}

NOTE: I believe lzss expects the data to be word aligned.

Credit

Converted to Golang from https://github.com/opensource-apple/kext_tools/blob/master/compression.c

License

MIT Copyright (c) 2018-2025 blacktop

Documentation

Overview

Package lzss is a LZSS compression package for Go.

Index

Constants

View Source
const (

	// Magic and CompressionType for LZSS Apple format
	Magic           = "complzss"
	CompressionType = 0x636f6d70 // "comp"
	Signature       = 0x6c7a7373 // "lzss"
)

Variables

This section is empty.

Functions

func Compress added in v0.1.2

func Compress(src []byte) []byte

Compress compresses data using LZSS algorithm (Apple format)

func Decompress

func Decompress(src []byte) []byte

Decompress decompresses lzss data

Types

type Header struct {
	CompressionType  uint32 // 0x636f6d70 "comp"
	Signature        uint32 // 0x6c7a7373 "lzss"
	CheckSum         uint32 // Likely CRC32
	UncompressedSize uint32
	CompressedSize   uint32
	Version          uint32 // Version of the compression algorithm
	Padding          [padding]byte
}

Header represents the LZSS header

Directories

Path Synopsis
cmd module

Jump to

Keyboard shortcuts

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