gzip

package
v0.2.76 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 8 Imported by: 2

Documentation

Overview

Package gzip provides pre-compressed data container.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalJSON

func MarshalJSON(v interface{}) ([]byte, error)

MarshalJSON encodes Go value as JSON and compresses result with gzip.

func UnmarshalJSON

func UnmarshalJSON(data []byte, v interface{}) error

UnmarshalJSON decodes compressed JSON bytes into a Go value.

func WriteCompressedBytes

func WriteCompressedBytes(compressed []byte, w io.Writer) (int, error)

WriteCompressedBytes writes compressed bytes to response.

Bytes are unpacked if response writer does not support direct gzip writing.

Types

type JSONContainer

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

JSONContainer contains compressed JSON.

func (JSONContainer) ETag

func (jc JSONContainer) ETag() string

ETag returns hash of uncompressed JSON content, identifying the identity representation.

Unlike hashing compressed bytes, this is stable across changes to the gzip/flate implementation (e.g. across Go versions), which do not guarantee stable output bytes for the same input.

func (JSONContainer) GzipCompressedJSON

func (jc JSONContainer) GzipCompressedJSON() []byte

GzipCompressedJSON returns JSON compressed with gzip.

func (JSONContainer) GzipETag added in v0.2.76

func (jc JSONContainer) GzipETag() string

GzipETag returns a hash of uncompressed JSON content salted for the gzip-compressed representation, so it differs from ETag.

The gzip and identity representations are byte-distinct, so gzip-compression middleware (see response/gzip) uses this instead of ETag when serving the gzip body, to avoid one strong validator being shared between two different representations.

func (JSONContainer) JSONWriteTo

func (jc JSONContainer) JSONWriteTo(w io.Writer) (int, error)

JSONWriteTo writes JSON payload to writer.

func (JSONContainer) MarshalJSON

func (jc JSONContainer) MarshalJSON() (j []byte, err error)

MarshalJSON returns uncompressed JSON.

func (*JSONContainer) PackJSON

func (jc *JSONContainer) PackJSON(v interface{}) error

PackJSON puts Go value in JSON container.

func (JSONContainer) UnpackJSON

func (jc JSONContainer) UnpackJSON(v interface{}) error

UnpackJSON unmarshals data from JSON container into a Go value.

type Writer

type Writer interface {
	GzipWrite(d []byte) (int, error)
}

Writer writes gzip data into suitable stream or returns 0, nil.

Jump to

Keyboard shortcuts

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