Skip to content

Commit

Permalink
ensure codecs implement CompressorProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
CAFxX committed Jan 21, 2021
1 parent 6e47e76 commit 04359cb
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 5 deletions.
8 changes: 8 additions & 0 deletions contrib/andybalholm/brotli/brotli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package brotli_test

import (
"github.com/CAFxX/httpcompression"
"github.com/CAFxX/httpcompression/contrib/andybalholm/brotli"
)

var _ httpcompression.CompressorProvider = &brotli.Compressor{}
3 changes: 3 additions & 0 deletions contrib/andybalholm/brotli/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package brotli

type Compressor = compressor
3 changes: 3 additions & 0 deletions contrib/klauspost/gzip/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package gzip

type Compressor = compressor
8 changes: 8 additions & 0 deletions contrib/klauspost/gzip/gzip_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package gzip_test

import (
"github.com/CAFxX/httpcompression"
"github.com/CAFxX/httpcompression/contrib/klauspost/gzip"
)

var _ httpcompression.CompressorProvider = &gzip.Compressor{}
3 changes: 3 additions & 0 deletions contrib/klauspost/pgzip/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package pgzip

type Compressor = compressor
8 changes: 8 additions & 0 deletions contrib/klauspost/pgzip/pgzip_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package pgzip_test

import (
"github.com/CAFxX/httpcompression"
"github.com/CAFxX/httpcompression/contrib/klauspost/pgzip"
)

var _ httpcompression.CompressorProvider = &pgzip.Compressor{}
3 changes: 3 additions & 0 deletions contrib/klauspost/zstd/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package zstd

type Compressor = compressor
10 changes: 5 additions & 5 deletions contrib/klauspost/zstd/zstd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ import (

const Encoding = "zstd"

type zstdCompressor struct {
type compressor struct {
pool sync.Pool
opts []zstd.EOption
}

func New(opts ...zstd.EOption) (c *zstdCompressor, err error) {
func New(opts ...zstd.EOption) (c *compressor, err error) {
opts = append([]zstd.EOption(nil), opts...)
gw, err := zstd.NewWriter(nil, opts...)
if err != nil {
return nil, err
}
c = &zstdCompressor{opts: opts}
c = &compressor{opts: opts}
c.pool.Put(gw)
return c, nil
}

func (c *zstdCompressor) Get(w io.Writer) io.WriteCloser {
func (c *compressor) Get(w io.Writer) io.WriteCloser {
if gw, ok := c.pool.Get().(*zstdWriter); ok {
gw.Reset(w)
return gw
Expand All @@ -42,7 +42,7 @@ func (c *zstdCompressor) Get(w io.Writer) io.WriteCloser {

type zstdWriter struct {
*zstd.Encoder
c *zstdCompressor
c *compressor
}

func (w *zstdWriter) Close() error {
Expand Down
8 changes: 8 additions & 0 deletions contrib/klauspost/zstd/zstd_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package zstd_test

import (
"github.com/CAFxX/httpcompression"
"github.com/CAFxX/httpcompression/contrib/klauspost/zstd"
)

var _ httpcompression.CompressorProvider = &zstd.Compressor{}

0 comments on commit 04359cb

Please sign in to comment.