Package yarpcgzip provides a YARPC binding for GZIP compression.



    This section is empty.


    This section is empty.


    This section is empty.


    type Compressor

    type Compressor struct {
    	// contains filtered or unexported fields

      Compressor represents the gzip compression strategy.

      func New

      func New(opts ...Option) *Compressor

        New returns a GZIP compression strategy, suitable for configuring an outbound dialer.

        The compressor needs to be adapted and registered to be compatible with the gRPC compressor system. Since gRPC requires global registration of compressors, you must arrange for the compressor to be registered in your application initialization. The adapter converts an io.Reader into an io.ReadCloser so that reading EOF will implicitly trigger Close, a behavior gRPC-go relies upon to reuse readers.

        import (
        var GZIPCompressor = yarpcgzip.New(yarpcgzip.Level(gzip.BestCompression))
        func init()
            gz := yarpcgrpccompressor.New(GZIPCompressor)

        If you are constructing your YARPC clients directly through the API, create a gRPC dialer with the Compressor option.

        trans := grpc.NewTransport()
        dialer := trans.NewDialer(GZIPCompressor)
        peers := roundrobin.New(dialer)
        outbound := trans.NewOutbound(peers)

        If you are using the YARPC configurator to create YARPC objects using config files, you will also need to register the compressor with your configurator.

        configurator := yarpcconfig.New()

        Then, using the compression strategy for outbound requests on a particular client, just set the compressor to gzip.

              address: ":443"
                enabled: true
              compressor: gzip

        func (*Compressor) Compress

        func (c *Compressor) Compress(w io.Writer) (io.WriteCloser, error)

          Compress creates a gzip compressor.

          func (*Compressor) Decompress

          func (c *Compressor) Decompress(r io.Reader) (io.ReadCloser, error)

            Decompress obtains a gzip decompressor.

            func (*Compressor) DecompressedSize

            func (c *Compressor) DecompressedSize(buf []byte) int

              DecompressedSize returns the decompressed size of the given GZIP compressed bytes.

              gRPC specifically casts the compressor to a DecompressedSizer to pre-check message length.

              Per gRPC-go, on which this is based:

              RFC1952 specifies that the last four bytes "contains the size of the original (uncompressed) input data modulo 2^32." gRPC has a max message size of 2GB so we don't need to worry about wraparound for that transport protocol.

              func (*Compressor) Name

              func (*Compressor) Name() string

                Name is gzip.

                type Option

                type Option interface {
                	// contains filtered or unexported methods

                  Option is an option argument for the Gzip compressor constructor, New.

                  func Level

                  func Level(level int) Option

                    Level sets the compression level for the compressor.

                    Source Files