uncozip

package module
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 15 Imported by: 0

README

uncozip

License Go Reference

This is a command and package to UNzip COrrupted ZIP files that do not have central directory records.

Even when an archive is so large that zip -FF Corrupted.zip --out New.zip fails, uncozip sometimes succeeds. (For example, when Corrupted.zip is larger than 4 GB.)

uncozip is also useful on non-Windows systems for unpacking archives that contain filenames encoded in non-UTF8 encodings such as Shift_JIS. (Example: uncozip -decode Shift_JIS foo.zip)

Usage

uncozip {OPTIONS} ZIPFILENAME [list...]

uncozip {OPTIONS} - [list...] < ZIPFILENAME

uncozip {OPTIONS} < ZIPFILENAME
  • -d string Directory to extract into
  • -debug Enable debug output
  • -strict Quit immediately on CRC error
  • -t Test CRC32 only
  • -decode IANA-NAME Specify an IANA-registered name used to decode filenames when the UTF-8 flag is not set (for example: -decode Shift_JIS)

Install

Download the binary package from the Releases page and extract the executable.

For scoop
scoop install https://raw.githubusercontent.com/hymkor/uncozip/master/uncozip.json

or

scoop bucket add hymkor https://github.com/hymkor/scoop-bucket
scoop install uncozip

package "github.com/hymkor/uncozip"

Unlike the standard archive/zip package, uncozip can:

  • read an archive from an io.Reader (archive/zip requires the archive's filename[^zip.OpenReader] or an io.ReaderAt plus the size[^zip.NewReader])
  • handle encrypted archives (you need to call [RegisterPasswordHandler])
  • decode filenames using any encoding (you need to call [RegisterNameDecoder])

[^zip.OpenReader]: See also https://pkg.go.dev/archive/zip#OpenReader [^zip.NewReader]: See also https://pkg.go.dev/archive/zip#NewReader

Documentation

Index

Constants

View Source
const (
	Store   = 0
	Deflate = 8
)

Variables

View Source
var (
	ErrLocalFileHeaderSignatureNotFound = errors.New("signature not found")
)

Functions

func SanitizePath added in v0.7.3

func SanitizePath(name string) string

Types

type CorruptedZip

type CorruptedZip struct {
	LastModificationTime time.Time
	LastAccessTime       time.Time
	CreationTime         time.Time

	// Debug outputs debug-log. When the field is not set, debug-log is dropped.
	Debug func(...any)
	// contains filtered or unexported fields
}

CorruptedZip is a reader for a ZIP archive that reads from io.Reader instead of io.ReaderAt

func New

func New(r io.Reader) *CorruptedZip

New returns a CorruptedZip instance that reads a ZIP archive.

func (*CorruptedZip) Body added in v0.1.0

func (cz *CorruptedZip) Body() io.Reader

Body returns the reader of the most recent file by a call to Scan.

func (*CorruptedZip) CRC32 added in v0.4.1

func (cz *CorruptedZip) CRC32() uint32

CRC32 returns the current file's CRC32 written in "local file header" or "data descriptor". When an "data descriptor" exists, it waits until file data stream is read all. This field is sed by Scan method

func (*CorruptedZip) Close added in v0.7.1

func (cz *CorruptedZip) Close()

Close releases resources used on the Scan method previous called.

func (*CorruptedZip) CompressedSize added in v0.4.0

func (cz *CorruptedZip) CompressedSize() uint64

CompressedSize returns the current file's compressed size written in "local file header" or "data descriptor". When an "data descriptor" exists, it waits until file data stream is read all. This field is sed by Scan method

func (*CorruptedZip) Each added in v0.7.3

func (cz *CorruptedZip) Each(f func(*CorruptedZip) bool)

Each is the function for rangefunc.

func (*CorruptedZip) Err added in v0.1.0

func (cz *CorruptedZip) Err() error

Err returns the error encountered by the CorruptedZip.

func (*CorruptedZip) IsDir added in v0.7.1

func (cz *CorruptedZip) IsDir() bool

IsDir returns true when the current file is a directory.

func (*CorruptedZip) Method added in v0.4.1

func (cz *CorruptedZip) Method() uint16

Method returns the mothod to compress the current entry data

func (*CorruptedZip) Name added in v0.1.0

func (cz *CorruptedZip) Name() string

Name returns the name of the most recent file by a call to Scan.

func (*CorruptedZip) OriginalSize added in v0.4.0

func (cz *CorruptedZip) OriginalSize() uint64

originalSize returns the current file's uncompressed size written in "local file header" or "data descriptor". When an "data descriptor" exists, it waits until file data stream is read all. This field is sed by Scan method

func (*CorruptedZip) RegisterNameDecoder added in v0.7.1

func (cz *CorruptedZip) RegisterNameDecoder(f func([]byte) (string, error))

RegisterNameDecoder sets callback function to translate nonUTF8 filename to UTF8

func (*CorruptedZip) RegisterPasswordHandler added in v0.6.0

func (cz *CorruptedZip) RegisterPasswordHandler(f func(filename string) (password []byte, err error))

RegisterPasswordHandler sets a callback function to query password to an user.

func (*CorruptedZip) Scan

func (cz *CorruptedZip) Scan() bool

Scan advances the CorruptedZip to the next single file in a ZIP archive.

type ErrPassword added in v0.4.0

type ErrPassword struct {
	// contains filtered or unexported fields
}

ErrPassword is an error reporting that password is invalid.

func (*ErrPassword) Error added in v0.4.0

func (e *ErrPassword) Error() string

Error returns an error message.

func (*ErrPassword) Name added in v0.4.0

func (e *ErrPassword) Name() string

Name returns a entry filename where an error occured

Directories

Path Synopsis
cmd
uncozip command

Jump to

Keyboard shortcuts

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