zipcharset

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: BSD-3-Clause Imports: 6 Imported by: 0

README

zipcharset

zipcharset is an advanced Go decoder adapter for ZIP archives that resolves legacy, non-Unicode filenames and comments, preventing Mojibake.

It relies on the zero-dependency library localecp for system-locale codepage deduction, while layering ZIP-specific heuristics and extra-fields extraction on top.

Features

  • ZIP-Specific Heuristics: Automatically evaluates packer version, flags, and packing OS metadata to determine if ANSI (Windows) or OEM (DOS) translation should apply.
  • Unicode Extra Fields Extraction: Safely parses and validates Info-ZIP Unicode Path (0x7075) and Unicode Comment (0x6375) structures.
  • Seamless Integration: Exposes a simple zip.ReaderOptions callback function for the klauspost/compress/zip library.

Dependencies

  • github.com/unxed/localecp (zero-dependency locale mapping engine)
  • github.com/klauspost/compress

Installation

go get github.com/unxed/zipcharset

Usage

package main

import (
	"fmt"
	"os"

	"github.com/klauspost/compress/zip"
	"github.com/unxed/zipcharset"
)

func main() {
	f, _ := os.Open("legacy_archive.zip")
	defer f.Close()

	stat, _ := f.Stat()

	opts := zip.ReaderOptions{
		NameDecoder: zipcharset.NewNameDecoder(),
	}

	zr, _ := zip.NewReaderWithOptions(f, stat.Size(), opts)

	for _, file := range zr.File {
		fmt.Println(file.Name)
	}
}

License

Licensed under the 3-Clause BSD License.

Documentation

Index

Constants

View Source
const (
	UnicodePathExtraID    = 0x7075
	UnicodeCommentExtraID = 0x6375

	CreatorFAT    = 0
	CreatorHPFS   = 6
	CreatorNTFS   = 11
	CreatorUnix   = 3
	CreatorMacOSX = 19
)

Variables

This section is empty.

Functions

func DecodeText added in v0.1.1

func DecodeText(raw []byte, isUTF8Flag bool, packOS byte, packVer uint16, extra []byte, isComment bool) string

func NewNameDecoder

func NewNameDecoder() func(f *zip.FileHeader) error

NewNameDecoder returns an opt-in callback function to rewrite legacy, non-Unicode filenames and comments into clean UTF-8.

func ParseUnicodeExtraField added in v0.1.1

func ParseUnicodeExtraField(extra []byte, targetID uint16, rawData []byte) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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