Home / Function/ Benchmark_Ctx_Body_With_Compression_Immutable() — fiber Function Reference

Benchmark_Ctx_Body_With_Compression_Immutable() — fiber Function Reference

Architecture documentation for the Benchmark_Ctx_Body_With_Compression_Immutable() function in ctx_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  87e123d5_9fd2_2de1_e3c6_ed2c2207471e["Benchmark_Ctx_Body_With_Compression_Immutable()"]
  7b3d4933_5ae3_f84d_ff6d_0cb34e268026["ctx_test.go"]
  87e123d5_9fd2_2de1_e3c6_ed2c2207471e -->|defined in| 7b3d4933_5ae3_f84d_ff6d_0cb34e268026
  style 87e123d5_9fd2_2de1_e3c6_ed2c2207471e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

ctx_test.go lines 1262–1382

func Benchmark_Ctx_Body_With_Compression_Immutable(b *testing.B) {
	encodingErr := errors.New("failed to encoding data")

	var (
		compressGzip = func(data []byte) ([]byte, error) {
			var buf bytes.Buffer
			writer := gzip.NewWriter(&buf)
			if _, err := writer.Write(data); err != nil {
				return nil, encodingErr
			}
			if err := writer.Flush(); err != nil {
				return nil, encodingErr
			}
			if err := writer.Close(); err != nil {
				return nil, encodingErr
			}
			return buf.Bytes(), nil
		}
		compressDeflate = func(data []byte) ([]byte, error) {
			var buf bytes.Buffer
			writer := zlib.NewWriter(&buf)
			if _, err := writer.Write(data); err != nil {
				return nil, encodingErr
			}
			if err := writer.Flush(); err != nil {
				return nil, encodingErr
			}
			if err := writer.Close(); err != nil {
				return nil, encodingErr
			}
			return buf.Bytes(), nil
		}
	)
	const input = "john=doe"
	compressionTests := []struct {
		compressWriter  func([]byte) ([]byte, error)
		contentEncoding string
		expectedBody    []byte
	}{
		{
			contentEncoding: "gzip",
			compressWriter:  compressGzip,
			expectedBody:    []byte(input),
		},
		{
			contentEncoding: "gzip,invalid",
			compressWriter:  compressGzip,
			expectedBody:    []byte(ErrUnsupportedMediaType.Error()),
		},
		{
			contentEncoding: StrDeflate,
			compressWriter:  compressDeflate,
			expectedBody:    []byte(input),
		},
		{
			contentEncoding: "gzip,deflate",
			compressWriter: func(data []byte) ([]byte, error) {
				var (
					buf    bytes.Buffer
					writer interface {
						io.WriteCloser
						Flush() error
					}
					err error
				)

				// deflate
				writer = zlib.NewWriter(&buf)
				if _, err = writer.Write(data); err != nil {
					return nil, encodingErr
				}
				if err = writer.Flush(); err != nil {
					return nil, encodingErr
				}
				if err = writer.Close(); err != nil {
					return nil, encodingErr
				}

				data = make([]byte, buf.Len())
				copy(data, buf.Bytes())
				buf.Reset()

Domain

Subdomains

Defined In

Frequently Asked Questions

What does Benchmark_Ctx_Body_With_Compression_Immutable() do?
Benchmark_Ctx_Body_With_Compression_Immutable() is a function in the fiber codebase, defined in ctx_test.go.
Where is Benchmark_Ctx_Body_With_Compression_Immutable() defined?
Benchmark_Ctx_Body_With_Compression_Immutable() is defined in ctx_test.go at line 1262.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free