Skip to content

ianlewis/go-dictzip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

go-dictzip

Go Reference codecov tests

go-dictzip is a Go library for reading and writing dictzip files.

Status

The API is currently unstable and will change. This package will use module version numbering to manage versions and compatibility.

Installation

To install this package run

go get github.com/ianlewis/go-dictzip

Examples

Reading compressed files

You can open a dictionary file and read it much like a normal reader.

// Open the dictionary.
f, _ := os.Open("dictionary.dict.dz")
r, _ := dictzip.NewReader(f)
defer r.Close()

uncompressedData, _ = io.ReadAll(r)

Random access

Random access can be performed using the ReadAt method.

// Open the dictionary.
f, _ := os.Open("dictionary.dict.dz")
r, _ := dictzip.NewReader(f)
defer r.Close()

buf := make([]byte, 12)
_, _ = r.ReadAt(buf, 5)

Writing compressed files

Dictzip files can be written using the dictzip.Writer. Compressed data is stored in chunks and chunk sizes are stored in the archive header allowing for more efficient random access.

// Open the dictionary.
f, _ := os.Open("dictionary.dict.dz", os.O_WRONLY|os.O_CREATE, 0o644)
w, _ := dictzip.NewWriter(f)
defer w.Close()

buf := []byte("Hello World!")
_, _ = r.Write(buf)

dictzip Command

This repository also includes a dictzip command that is compatible with the dictzip(1) command.

# compress dictionary.dict to dictionary.dict.dz
$ dictzip dictionary.dict

# decompress dictionary.dict.dz to dictionary.dict
$ dictzip -d dictionary.dict.dz

# decompress part of the file and print to stdout
$ dictzip --stdout --start 1024 --size 25 dictionary.dict.dz
dictionary entry contents

Related projects

References

About

A dictzip implementation in Go

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published