go-dictzip is a Go library for reading and writing
dictzip
files.
The API is currently unstable and will change. This package will use module version numbering to manage versions and compatibility.
To install this package run
go get github.com/ianlewis/go-dictzip
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 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)
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)
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
- dictzip(1) - Linux man page
- RFC 1952 - GZIP file format specification