Documentation
¶
Overview ¶
Package zstd writes RFC 8878 Zstandard frames and calculates cache metadata over the encoded representation while it is emitted.
Host Go uses github.com/klauspost/compress/zstd. TinyGo uses this package's bounded encoder, which can also be selected on host Go with the shared force_tinygo_logic build tag. Both implementations expose the same API and calculate Result's SHA-256 digest over bytes successfully written.
Index ¶
Examples ¶
Constants ¶
const ContentEncoding = "zstd"
ContentEncoding is the HTTP content-coding token for Zstandard.
Variables ¶
var ( ErrClosed = errors.New("zstd: writer is closed") )
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option configures both the host-Go and TinyGo encoders.
type Result ¶
Result describes an encoded representation. SHA256 covers exactly Size bytes written to the destination, including the Zstandard frame headers.
func EncodeAll ¶
EncodeAll encodes src, returning the frame and its cache metadata. The digest is produced while the frame is written; the encoded bytes are not traversed a second time.
Example ¶
package main
import (
"fmt"
"github.com/shibukawa/tinygodriver/compress/zstd"
)
func main() {
encoded, result, err := zstd.EncodeAll([]byte("response body"))
if err != nil {
panic(err)
}
fmt.Println(len(encoded) == int(result.Size))
fmt.Println(zstd.ContentEncoding)
}
Output: true zstd
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer emits one Zstandard frame through github.com/klauspost/compress/zstd. Writer is not safe for concurrent use. Close must succeed before Result can be read.
func NewWriter ¶
NewWriter starts a host-Go Zstandard stream. TinyGo and builds using the force_tinygo_logic tag select the bounded TinyGo encoder instead.