Documentation ¶
Overview ¶
Package dictzip implements the dictzip compression format. Dictzip compresses files using the gzip(1) algorithm (LZ77) in a manner which is completely compatible with the gzip file format. See: https://linux.die.net/man/1/dictzip See: https://linux.die.net/man/1/gzip See: https://datatracker.ietf.org/doc/html/rfc1952
Unless otherwise informed clients should not assume implementations in this package are safe for parallel execution.
Example ¶
path := "internal/testdata/hello.txt.dz" f, err := os.Open(path) if err != nil { panic(err) } r, err := dictzip.NewReader(f) if err != nil { panic(err) } buf := make([]byte, 12) _, err = r.ReadAt(buf, 5) if err != nil { panic(err) } fmt.Println(string(buf))
Output: Hello World!
Index ¶
Examples ¶
Constants ¶
const ( // OSFAT represents an FAT filesystem OS (MS-DOS, OS/2, NT/Win32). OSFAT byte = iota // OSAmiga represents the Amiga OS. OSAmiga // OSVMS represents VMS (or OpenVMS). OSVMS // OSUnix represents Unix operating systems. OSUnix // OSVM represents VM/CMS. OSVM // OSAtari represents Atari TOS. OSAtari // OSHPFS represents HPFS filesystem (OS/2, NT). OSHPFS // OSMacintosh represents the Macintosh operating system. OSMacintosh // OSZSystem represents Z-System. OSZSystem // OSCPM represents the CP/M operating system. OSCPM // OSTOPS20 represents the TOPS-20 operating system. OSTOPS20 // OSNTFS represents an NTFS filesystem OS (NT). OSNTFS // OSQDOS represents QDOS. OSQDOS // OSAcorn represents Acorn RISCOS. OSAcorn // OSUnknown represents an unknown operating system. OSUnknown = 0xff )
const ( // XFLSlowest indicates that the compressor used maximum compression (e.g. slowest algorithm). XFLSlowest byte = 0x2 // XFLFastest indicates that the compressor used the fastest algorithm. XFLFastest byte = 0x4 )
const ( // NoCompression performs no compression on the input. NoCompression = flate.NoCompression // BestSpeed provides the lowest level of compression but the fastest // performance. BestSpeed = flate.BestSpeed // BestCompression provides the highest level of compression but the slowest // performance. BestCompression = flate.BestCompression // DefaultCompression is the default compression level used for compressing // chunks. It provides a balance between compression and performance. DefaultCompression = flate.DefaultCompression // HuffmanOnly disables Lempel-Ziv match searching and only performs Huffman // entropy encoding. See [flate.HuffmanOnly]. HuffmanOnly = flate.HuffmanOnly )
const ( // DefaultChunkSize is the default chunk size used when writing dictzip files. DefaultChunkSize = math.MaxUint16 )
Variables ¶
var ( // ErrHeader indicates an error with gzip header data. ErrHeader = fmt.Errorf("%w: invalid header", errDictzip) )
Functions ¶
This section is empty.
Types ¶
type Header ¶
type Header struct { // Comment is the COMMENT header field. Comment string // Extra includes all EXTRA sub-fields except the dictzip RA sub-field. Extra []byte // ModTime is the MTIME modification time field. ModTime time.Time // Name is the NAME header field. Name string // OS is the OS header field. OS byte // contains filtered or unexported fields }
Header is the gzip file header.
Strings must be UTF-8 encoded and may only contain Unicode code points U+0001 through U+00FF, due to limitations of the gzip file format.
type Reader ¶
type Reader struct { // Header is the gzip header data and is valid after [NewReader] or // [Reader.Reset]. Header // contains filtered or unexported fields }
Reader implements io.Reader and io.ReaderAt. It provides random access to the compressed data.
func NewReader ¶
func NewReader(r io.ReadSeeker) (*Reader, error)
NewReader returns a new dictzip Reader reading compressed data from the given reader. It does not assume control of the given io.Reader. It is the responsibility of the caller to Close on that reader when it is not longer used.
NewReader will call Seek on the given reader to ensure that it is being read from the beginning.
It is the callers responsibility to call Reader.Close on the returned Reader when done.
func (*Reader) ReadAt ¶
ReadAt implements io.ReaderAt.ReadAt.
type Writer ¶ added in v0.2.0
type Writer struct { // Header is written to the file when [Writer.Close] is called. Header // contains filtered or unexported fields }
Writer implements io.WriteCloser for writing dictzip files. Writer writes chunks to a temporary file during write and copies the resulting data to the final file when Writer.Close is called.
For this reason, Writer.Close must be called in order to write the file correctly.
func NewWriter ¶ added in v0.2.0
NewWriter initializes a new dictzip Writer with the default compression level and chunk size.
The OS Header is always set to OSUnknown (0xff) by default.
func NewWriterLevel ¶ added in v0.2.0
NewWriterLevel initializes a new dictzip Writer with the given compression level and chunk size.
The OS Header is always set to OSUnknown (0xff) by default.